ios - Include email verification within signUpInBackgroundWithBlock function -
i have implemented following function (attached "register button") within registration view controller seen below. function relies upon parse , seamless in general.
however encountering following issues @ present:
if user inserts invalid email address mistake; error string listed under "else" activated (which good) username , password entered above registered regardless.
users able leave password field blank.
any whatsoever, pertaining issue 1, immensely appreciated.
// register user. - (ibaction)registeruser:(id)sender { pfuser *user = [pfuser user]; user.username = self.mobiletextfield.text; user.password = self.passwordtextfield.text; user.email = self.emailtextfield.text; // show loading hud. [mbprogresshud showhudaddedto:self.view animated:yes]; dispatch_async(dispatch_get_global_queue( dispatch_queue_priority_low, 0), ^{ [user signupinbackgroundwithblock:^(bool succeeded, nserror *error) { if (!error) { [self performseguewithidentifier:@"userregistered" sender:self]; } else { nsstring *errorstring = [[error userinfo] objectforkey:@"error"]; uialertview *erroralertview = [[uialertview alloc] initwithtitle:@"error" message:errorstring delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [erroralertview show]; // dismiss loading hud. dispatch_async(dispatch_get_main_queue(), ^{ [mbprogresshud hidehudforview:self.view animated:yes]; }); } }]; // end editing. [self.view endediting: yes]; }); }
you have number of problems here.
a, absolutely do not need , should not take new thread. parse you. must change it.
b, may looking magic formula in parse "if ( (!succeeded) || error)..."
c, should locally check email valid before sending it. (ie, can't enter "xyz@hotmail" or not sensible email.)
ie, need write routine "checkthisemailisvalid". if need yell out. note it's not easy conceptually. understand parse try verify email right? ie send 1 of emails "new user, click here verify email!" you're familiar that?
d, great secret 202 error code
here's example code production app, hope helps!
-(void)_actuallyjoin { ... things check email valid ... in app username lowercase email pfuser *nuser = [pfuser user]; nuser.username = [self.email.text lowercasestring]; ... in app, email email, password password nuser.email = self.email.text; nuser.password = self.password.text; [app huddie]; app.hud.labeltext = @"registering ..."; app.hud.detailslabeltext = @"1 of 3 ..."; ... mbprogresshud. [nuser signupinbackgroundwithblock:^(bool succeeded, nserror *error) { if ( (!succeeded) || error) { [app.hud hide:yes]; .. that's mbprogresshud .. usually, blank form while app connecting self.email.text = @""; self.password.text = @""; self.confirmpassword.text = @""; if ( error.code == 202 ) { [pfanalytics trackevent:@"newaccount" dimensions:@{ @"result":@"emailalreadyused" }]; [self woe:@"that email address in use...."]; [pfuser logout]; .. don't forget return; } [pfanalytics trackevent:@"newaccount" dimensions:@{ @"result":@"connectionwoe" }]; [self woe:@"couldn't connect. please try later"]; return; } nslog(@"step 1 rego success"); [self _actuallyjoinsteptwo]; ... continue save other information ... example user's address, age, avatar photo etc. }]; }
Comments
Post a Comment