@@ -5,9 +5,10 @@ import utils from '../utils';
55import email from '../email' ;
66
77const router = new Router ( ) ;
8+ const max = ( process . env . NODE_ENV !== 'production' ) ? 50000 : 5 ;
89const loginLimiter = rateLimit ( {
910 windowMs : 60 * 60 * 1000 ,
10- max : 5 ,
11+ max : max ,
1112 message : "Too many login attempts for this IP. Please try again later."
1213} ) ;
1314
@@ -174,7 +175,7 @@ router.put('/', utils.authMiddleware, async (req, res) => {
174175 let code ;
175176 let message ;
176177 try {
177- if ( validator . isEmail ( req . body . email ) && req . body . password !== undefined ) {
178+ if ( validator . isEmail ( req . body . email ) ) {
178179 /** @todo add email and phone update options */
179180 const { email, password, displayName, phone, attributes } = req . body ;
180181 const user = await req . context . models . User . findOne ( {
@@ -186,20 +187,22 @@ router.put('/', utils.authMiddleware, async (req, res) => {
186187
187188
188189 /** @todo when roles are added make sure only admin or relevant user can change password */
189- const e = await utils . loadCasbin ( ) ;
190- const roles = await e . getRolesForUser ( req . context . me . email ) ;
191-
192- if ( password ) {
193- if ( req . context . me . email === email || roles . includes ( 'admin' ) ) {
194- user . password = password ;
190+ if ( ! process . env . BYPASS_LOGIN ) {
191+ const e = await utils . loadCasbin ( ) ;
192+ const roles = await e . getRolesForUser ( req . context . me . email ) ;
193+
194+ if ( password ) {
195+ if ( req . context . me . email === email || roles . includes ( 'admin' ) ) {
196+ user . password = password ;
197+ }
195198 }
196- }
197199
198- /** @todo this is half-baked. Once updating users is available through the front-end this should be revisited. */
199- if ( roles !== undefined ) {
200- const e = await utils . loadCasbin ( ) ;
201- for ( const role of roles ) {
202- await e . addRoleForUser ( email . toLowerCase ( ) , role ) ;
200+ /** @todo this is half-baked. Once updating users is available through the front-end this should be revisited. */
201+ if ( roles !== undefined ) {
202+ const e = await utils . loadCasbin ( ) ;
203+ for ( const role of roles ) {
204+ await e . addRoleForUser ( email . toLowerCase ( ) , role ) ;
205+ }
203206 }
204207 }
205208
@@ -235,6 +238,11 @@ router.delete('/:email', utils.authMiddleware, async (req, res) => {
235238 email : req . params . email . toLowerCase ( )
236239 }
237240 } ) ;
241+
242+ const e = await utils . loadCasbin ( ) ;
243+ await e . deleteRolesForUser ( req . params . email . toLowerCase ( ) ) ;
244+
245+
238246 await user . destroy ( ) ;
239247
240248 code = 200 ;
0 commit comments