@@ -7,6 +7,8 @@ var moment = require('moment');
7
7
var pg = require ( 'pg' ) ;
8
8
var crypto = require ( 'crypto' ) ;
9
9
10
+ var profileUtils = require ( './lib/profile-utils' ) ;
11
+
10
12
module . exports = function ( options ) {
11
13
var seneca = this ;
12
14
var plugin = 'cd-users' ;
@@ -30,6 +32,7 @@ module.exports = function (options) {
30
32
seneca . add ( { role : plugin , cmd : 'load_champions_for_user' } , cmd_load_champions_for_user ) ;
31
33
seneca . add ( { role : plugin , cmd : 'load_dojo_admins_for_user' } , cmd_load_dojo_admins_for_user ) ;
32
34
seneca . add ( { role : plugin , cmd : 'record_login' } , cmd_record_login ) ;
35
+ seneca . add ( { role : plugin , cmd : 'update_profile_password' } , cmd_update_profile_password ) ;
33
36
seneca . add ( { role : 'user' , cmd : 'login' } , cmd_login ) ;
34
37
seneca . add ( { role : 'user' , cmd : 'cdf_login' } , cmd_cdf_login ) ;
35
38
seneca . add ( { role : plugin , cmd : 'load_prev_founder' } , cmd_load_prev_founder ) ;
@@ -65,6 +68,13 @@ module.exports = function (options) {
65
68
} ) ;
66
69
}
67
70
71
+ function cmd_update_profile_password ( args , done ) {
72
+ profileUtils . encodePassword ( args . password ) . then ( ( profileHash ) => {
73
+ const updatedUser = Object . assign ( { } , args . user , { profilePassword : profileHash } ) ;
74
+ seneca . act ( { role : plugin , cmd : 'update' } , { id : args . user . id , user : updatedUser } , done ) ;
75
+ } ) ;
76
+ }
77
+
68
78
function cmd_load ( args , done ) {
69
79
var seneca = this ;
70
80
var id = args . id ;
@@ -130,6 +140,13 @@ module.exports = function (options) {
130
140
}
131
141
} ;
132
142
143
+ function addProfilePassword ( data , done ) {
144
+ profileUtils . encodePassword ( user . password ) . then ( ( profileHash ) => {
145
+ user . profilePassword = profileHash ;
146
+ done ( null , data ) ;
147
+ } ) ;
148
+ }
149
+
133
150
function verifyCaptcha ( done ) {
134
151
request . post ( postData , function ( err , response , body ) {
135
152
if ( err ) {
@@ -221,6 +238,7 @@ module.exports = function (options) {
221
238
async . waterfall ( [
222
239
verifyCaptcha ,
223
240
checkPermissions ,
241
+ addProfilePassword ,
224
242
registerUser ,
225
243
sendWelcomeEmail
226
244
] , function ( err , results ) {
@@ -428,6 +446,8 @@ module.exports = function (options) {
428
446
out . reset = reset ;
429
447
if ( ! out . ok ) { return done ( null , out ) ; }
430
448
449
+ seneca . act ( { role : plugin , cmd : 'update_profile_password' } , { password : args . password , user : user } ) ;
450
+
431
451
reset . active = false ;
432
452
reset . save$ ( function ( err , reset ) {
433
453
if ( err ) { return done ( err ) ; }
@@ -503,17 +523,28 @@ module.exports = function (options) {
503
523
if ( err ) return done ( err ) ;
504
524
if ( ! loginResponse . ok || ! loginResponse . user ) return done ( null , loginResponse ) ;
505
525
506
- async . series ( [
526
+ const handlers = [
507
527
verifyPermissions ,
508
528
recordLogin
509
- ] , function ( err ) {
529
+ ] ;
530
+
531
+ if ( ! loginResponse . user . profilePassword ) {
532
+ handlers . push ( updateProfilePassword ) ;
533
+ }
534
+
535
+ async . series ( handlers , function ( err ) {
510
536
if ( err ) {
511
537
return done ( err ) ;
512
538
}
513
539
514
540
return done ( null , loginResponse ) ;
515
541
} ) ;
516
542
543
+ function updateProfilePassword ( next ) {
544
+ seneca . act ( { role : plugin , cmd : 'update_profile_password' } , { password : args . password , user : loginResponse . user } ) ;
545
+ next ( ) ;
546
+ }
547
+
517
548
function verifyPermissions ( next ) {
518
549
var userRole ;
519
550
0 commit comments