Xcode forgot password Parse - ios

- (IBAction)forgotPassword:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Direccion de Correo" message:#"Introduzca su correo electronico:" delegate:self cancelButtonTitle:#"Cancelar" otherButtonTitles:#"Aceptar", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex ==1){
NSLog(#"ok button clicked in forgot password alert view");
NSString *email=[alertView textFieldAtIndex:0].text;
if ([email isEqualToString:#"email"]) {
UIAlertView *display;
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Please enter password for resetting password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[display show];
}else{
[PFUser requestPasswordResetForEmailInBackground:email block:^(BOOL succeeded, NSError *error) {
UIAlertView *display;
if(succeeded){
display=[[UIAlertView alloc] initWithTitle:#"Correo electronico enviado" message:#"Por favor, revise su correo para resetear contraseƱa" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
}else{
display=[[UIAlertView alloc] initWithTitle:#"Correo fallido" message:#"el correo electronico no coincide con ninguno en la base de datos" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}
}
}

Why you are going for multiple queries first to find User details if found send ResetPasswordRequest instead use completion handler for Reset Request.
[PFUser requestPasswordResetForEmailInBackground:self.txtEmail.text block:^(BOOL succeeded,NSError *error)
{
if (!error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: #"Link to reset the password has been send to specified email"] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
return;
}
else
{
NSString *errorString = [error userInfo][#"error"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: #"Password reset failed: %#",errorString] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
return;
}
}];
If user is not present Parse will respond with an error "Error: no user found with email xxxxxxxxx#xxx.com"
Regards,
Amit

In your below code,
//Here you fire the query to check for email address in your parse backend
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) { //If no error in your query then will enter below block
//the objects is array of object it gets from your parse but in your case it return's zero which implies that there is no object with that email in your parse db.
if (objects.count ==0) {
//As objects.count is zero that means no email exist so in that case you don't send email for password recovery and show a alert as below to user that email is invalid(meaning not exist)
UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:#"Correo enviado" message:#"Por favor, revise su correo para resetear su contraseƱa" delegate:self cancelButtonTitle:#"Cancelar" otherButtonTitles:nil];
[alertView show];
} else {
//In this, else case will enter when there is objects.count greater than zero which means that email exist on db. So, in that case you would request for password recovery as below.
//Also could show a alert to let user know that request for password recovery was sent successfully.
[self sendEmail:emailTextField.text];
//the query was successful, but found 0 results
//email does not exist in the database, dont send the email
//show your alert view here
}
} else {
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
Why are again checking condition(objects == nil) as your doing in first condition(object.count == 0). Both are same so no point in showing alert for one reason. Also I ran your code and I was getting one alert to enter some text followed by a alert with title "Correo enviado".
If I misunderstand your query or anything else then please let me know.

Related

Multiple if-else conditions in ios [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a sign-up view controller that contains multiple text fields to register the user.
I need to validate all the text fields such as not empty, valid email, username, password etc. and display the alert message for all different condition.
Now I following the approach as:
if (condition) {
if (condition) {
if (condition) {
} else {
[alert show];
}
} else {
[alert show];
}
} else {
[alert show];
}
I know this is not the best approach. So guys please suggest an appropriate way to do that task.
Thanks,
Multiple If else Condition
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
NSString *mobileRegex = #"[0-9]{6,14}$";
NSPredicate *mobileTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", mobileRegex]
if (txtName.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Name" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Mobile Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if ([mobileTest evaluateWithObject:txtMobile.text] == NO)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Mobile Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length < 10)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Phone Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtMobile.text.length > 10)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Phone Number" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if (txtEmail.text.length == 0)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter Email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else if ([emailTest evaluateWithObject:txtEmail.text] == NO)
{
[[[UIAlertView alloc]initWithTitle:#"Alert" message:#"Please Enter valid Email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else
{
//success Code
}
Here isAllFieldsAreValid() will validate all the fields you can add all the validation here.
showAlert is a method to show alert about error.
allTrim() is a macro that will trim whitespace.
- (BOOL)isAllFieldsAreValid {
//here only empty string is checked you can add other if-else to validate email, phno, etc.
if ([allTrim(self.txtFname.text) isEqualToString:#""]) {
[self showAlert:#"Please enter first name."];
return false;
} else if ([allTrim(self.txtLname.text) isEqualToString:#""]) {
[self showAlert:#"Please enter last name."];
return false;
} else if ([allTrim(self.txtEmail_SignUp.text) isEqualToString:#""]) {
[self showAlert:#"Please enter email id."];
return false;
} else if ([allTrim(self.txtPassword_SignUp.text) isEqualToString:#""]) {
[self showAlert:#"Please enter password."];
return false;
}
return true;
}
You can call this on button click and upon true and false you can take action.
- (IBAction)buttonTappedInLoginView:(UIButton *)sender {
if ([self isAllFieldsAreValid]) {
// do stuff
}
}
Use this code,
if (firstnametf.text.length==0 || lastnametf.text.length==0 || emailtf.text.length==0 || myimageView.image == nil || commenttf.text.length==0 || [commenttf.text isEqualToString:#"Comment"])
{
[self validatetextfield];
}
else if (![emailtf.text isEqualToString:#""])
{
NSString *emailRegEx = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailRegEx];
//Valid email address
if ([emailTest evaluateWithObject:emailtf.text] == YES)
{
//All conditions are checked, you will set the function
}
else if ()
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test!" message:#"Please Enter Valid Email Address. \nex. fdsjfkd#mail.com" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
}
Method:
-(void) validatetextfield
{
if (firstnametf.text.length==0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Firstname Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[firstnametf becomeFirstResponder];
}
else if (lastnametf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Lastname Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[lastnametf becomeFirstResponder];
}
else if (emailtf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Email Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[emailtf becomeFirstResponder];
}
else if(commenttf.text.length==0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Comment Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[commenttf becomeFirstResponder];
}
else if ([commenttf.text isEqualToString:#"Comment"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Comment Field Empty!" message:#"Please Enter the Valid Details" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[commenttf becomeFirstResponder];
}
else if (myimageView.image == nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Image not Upload!" message:#"Please Upload Image" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Change the Alert condition, hope its helpful

I am trying to call an UIAlertView method for particular UIButton like UpdateEmail or ForgotPassword but properly call i am use this code

I am using this code for Update Email Address and Forgot Password but their is a problem when I click on 'ForgotPassword' button it's work properly but when I click on 'UpdateEmail' button it not work properly it call the UIAlert for 'ForgotPassword' button and I am trying to call" else if (self.ForgotPassword.tag == 1) part of -(Void)alertView " for when I press 'UpdateEmail' UIButton.
//Forgot method for ForgotPassword
-(IBAction)ForgotPassword:(id)sender
{
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#"Please enter your email id" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
}
//Method for Update Email Address
-(IBAction)UpdateEmail:(id)sender
{
if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Update Email"
message:#"Enter Your Email Address"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
else
{
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Please First Loginig"
message:#"Please First Loging"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
}
}
// Method for Alert View
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
self.ForgotPassword.tag=0;
self.UpdateEmail.tag=1;
if (self.ForgotPassword.tag == 0){
if(buttonIndex ==1){
NSLog(#"ok button clicked in forgot password alert view");
NSString *femailId=[alertView textFieldAtIndex:0].text;
if ([femailId isEqualToString:#""]){
UIAlertView *display;
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Please enter password for resetting password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[display show];
}else{
[PFUser requestPasswordResetForEmailInBackground:femailId block:^(BOOL succeeded, NSError *error){
UIAlertView *display;
if(succeeded){
display=[[UIAlertView alloc] initWithTitle:#"Password email" message:#"Please check your email for resetting the password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
}else{
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Email doesn't exists in our database" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}
}
}else if (self.ForgotPassword.tag == 1){
PFUser *user = [PFUser currentUser];
user[#"email"] = [alertView textFieldAtIndex:0].text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if (succeeded){
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Email Upadated!"
message:#"your Email is Updated"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
//NSLog(#"Success");
}else{
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:#"Email is NOT Update"
message:#"Email is alredy registred"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
[myAlert1 show];
NSLog(#"Error");
}
}];
}
}
You need to give tag to your two different UIAlertView like below.
-(IBAction)ForgotPassword:(id)sender
{
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#"Please enter your email id" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
forgotPassword.tag = 0; //// Here for forgot password
}
-(IBAction)UpdateEmail:(id)sender
{
if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Update Email"
message:#"Enter Your Email Address"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
alert.tag =1; ///Here for email update
}
}
Then, in -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex, you can detect which alertView's button was clicked.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
{
if(alertView.tag == 0) /// Because we assigned forgotPassword.tag = 0; above for forgotPassword
{
if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Forgot Password.
}
}
else if(alertView.tag ==1) /// Because we assigned alert.tag = 1; above for update email
{
if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Update Email.
}
}
}

forgot password/username Xcode

I am building login/signup pages and it's work so perfectly.
But I just want to know how I can add a label or a button for the "Forgot my password or username" on the login page.
I'd like to have a pop up message or an alert that allows the user to enter their Email
so in case their Email doesn't exist in the database there will pop a message that says, that this email is not correct or something
in case the email already exists in the database I want to send the username and a new password to the user.
Please note that I am using parse.
Thank you,
First display an alert view with type UIAlertViewStylePlainTextInput
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#"Please enter your email id" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
and in your alert view delegate
if(buttonIndex ==1){
NSLog(#"ok button clicked in forgot password alert view");
NSString *femailId=[alertView textFieldAtIndex:0].text;
if ([femailId isEqualToString:#""]) {
UIAlertView *display;
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Please enter password for resetting password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[display show];
}else{
[PFUser requestPasswordResetForEmailInBackground:femailId block:^(BOOL succeeded, NSError *error) {
UIAlertView *display;
if(succeeded){
display=[[UIAlertView alloc] initWithTitle:#"Password email" message:#"Please check your email for resetting the password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
}else{
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Email doesn't exists in our database" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}

iOS Incompatible block pointer types issue

I have an implementation problem with a project using MKStoreKit. I am trying to implement an UIAlertView with various purchase options.
Here is the code where I do various things and call up UIAlertView:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if(FALSE == payWallFlag)
{
// Display Alert Dialog
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Subscription Options"
message:#"You do not have an active subscription. Please purchase one of the options below."
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[message addButtonWithTitle:#"7 Day Subscription $0.99"];
[message show];
return FALSE;
} else if(TRUE == payWallFlag)
{
// Load content
}
}
This is the physical alertView with the code which I am trying to call:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Cancel"])
{
NSLog(#"Cancel Button was selected.");
}
else if([title isEqualToString:#"7 Day Subscription $0.99"])
{
NSLog(#"7 Day Subscription button pressed.");
//Buy a 7 day subscription
if([SKPaymentQueue canMakePayments]) {
[[MKStoreManager sharedManager] buyFeature:kFeatureAId onComplete:^(NSString* purchasedFeature)
{
NSLog(#"Purchased: %#", purchasedFeature);
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Successful"
message:#"Thank you. You have successfully purchased a 7 Day Subscription."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Show the user the content now
payWallFlag = TRUE;
return TRUE;
}
onCancelled:^
{
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Failed"
message:#"Unfortunately you have cancelled your purchase of a 7 Day Subscription. Please try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Block the content again
payWallFlag = FALSE;
}];
}
else
{
NSLog(#"Parental control enabled");
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Purchase Failed"
message:#"Unfortunately Parental Controls are preventing you from purchasing a subscription. Please try again."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];
// Block the content again
payWallFlag = FALSE;
}
}
}
The issue is I get the following Xcode error message in the UIAlertView:
Incompatible block pointer types sending 'int (^)(NSString *)' to parameter of type 'void (^)(NSString *)'
It appears the problems are: onComplete:^(NSString* purchasedFeature) and onCancelled:^ but I have no idea how to fix this.
You should not return TRUE; from that block, because then the compiler assumes that block returns an int, while it should return void (hence incompatible block types).
...onComplete:^(NSString* purchasedFeature) {
NSLog(#"Purchased: %#", purchasedFeature);
// Send an alert to the user
UIAlertView *alert = [[UIAlertView alloc] ...];
[alert autorelease];
[alert show];
// Show the user the content now
payWallFlag = TRUE;
return TRUE; // <--- Remove this line.
}...
For the second block (the onCancelled one), you probably missed the NSString* parameter, or whatever it expects.

Facebook Connect Graph API get notification when successfully sharing to facebook

I use this code to share to facebook:
[appDelegate.facebook dialog:#"feed" andParams:params andDelegate:appDelegate];
How can i get the notification (like sharekit) when sharing is successful?
I want to show UIAlertView but i do not know which facebook method that i need to put the UIAlertView.
I try in this method:
- (void)dialogDidSucceed:(NSURL *)url {
if ([_delegate respondsToSelector:#selector(dialogCompleteWithUrl:)]) {
[_delegate dialogCompleteWithUrl:url];
}
UIAlertView * alert=[[UIAlertView alloc]
initWithTitle: #"Sharing to Facebook"
message: #"Success"
delegate:self
cancelButtonTitle:#"Close"
otherButtonTitles:nil, nil];
[self setAlertSuccess:alert];
[alertSuccess show];
[alert release];
NSLog(#"SUCCESS 2");
[self dismissWithSuccess:YES animated:YES];
}
It is working however, when i click cancel button, this method is also called. So where is the right one to put the success alert view?
I am new in IOS.
These are changes i made in FBDialog.m
- (void)dismissWithSuccess:(BOOL)success animated:(BOOL)animated {
if (success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook Login Sucessful!" message:#"" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
if ([_delegate respondsToSelector:#selector(dialogDidComplete:)]) {
[_delegate dialogDidComplete:self];
}
} else {
if ([_delegate respondsToSelector:#selector(dialogDidNotComplete:)]) {
[_delegate dialogDidNotComplete:self];
}
}
[self dismiss:animated];
}

Resources