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];
}];
}
Related
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.
}
}
}
I have an app that shows tweets on a map and when one is selected it shows more details for the tweet (twitter handle, the tweet, profile pic, etc.) There are buttons for favoriting and retweeting the tweet. The app uses STTwitter to interact with the Twitter API and authenticates the user of the app with twitter = [STTwitterAPI twitterAPIOSWithFirstAccount]; For retweeting and favoriting in the tweet detail view, I do this:
- (IBAction)retweet:(id)sender {
[twitter postStatusRetweetWithID:tweetID successBlock:^(NSDictionary *status) {
UIAlertView *retweetSuccess = [[UIAlertView alloc]initWithTitle:#"Retweeted!" message:#"You have retweeted this post." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[retweetSuccess show];
} errorBlock:^(NSError *error) {
UIAlertView *retweetFailure = [[UIAlertView alloc]initWithTitle:#"Retweet Failed!" message:#"" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[retweetFailure show];
}];
}
- (IBAction)favorite:(id)sender {
[twitter postFavoriteCreateWithStatusID:tweetID includeEntities:nil successBlock:^(NSDictionary *status) {
UIAlertView *favoriteSuccess = [[UIAlertView alloc]initWithTitle:#"Favorited!" message:#"You have favorited this post." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[favoriteSuccess show];
} errorBlock:^(NSError *error) {
UIAlertView *favoriteFailure = [[UIAlertView alloc]initWithTitle:#"Favorite Failed!" message:#"" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[favoriteFailure show];
}];
}
How can I detect if a tweet has already been retweeted or favorited by the user so I can show a different button image for the retweet and favorite buttons?
- (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.
I want to implement a function that allows users to reset their password. I already created a button that displays an alert view and asks for their email, but when I tap ok, it doesn't send an email.
What can I do?
-(IBAction)forget:(id)sender {
[PFUser requestPasswordResetForEmailInBackground:#"email#example.com"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Email Address" message:#"Enter the email for your account:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (IBAction)forget:(id)sender {
[self getEmail];
}
- (void)getEmail {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Email Address" message:#"Enter the email for your account:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
UITextField *emailTextField = [alertView textFieldAtIndex:0];
[self sendEmail:emailTextField.text];
}
}
- (void)sendEmail:(NSString *)email{
[PFUser requestPasswordResetForEmailInBackground:email];
}
In my Calorie Tracker App, I have two textfields. One is for the name of the food, and the other is for the amount of calories.To check and see if they are filled I wrote the following code:
if([foodString isEqual: #" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You have not entered the name of the meal!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else if([self.amountText isEqual: #" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You have not enteted the amount of calories!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else if([self.amountText isEqual:#" "] && [foodString isEqual:#" "])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"You haven't entered anything!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
So for the one where the amountText textfield isn't filled out, but the nameOfFood is filled out, there is an alert. For the rest however, there is no alert. If anyone could provide the proper syntax for checking to see if my textfields are being filled out properly, it would be much appreciated.
Remember, my first textfield is a string value, and the other is an integer value.
Thanks in advance.