Skip to content

Commit f1e3e2a

Browse files
committed
fix: refactor views, improve/simplify the auth workflows
1 parent 21c987a commit f1e3e2a

File tree

15 files changed

+114
-99
lines changed

15 files changed

+114
-99
lines changed

locales/en.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"Please sign in": "Please sign in",
3-
"email address": "email address",
4-
"username": "username",
5-
"password": "password",
6-
"Remember me": "Remember me",
7-
"Log in": "Log in",
8-
"hot update server": "hot update server",
9-
"Change Password": "Change Password",
10-
"Obtain": "Obtain",
11-
"old password": "old password",
12-
"new password": "new password",
13-
"please login again": "please login again",
14-
"change success": "change success"
15-
}
2+
"Please sign in": "Please sign in",
3+
"email address": "email address",
4+
"username": "username",
5+
"password": "password",
6+
"Remember me": "Remember me",
7+
"Log in": "Log in",
8+
"hot update server": "hot update server",
9+
"Change Password": "Change Password",
10+
"Obtain": "Obtain",
11+
"old password": "old password",
12+
"new password": "new password",
13+
"please login again": "please login again",
14+
"change success": "change success",
15+
"Logout": "Logout",
16+
"Register": "Register"
17+
}

locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"old password": "原密码",
1212
"new password": "新密码",
1313
"please login again": "请重新登录",
14-
"change success": "修改成功"
14+
"change success": "修改成功",
15+
"Logout": "登出"
1516
}
File renamed without changes.

public/stylesheets/style.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

public/stylesheets/tokens.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/routes/auth.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ authRouter.get('/password', (req: Req, res) => {
1515
});
1616

1717
authRouter.get('/login', (req: Req<void, void, { email: string }>, res) => {
18-
res.render('auth/login', { title: 'CodePushServer', email: req.query.email || '' });
18+
res.render('auth/login', {
19+
title: 'CodePushServer',
20+
email: req.query.email || '',
21+
showRegister: config.common.allowRegistration,
22+
});
1923
});
2024

2125
authRouter.get('/link', (req: Req, res) => {

views/auth/confirm.pug

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
extends ../layout
1+
extends ../common
2+
23
block css
34
link(rel='stylesheet', href='/stylesheets/signin.css')
45

@@ -30,13 +31,11 @@ block content
3031
button#okBtn.btn.btn-primary(type="button" data-dismiss="modal") OK
3132
block js
3233
script().
33-
var submit = false;
34-
$('#inputEmail').on('click', function () {
35-
location.href = '/auth/register?email=' + $('#inputEmail').val();
36-
});
3734
$('#okBtn').on('click', function () {
3835
location.href = '/auth/login?email=' + $('#inputEmail').val();
3936
});
37+
38+
var submit = false;
4039
$('#submitBtn').on('click', function () {
4140
if (submit) {
4241
return ;

views/auth/login.pug

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
extends ../layout
1+
extends ../common
2+
23
block css
34
link(rel='stylesheet', href='/stylesheets/signin.css')
45

@@ -7,17 +8,29 @@ block content
78
form#form.form-signin(method="post")
89
h2.form-signin-heading #{__('Please sign in')}
910
label.sr-only(for="inputEmail") #{__('email address')}#{__('username')}
10-
input#inputEmail.form-control(type="text" name="account" placeholder=`${__('email address')}${__('username')}` required autofocus)
11+
input#inputEmail.form-control(type="text" name="account" placeholder=`${__('email address')}${__('username')}` value=email required autofocus)
1112
label.sr-only(for="inputPassword") #{__('password')}
1213
input#inputPassword.form-control(type="password" name="password" placeholder=`${__('password')}` required)
13-
.checkbox
14-
label
15-
input(type="checkbox" value="remember-me")
16-
span #{__('Remember me')}
1714
a#submitBtn.btn.btn-lg.btn-primary.btn-block #{__('Log in')}
15+
if showRegister
16+
a#registerBtn.btn.btn-lg.btn-primary.btn-block(href="/auth/register" type="button") #{__('Register')}
1817

1918
block js
2019
script().
20+
function onLoggedIn() {
21+
var query = parseQuery()
22+
if (query.hostname) {
23+
// come from code-push-cli login
24+
location.href = '/tokens/' + location.search;
25+
} else {
26+
location.href = '/';
27+
}
28+
}
29+
30+
if (getAccessToken()) {
31+
onLoggedIn();
32+
}
33+
2134
var submit = false;
2235
$('#submitBtn').on('click', function () {
2336
if (submit) {
@@ -31,9 +44,9 @@ block js
3144
dataType: 'json',
3245
success: function (data) {
3346
if (data.status == "OK") {
34-
sessionStorage.setItem('auth', data.results.tokens)
47+
localStorage.setItem('auth', data.results.tokens)
3548
submit = false;
36-
location.href = '/tokens/' + location.search;
49+
onLoggedIn();
3750
} else {
3851
alert(data.message);
3952
submit = false;

views/auth/password.pug

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
extends ../layout
1+
extends ../common
22

33
block content
44
.container(style="margin-top:30px;")
55
form#form.col-md-5.col-md-offset-3(method="post")
6-
.form-group
7-
label.sr-only(for="inputEmail") #{__('email address')}#{__('username')}
8-
input#inputEmail.form-control(type="text" name="account" placeholder=`${__('email address')}${__('username')}` 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") #{__('Obtain')} token
156
.form-group
167
label.sr-only(for="inputPassword") #{__('old password')}
178
input#inputPassword.form-control(type="password" name="oldPassword" placeholder=`${__('old password')}` required)
@@ -23,30 +14,33 @@ block content
2314

2415
block js
2516
script().
17+
ensureLogin();
18+
2619
var submit = false;
2720
$('#submitBtn').on('click', function () {
2821
if (submit) {
2922
return ;
3023
}
31-
var token = $('#inputToken').val();
24+
submit = true;
25+
var accessToken = getAccessToken();
3226
var oldPassword = $('#inputPassword').val();
3327
var newPassword = $('#inputNewPassword').val();
34-
submit = true;
3528
$.ajax({
3629
type: 'patch',
37-
data: JSON.stringify({oldPassword:oldPassword,newPassword:newPassword}),
30+
data: JSON.stringify({ oldPassword: oldPassword, newPassword: newPassword }),
3831
contentType: 'application/json;charset=utf-8',
3932
headers: {
40-
Authorization : 'Bearer '+token
33+
Authorization : 'Bearer ' + accessToken,
4134
},
4235
url: '/users/password',
4336
dataType: 'json',
4437
success: function (data) {
4538
if (data.status == "OK") {
4639
alert("#{__('change success')}");
47-
location.href = '/auth/login';
40+
logout();
4841
} else if (data.status == 401) {
4942
alert('token invalid');
43+
logout();
5044
} else {
5145
alert(data.message);
5246
}

views/auth/register.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
extends ../layout
1+
extends ../common
2+
23
block css
34
link(rel='stylesheet', href='/stylesheets/signin.css')
45

@@ -27,7 +28,6 @@ block js
2728
success: function (data) {
2829
if (data.status == "OK") {
2930
let email = $('#inputEmail').val();
30-
sessionStorage.setItem('email', email);
3131
location.href = '/auth/confirm?email=' + email;
3232
submit = false;
3333
} else {

0 commit comments

Comments
 (0)