Skip to content

Commit

Permalink
add modify password
Browse files Browse the repository at this point in the history
  • Loading branch information
lisong committed Sep 16, 2018
1 parent 1c11cd9 commit 4fc1f8e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ middleware.checkToken = function(req, res, next) {
authType = 2;
authToken = _.trim(_.trimStart(_.get(req, 'query.access_token', null)));
}
if (authType == 1) {
if (authToken && authType == 1) {
checkAuthToken(authToken)
.then((users) => {
req.users = users;
Expand All @@ -99,7 +99,7 @@ middleware.checkToken = function(req, res, next) {
next(e);
}
});
} else if (authType == 2) {
} else if (authToken && authType == 2) {
checkAccessToken(authToken)
.then((users) => {
req.users = users;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"config",
"core",
"docs",
"docker",
"models",
"public",
"routes",
Expand Down
4 changes: 4 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ var validator = require('validator');
var log4js = require('log4js');
var log = log4js.getLogger("cps:auth");

router.get('/password', (req, res) => {
res.render('auth/password', { title: 'CodePushServer' });
});

router.get('/login', (req, res) => {
var codePushWebUrl = _.get(config, 'common.codePushWebUrl');
if (codePushWebUrl && validator.isURL(codePushWebUrl)) {
Expand Down
57 changes: 57 additions & 0 deletions views/auth/password.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
extends ../layout

block content
.container(style="margin-top:30px;")
form#form.col-md-5.col-md-offset-3(method="post")
.form-group
label.sr-only(for="inputEmail") 邮箱地址/用户名
input#inputEmail.form-control(type="text" name="account" placeholder="邮箱地址/用户名" required autofocus)
.form-group
.col-md-10(style="margin-left:-15px;")
label.sr-only(for="inputToken") token
input#inputToken.form-control(type="text" name="token" placeholder="token" required)
.col-md-2
a.form-control.btn.btn-link(style="margin-bottom:15px;" target="_blank" href="/auth/login") 获取token
.form-group
label.sr-only(for="inputPassword") 原密码
input#inputPassword.form-control(type="password" name="oldPassword" placeholder="原密码" required)
.form-group
label.sr-only(for="inputNewPassword") 新密码
input#inputNewPassword.form-control(type="password" name="newPassword" placeholder="新密码" required)
.form-group
a#submitBtn.btn.btn-lg.btn-primary.btn-block 修改密码

block js
script().
var submit = false;
$('#submitBtn').on('click', function () {
if (submit) {
return ;
}
var token = $('#inputToken').val();
var oldPassword = $('#inputPassword').val();
var newPassword = $('#inputNewPassword').val();
submit = true;
$.ajax({
type: 'patch',
data: JSON.stringify({oldPassword:oldPassword,newPassword:newPassword}),
contentType: 'application/json;charset=utf-8',
headers: {
Authorization : 'Bearer '+token
},
url: '/users/password',
dataType: 'json',
success: function (data) {
if (data.status == "OK") {
alert("修改成功");
location.href = '/auth/login';
} else if (data.status == 401) {
alert('token invalid');
} else {
alert(data.message);
}
submit = false;
}
});
});

3 changes: 2 additions & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ block content
h1(style="text-align: center;")= title
p(style="text-align: center;") Welcome to #{title}
.site-notice
a.btn.btn-primary(href="/auth/login" type="button") 登录
a.btn.btn-primary(href="/auth/login" type="button") 登录
a.btn.btn-primary.col-md-offset-1(href="/auth/password" type="button") 修改密码
2 changes: 2 additions & 0 deletions views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ doctype html
html
head
title= title
meta(name="keywords" content="code-push-server,code-push,react-native,cordova")
meta(name="description" content="CodePush service is hotupdate services which adapter react-native-code-push and cordova-plugin-code-push")
link(rel='stylesheet', href='/js/bootstrap-3.3.7/css/bootstrap.min.css')
block css
body
Expand Down

0 comments on commit 4fc1f8e

Please sign in to comment.