@@ -20,10 +20,7 @@ const signupOrLogin = async ctx => {
20
20
// then set it as the returnTo value for when we log in
21
21
if ( _ . isString ( ctx . query . return_to ) && ! s . isBlank ( ctx . query . return_to ) ) {
22
22
ctx . session . returnTo = ctx . query . return_to ;
23
- } else if (
24
- _ . isString ( ctx . query . redirect_to ) &&
25
- ! s . isBlank ( ctx . query . redirect_to )
26
- ) {
23
+ } else if ( _ . isString ( ctx . query . redirect_to ) && ! s . isBlank ( ctx . query . redirect_to ) ) {
27
24
// in case people had a typo, we should support redirect_to as well
28
25
ctx . session . returnTo = ctx . query . redirect_to ;
29
26
}
@@ -34,16 +31,11 @@ const signupOrLogin = async ctx => {
34
31
ctx . session . returnTo . indexOf ( '://' ) !== - 1 &&
35
32
ctx . session . returnTo . indexOf ( config . urls . web ) !== 0
36
33
) {
37
- logger . warn (
38
- `Prevented abuse with returnTo hijacking to ${ ctx . session . returnTo } `
39
- ) ;
34
+ logger . warn ( `Prevented abuse with returnTo hijacking to ${ ctx . session . returnTo } ` ) ;
40
35
ctx . session . returnTo = null ;
41
36
}
42
37
43
- ctx . state . verb =
44
- ctx . path . replace ( `/${ ctx . req . locale } ` , '' ) === '/signup'
45
- ? 'sign up'
46
- : 'log in' ;
38
+ ctx . state . verb = ctx . path . replace ( `/${ ctx . req . locale } ` , '' ) === '/signup' ? 'sign up' : 'log in' ;
47
39
48
40
await ctx . render ( 'signup-or-login' ) ;
49
41
} ;
@@ -54,8 +46,7 @@ const login = async (ctx, next) => {
54
46
return new Promise ( async ( resolve , reject ) => {
55
47
if ( err ) return reject ( err ) ;
56
48
57
- let redirectTo = `/${ ctx . req . locale } ${ config . auth . callbackOpts
58
- . successReturnToOrRedirect } `;
49
+ let redirectTo = `/${ ctx . req . locale } ${ config . auth . callbackOpts . successReturnToOrRedirect } ` ;
59
50
60
51
if ( ctx . session && ctx . session . returnTo ) {
61
52
redirectTo = ctx . session . returnTo ;
@@ -69,7 +60,7 @@ const login = async (ctx, next) => {
69
60
return reject ( err ) ;
70
61
}
71
62
72
- if ( ctx . is ( 'json' ) ) {
63
+ if ( ctx . accepts ( 'json' ) ) {
73
64
ctx . body = {
74
65
message : ctx . translate ( 'LOGGED_IN' ) ,
75
66
redirectTo,
@@ -96,6 +87,9 @@ const login = async (ctx, next) => {
96
87
const register = async ctx => {
97
88
const { body } = ctx . request ;
98
89
90
+ if ( Object . keys ( body ) . length === 0 )
91
+ return ctx . throw ( Boom . badData ( ctx . translate ( 'MISSING_REGISTER_FIELDS' ) ) ) ;
92
+
99
93
if ( ! _ . isString ( body . email ) || ! validator . isEmail ( body . email ) )
100
94
return ctx . throw ( Boom . badRequest ( ctx . translate ( 'INVALID_EMAIL' ) ) ) ;
101
95
@@ -119,7 +113,7 @@ const register = async ctx => {
119
113
delete ctx . session . returnTo ;
120
114
}
121
115
122
- if ( ctx . is ( 'json' ) ) {
116
+ if ( ctx . accepts ( 'json' ) ) {
123
117
ctx . body = {
124
118
message : ctx . translate ( 'REGISTERED' ) ,
125
119
redirectTo
@@ -161,7 +155,7 @@ const forgotPassword = async ctx => {
161
155
// we always say "a password reset request has been sent to your email"
162
156
// and if the email didn't exist in our system then we simply don't send it
163
157
if ( ! user ) {
164
- if ( ctx . is ( 'json' ) ) {
158
+ if ( ctx . accepts ( 'json' ) ) {
165
159
ctx . body = {
166
160
message : ctx . translate ( 'PASSWORD_RESET_SENT' )
167
161
} ;
@@ -180,10 +174,7 @@ const forgotPassword = async ctx => {
180
174
)
181
175
return ctx . throw (
182
176
Boom . badRequest (
183
- ctx . translate (
184
- 'PASSWORD_RESET_LIMIT' ,
185
- moment ( user . reset_token_expires_at ) . fromNow ( )
186
- )
177
+ ctx . translate ( 'PASSWORD_RESET_LIMIT' , moment ( user . reset_token_expires_at ) . fromNow ( ) )
187
178
)
188
179
) ;
189
180
@@ -195,7 +186,7 @@ const forgotPassword = async ctx => {
195
186
196
187
await user . save ( ) ;
197
188
198
- if ( ctx . is ( 'json' ) ) {
189
+ if ( ctx . accepts ( 'json' ) ) {
199
190
ctx . body = {
200
191
message : ctx . translate ( 'PASSWORD_RESET_SENT' )
201
192
} ;
@@ -259,7 +250,7 @@ const resetPassword = async ctx => {
259
250
} finally {
260
251
await user . save ( ) ;
261
252
await util . promisify ( ctx . login ) . bind ( ctx . req ) ( user ) ;
262
- if ( ctx . is ( 'json' ) ) {
253
+ if ( ctx . accepts ( 'json' ) ) {
263
254
ctx . body = {
264
255
message : ctx . translate ( 'RESET_PASSWORD' ) ,
265
256
redirectTo : `/${ ctx . req . locale } `
0 commit comments