Skip to content

Commit 4fc1f8e

Browse files
committed
add modify password
1 parent 1c11cd9 commit 4fc1f8e

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

core/middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ middleware.checkToken = function(req, res, next) {
8585
authType = 2;
8686
authToken = _.trim(_.trimStart(_.get(req, 'query.access_token', null)));
8787
}
88-
if (authType == 1) {
88+
if (authToken && authType == 1) {
8989
checkAuthToken(authToken)
9090
.then((users) => {
9191
req.users = users;
@@ -99,7 +99,7 @@ middleware.checkToken = function(req, res, next) {
9999
next(e);
100100
}
101101
});
102-
} else if (authType == 2) {
102+
} else if (authToken && authType == 2) {
103103
checkAccessToken(authToken)
104104
.then((users) => {
105105
req.users = users;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"config",
8989
"core",
9090
"docs",
91+
"docker",
9192
"models",
9293
"public",
9394
"routes",

routes/auth.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ var validator = require('validator');
66
var log4js = require('log4js');
77
var log = log4js.getLogger("cps:auth");
88

9+
router.get('/password', (req, res) => {
10+
res.render('auth/password', { title: 'CodePushServer' });
11+
});
12+
913
router.get('/login', (req, res) => {
1014
var codePushWebUrl = _.get(config, 'common.codePushWebUrl');
1115
if (codePushWebUrl && validator.isURL(codePushWebUrl)) {

views/auth/password.pug

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
extends ../layout
2+
3+
block content
4+
.container(style="margin-top:30px;")
5+
form#form.col-md-5.col-md-offset-3(method="post")
6+
.form-group
7+
label.sr-only(for="inputEmail") 邮箱地址/用户名
8+
input#inputEmail.form-control(type="text" name="account" placeholder="邮箱地址/用户名" required autofocus)
9+
.form-group
10+
.col-md-10(style="margin-left:-15px;")
11+
label.sr-only(for="inputToken") token
12+
input#inputToken.form-control(type="text" name="token" placeholder="token" required)
13+
.col-md-2
14+
a.form-control.btn.btn-link(style="margin-bottom:15px;" target="_blank" href="/auth/login") 获取token
15+
.form-group
16+
label.sr-only(for="inputPassword") 原密码
17+
input#inputPassword.form-control(type="password" name="oldPassword" placeholder="原密码" required)
18+
.form-group
19+
label.sr-only(for="inputNewPassword") 新密码
20+
input#inputNewPassword.form-control(type="password" name="newPassword" placeholder="新密码" required)
21+
.form-group
22+
a#submitBtn.btn.btn-lg.btn-primary.btn-block 修改密码
23+
24+
block js
25+
script().
26+
var submit = false;
27+
$('#submitBtn').on('click', function () {
28+
if (submit) {
29+
return ;
30+
}
31+
var token = $('#inputToken').val();
32+
var oldPassword = $('#inputPassword').val();
33+
var newPassword = $('#inputNewPassword').val();
34+
submit = true;
35+
$.ajax({
36+
type: 'patch',
37+
data: JSON.stringify({oldPassword:oldPassword,newPassword:newPassword}),
38+
contentType: 'application/json;charset=utf-8',
39+
headers: {
40+
Authorization : 'Bearer '+token
41+
},
42+
url: '/users/password',
43+
dataType: 'json',
44+
success: function (data) {
45+
if (data.status == "OK") {
46+
alert("修改成功");
47+
location.href = '/auth/login';
48+
} else if (data.status == 401) {
49+
alert('token invalid');
50+
} else {
51+
alert(data.message);
52+
}
53+
submit = false;
54+
}
55+
});
56+
});
57+

views/index.pug

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ block content
77
h1(style="text-align: center;")= title
88
p(style="text-align: center;") Welcome to #{title}
99
.site-notice
10-
a.btn.btn-primary(href="/auth/login" type="button") 登录
10+
a.btn.btn-primary(href="/auth/login" type="button") 登录
11+
a.btn.btn-primary.col-md-offset-1(href="/auth/password" type="button") 修改密码

views/layout.pug

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ doctype html
22
html
33
head
44
title= title
5+
meta(name="keywords" content="code-push-server,code-push,react-native,cordova")
6+
meta(name="description" content="CodePush service is hotupdate services which adapter react-native-code-push and cordova-plugin-code-push")
57
link(rel='stylesheet', href='/js/bootstrap-3.3.7/css/bootstrap.min.css')
68
block css
79
body

0 commit comments

Comments
 (0)