@@ -506,6 +506,20 @@ class ParseUser extends ParseObject {
506506 } ) ;
507507 }
508508
509+ /**
510+ * Verify whether a given password is the password of the current user.
511+ *
512+ * @param {String } password A password to be verified
513+ * @param {Object } options
514+ * @return {Promise } A promise that is fulfilled with a user
515+ * when the password is correct.
516+ */
517+ verifyPassword ( password : string , options ? : RequestOptions ) : Promise < ParseUser > {
518+ const username = this . getUsername ( ) || '' ;
519+
520+ return ParseUser . verifyPassword ( username , password , options ) ;
521+ }
522+
509523 static readOnlyAttributes ( ) {
510524 return [ 'sessionToken' ] ;
511525 }
@@ -761,6 +775,69 @@ class ParseUser extends ParseObject {
761775 ) ;
762776 }
763777
778+ /**
779+ * Request an email verification.
780+ *
781+ * <p>Calls options.success or options.error on completion.</p>
782+ *
783+ * @param {String } email The email address associated with the user that
784+ * forgot their password.
785+ * @param {Object } options
786+ * @static
787+ * @returns {Promise }
788+ */
789+ static requestEmailVerification ( email : string , options ? : RequestOptions ) {
790+ options = options || { } ;
791+
792+ const requestOptions = { } ;
793+ if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
794+ requestOptions . useMasterKey = options . useMasterKey ;
795+ }
796+
797+ const controller = CoreManager . getUserController ( ) ;
798+ return controller . requestEmailVerification ( email , requestOptions ) ;
799+ }
800+
801+ /**
802+ * Verify whether a given password is the password of the current user.
803+ *
804+ * @param {String } username A username to be used for identificaiton
805+ * @param {String } password A password to be verified
806+ * @param {Object } options
807+ * @static
808+ * @returns {Promise } A promise that is fulfilled with a user
809+ * when the password is correct.
810+ */
811+ static verifyPassword ( username : string , password : string , options ? : RequestOptions ) {
812+ if ( typeof username !== 'string' ) {
813+ return Promise . reject (
814+ new ParseError (
815+ ParseError . OTHER_CAUSE ,
816+ 'Username must be a string.'
817+ )
818+ ) ;
819+ }
820+
821+ if ( typeof password !== 'string' ) {
822+ return Promise . reject (
823+ new ParseError (
824+ ParseError . OTHER_CAUSE ,
825+ 'Password must be a string.'
826+ )
827+ ) ;
828+ }
829+
830+ options = options || { } ;
831+
832+ const verificationOption = { } ;
833+ if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
834+ verificationOption . useMasterKey = options . useMasterKey ;
835+ }
836+
837+ const controller = CoreManager . getUserController ( ) ;
838+ return controller . verifyPassword ( username , password , verificationOption ) ;
839+ }
840+
764841 /**
765842 * Allow someone to define a custom User class without className
766843 * being rewritten to _User. The default behavior is to rewrite
@@ -1160,6 +1237,26 @@ const DefaultController = {
11601237 }
11611238 return user ;
11621239 } ) ;
1240+ } ,
1241+
1242+ verifyPassword ( username : string , password : string , options : RequestOptions ) {
1243+ const RESTController = CoreManager . getRESTController ( ) ;
1244+ return RESTController . request (
1245+ 'GET' ,
1246+ 'verifyPassword' ,
1247+ { username, password } ,
1248+ options
1249+ ) ;
1250+ } ,
1251+
1252+ requestEmailVerification ( email : string , options : RequestOptions ) {
1253+ const RESTController = CoreManager . getRESTController ( ) ;
1254+ return RESTController . request (
1255+ 'POST' ,
1256+ 'verificationEmailRequest' ,
1257+ { email : email } ,
1258+ options
1259+ ) ;
11631260 }
11641261} ;
11651262
0 commit comments