parse.com - Parse iOS SDK - Login using Mobile phone verification code like Watsapp -
how implement login mechanism mobile verification code.
signup (new user new mobile number)
i can able signup user generating random password after verifying code send mobile number.
login (existing user mobile number) don't knows how implement this. cant use changepassword method because works logged in user.
setting current user
saw method in parse documentation. can use method. if yes, how can session token.
[pfuser becomeinbackground:@"session-token-here" block:^(pfuser *user, nserror *error) { if (error) { // token not validated. } else { // current user set user. } }];
successfully changed password without login calling cloud code ios , logged in new password.
ios code
[pfcloud callfunctioninbackground:@"assignpasswordtouser" withparameters:@{@"username":[self generateusername],@"password":loginmodel.verficationcode} block:^(id object, nserror *error) { if(!error) { nslog(@"assign new password success"); [self dologin]; }else{ nslog(@"assign new password failed"); [self handerror:error]; } }];
cloud code
parse.cloud.define("assignpasswordtouser", function(request, response){ parse.cloud.usemasterkey(); var query = new parse.query(parse.user); query.equalto("username", request.params.username); query.first({ success: function(theuser){ var newpassword = request.params.password; console.log("new password: " + newpassword); console.log("set: " + theuser.set("password", newpassword)); theuser.save(null,{ success: function(theuser){ // user saved correctly response.success(1); }, error: function(smlogin, error){ response.error("save failure"); } }); }, error: function(error){ response.error("error"); } }); });
Comments
Post a Comment