@@ -504,7 +504,9 @@ RestWrite.prototype.ensureUniqueAuthDataId = async function () {
504
504
key => this . data . authData [ key ] && this . data . authData [ key ] . id
505
505
) ;
506
506
507
- if ( ! hasAuthDataId ) { return ; }
507
+ if ( ! hasAuthDataId ) {
508
+ return ;
509
+ }
508
510
509
511
const r = await Auth . findUsersWithAuthData ( this . config , this . data . authData ) ;
510
512
const results = this . filteredObjectsByACL ( r ) ;
@@ -547,7 +549,6 @@ RestWrite.prototype.handleAuthData = async function (authData) {
547
549
548
550
// User found with provided authData
549
551
if ( results . length === 1 ) {
550
-
551
552
this . storage . authProvider = Object . keys ( authData ) . join ( ',' ) ;
552
553
553
554
const { hasMutatedAuthData, mutatedAuthData } = Auth . hasMutatedAuthData (
@@ -809,7 +810,9 @@ RestWrite.prototype._validateEmail = function () {
809
810
} ;
810
811
811
812
RestWrite . prototype . _validatePasswordPolicy = function ( ) {
812
- if ( ! this . config . passwordPolicy ) { return Promise . resolve ( ) ; }
813
+ if ( ! this . config . passwordPolicy ) {
814
+ return Promise . resolve ( ) ;
815
+ }
813
816
return this . _validatePasswordRequirements ( ) . then ( ( ) => {
814
817
return this . _validatePasswordHistory ( ) ;
815
818
} ) ;
@@ -843,18 +846,20 @@ RestWrite.prototype._validatePasswordRequirements = function () {
843
846
if ( this . config . passwordPolicy . doNotAllowUsername === true ) {
844
847
if ( this . data . username ) {
845
848
// username is not passed during password reset
846
- if ( this . data . password . indexOf ( this . data . username ) >= 0 )
847
- { return Promise . reject ( new Parse . Error ( Parse . Error . VALIDATION_ERROR , containsUsernameError ) ) ; }
849
+ if ( this . data . password . indexOf ( this . data . username ) >= 0 ) {
850
+ return Promise . reject ( new Parse . Error ( Parse . Error . VALIDATION_ERROR , containsUsernameError ) ) ;
851
+ }
848
852
} else {
849
853
// retrieve the User object using objectId during password reset
850
854
return this . config . database . find ( '_User' , { objectId : this . objectId ( ) } ) . then ( results => {
851
855
if ( results . length != 1 ) {
852
856
throw undefined ;
853
857
}
854
- if ( this . data . password . indexOf ( results [ 0 ] . username ) >= 0 )
855
- { return Promise . reject (
856
- new Parse . Error ( Parse . Error . VALIDATION_ERROR , containsUsernameError )
857
- ) ; }
858
+ if ( this . data . password . indexOf ( results [ 0 ] . username ) >= 0 ) {
859
+ return Promise . reject (
860
+ new Parse . Error ( Parse . Error . VALIDATION_ERROR , containsUsernameError )
861
+ ) ;
862
+ }
858
863
return Promise . resolve ( ) ;
859
864
} ) ;
860
865
}
@@ -878,19 +883,21 @@ RestWrite.prototype._validatePasswordHistory = function () {
878
883
}
879
884
const user = results [ 0 ] ;
880
885
let oldPasswords = [ ] ;
881
- if ( user . _password_history )
882
- { oldPasswords = _ . take (
883
- user . _password_history ,
884
- this . config . passwordPolicy . maxPasswordHistory - 1
885
- ) ; }
886
+ if ( user . _password_history ) {
887
+ oldPasswords = _ . take (
888
+ user . _password_history ,
889
+ this . config . passwordPolicy . maxPasswordHistory - 1
890
+ ) ;
891
+ }
886
892
oldPasswords . push ( user . password ) ;
887
893
const newPassword = this . data . password ;
888
894
// compare the new password hash with all old password hashes
889
895
const promises = oldPasswords . map ( function ( hash ) {
890
896
return passwordCrypto . compare ( newPassword , hash ) . then ( result => {
891
- if ( result )
892
- // reject if there is a match
893
- { return Promise . reject ( 'REPEAT_PASSWORD' ) ; }
897
+ if ( result ) {
898
+ // reject if there is a match
899
+ return Promise . reject ( 'REPEAT_PASSWORD' ) ;
900
+ }
894
901
return Promise . resolve ( ) ;
895
902
} ) ;
896
903
} ) ;
@@ -900,14 +907,15 @@ RestWrite.prototype._validatePasswordHistory = function () {
900
907
return Promise . resolve ( ) ;
901
908
} )
902
909
. catch ( err => {
903
- if ( err === 'REPEAT_PASSWORD' )
904
- // a match was found
905
- { return Promise . reject (
906
- new Parse . Error (
907
- Parse . Error . VALIDATION_ERROR ,
908
- `New password should not be the same as last ${ this . config . passwordPolicy . maxPasswordHistory } passwords.`
909
- )
910
- ) ; }
910
+ if ( err === 'REPEAT_PASSWORD' ) {
911
+ // a match was found
912
+ return Promise . reject (
913
+ new Parse . Error (
914
+ Parse . Error . VALIDATION_ERROR ,
915
+ `New password should not be the same as last ${ this . config . passwordPolicy . maxPasswordHistory } passwords.`
916
+ )
917
+ ) ;
918
+ }
911
919
throw err ;
912
920
} ) ;
913
921
} ) ;
@@ -941,10 +949,16 @@ RestWrite.prototype.createSessionTokenIfNeeded = async function () {
941
949
// Get verification conditions which can be booleans or functions; the purpose of this async/await
942
950
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
943
951
// conditional statement below, as a developer may decide to execute expensive operations in them
944
- const verifyUserEmails = async ( ) => this . config . verifyUserEmails === true || ( typeof this . config . verifyUserEmails === 'function' && await Promise . resolve ( this . config . verifyUserEmails ( request ) ) === true ) ;
945
- const preventLoginWithUnverifiedEmail = async ( ) => this . config . preventLoginWithUnverifiedEmail === true || ( typeof this . config . preventLoginWithUnverifiedEmail === 'function' && await Promise . resolve ( this . config . preventLoginWithUnverifiedEmail ( request ) ) === true ) ;
952
+ const verifyUserEmails = async ( ) =>
953
+ this . config . verifyUserEmails === true ||
954
+ ( typeof this . config . verifyUserEmails === 'function' &&
955
+ ( await Promise . resolve ( this . config . verifyUserEmails ( request ) ) ) === true ) ;
956
+ const preventLoginWithUnverifiedEmail = async ( ) =>
957
+ this . config . preventLoginWithUnverifiedEmail === true ||
958
+ ( typeof this . config . preventLoginWithUnverifiedEmail === 'function' &&
959
+ ( await Promise . resolve ( this . config . preventLoginWithUnverifiedEmail ( request ) ) ) === true ) ;
946
960
// If verification is required
947
- if ( await verifyUserEmails ( ) && await preventLoginWithUnverifiedEmail ( ) ) {
961
+ if ( ( await verifyUserEmails ( ) ) && ( await preventLoginWithUnverifiedEmail ( ) ) ) {
948
962
this . storage . rejectSignup = true ;
949
963
return ;
950
964
}
@@ -1436,6 +1450,23 @@ RestWrite.prototype.runDatabaseOperation = function () {
1436
1450
`Cannot modify user ${ this . query . objectId } .`
1437
1451
) ;
1438
1452
}
1453
+ // Handle authData updates for _User class
1454
+ if (
1455
+ this . className === '_User' &&
1456
+ this . query &&
1457
+ this . data &&
1458
+ Object . prototype . hasOwnProperty . call ( this . data , 'authData' )
1459
+ ) {
1460
+ if ( ! this . auth . isMaster && ! this . auth . isMaintenance ) {
1461
+ // For non-master key requests, remove authData from the update
1462
+ delete this . data . authData ;
1463
+ // If no other fields to update, return early
1464
+ if ( Object . keys ( this . data ) . length === 0 ) {
1465
+ this . response = { response : { } } ;
1466
+ return Promise . resolve ( ) ;
1467
+ }
1468
+ }
1469
+ }
1439
1470
1440
1471
if ( this . className === '_Product' && this . data . download ) {
1441
1472
this . data . downloadName = this . data . download . name ;
@@ -1746,7 +1777,9 @@ RestWrite.prototype.buildParseObjects = function () {
1746
1777
}
1747
1778
let curObj = parentVal ;
1748
1779
for ( let i = 1 ; i < splittedKey . length - 1 ; i ++ ) {
1749
- if ( typeof curObj [ splittedKey [ i ] ] === 'undefined' ) curObj [ splittedKey [ i ] ] = { } ;
1780
+ if ( typeof curObj [ splittedKey [ i ] ] === 'undefined' ) {
1781
+ curObj [ splittedKey [ i ] ] = { } ;
1782
+ }
1750
1783
curObj = curObj [ splittedKey [ i ] ] ;
1751
1784
}
1752
1785
curObj [ splittedKey [ splittedKey . length - 1 ] ] = data [ key ] ;
0 commit comments