Parse PFLogin email verification - authentication

I wonder if anyone is able to provide a code example of Parse login where the email address must be validated and also must be from a specific address. I believe it is something like;
[query whereKey:#"emailVerified" equalTo:[NSNumber numberWithBool:YES]];
and
[query whereKey:#"comment" containsString:#"#gmail.com"];
but I have been unable to get this working in my project.
Any help or suggestions would be great but a piece of code would be awesome
Below is my existing code which will not let an unverified email user login but now I want to add the email handle
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"User not validated email");
[[[UIAlertView alloc] initWithTitle:#"Access restricted" message:#"To access this area please validate your email address" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
else if ([[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:#"Welcome back" message:(#"%#", user.username) delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
NSLog(#"Login sucessfull and username is %#",user.username);
}

Are you performing this check prior to allowing the user to login? If so the email being verified can be checked easily.
You can create a helper method with the following
- (void)methodname:(PFUser *)User {
if (![[user objectForKey:#"emailVerified"] boolValue]) {
// make sure user did not recently verify email address
[user refresh];
if (![[user objectForKey:#"emailVerified"] boolValue]) {
// handle how you want to tell user they need to verify email address
[self redirectWithMessage:#"You must verify your email address"];
return;
}
} else if {
// check for specific address and handle if doesn't meet that requirement
} else {
// The user verified and email is of correct address - send user to view
}
Working from cell phone, please excuse it not being in a full code block.

thanks for your suggestions and comments. I managed to solve it, for some reason could not work it out yesterday. The i believe answer is;
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"User refresh");
// make sure user did not recently verify email address
[user refresh];
if (![[user objectForKey:#"emailVerified"] boolValue])
NSLog(#"User not validated email");
[[[UIAlertView alloc] initWithTitle:#"Access restricted" message:#"To access this area please validate your email address" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
if (![[user objectForKey:#"email"] containsString:#"gmail.com"]) {
[[[UIAlertView alloc] initWithTitle:#"Error" message:#"You must have a validated gmail.com email to access this area." delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
NSLog(#"Email not verified or not a gmail email");
}
else if ([[user objectForKey:#"emailVerified"] boolValue]){
NSLog(#"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:#"Welcome back" message:(#"%#", user.username) delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
}

if (user.objectForKey("emailVerified").boolValue == true){
println("true")
} else {
println("false")
}

Related

Textfield - Make sure the user fill in at least one field

On the Sign Up in my app I want to make sure that the user fill in one field. It should not matter which field for the user though. That's the problem I'm having. The closet I get is to force the user to fill in one specific textfield like the code below. And that's not the best UX i guess :) Anyone who know what to do?
self.saveButton.delegate = self;
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([self.RandomTextField.text isEqualToString:#""]) {
self.saveButton.enabled = NO;
} else {
self.saveButton.enabled = YES;
}
return YES;
}
- (IBAction)SignUPBtn:(UIButton *)sender {
if(txtName.text.length==0 && txtEmail.text.length==0 && txtPass.text.length==0)
{
[[[UIAlertView alloc] initWithTitle:#"" message:#"Please Fill Atleast One Field" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil]show];
}
else
{
//Write Your Code here. this else called only if anyone of three textfield is filled up.
}
}
in the click event of the sign_up button
- (IBAction)SignUPBtn:(UIButton *)sender {
if([textfeld_Email.text length]>0)
{
//sign up
}
else
{
if([textfeld_Pswd.text length]>0)
{
//sing up
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Please enter your email and pass" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
}

Objective C - SLComposeViewController delayed presention

I've been doing a program which takes care of posting a picture or words (or both) to both facebook and twitter. But I want to do them both at the same time, so I wrote my code like this:
//POST TO FACEBOOK
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
slcvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[slcvc addImage:bim];
[slcvc setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
//POST TO TWITTER
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
slcvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slcvc addImage:bim];
[slcvc setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
This is all of course, in an IBAction function that is "file owned" already (slcvc is the SLComposeViewController, bim is an UIImage, and tf.text is the text of the UITextfield tf). And I have posted with this code before, only that it worked separately. If I try to use this to post a picture to Facebook and Twitter at the same time, I get this error:
Attempt to present <SLTwitterComposeViewController: 0xf6265e0> on <ViewController: 0x9476960> which is waiting for a delayed presention of <SLFacebookComposeViewController: 0x9432d70> to complete
(I'm still allowed to post to Facebook but not to Twitter)
I'm sure this happens because the SLComposeViewController registers itself as free to operate again once the first posting (the one for Facebook in this case) is done. So is there a way to have the second posting (the one for Twitter) to wait somehow for the user to send the first posting (to Facebook) and then to present the posting for Twitter? Thanks to anyone in advance for any help or suggestions!!
You will need to use the completion handler of the SLComposeViewController. This is called after user is done composing the post or cancelling it:
[slcvc setCompletionHandler:^(SLComposeViewControllerResult result) {
//POST TO TWITTER
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
slcvc2 = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slcvc2 addImage:bim];
[slcvc2 setInitialText:tf.text];
[self presentViewController:slcvc animated:YES completion:NULL];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter - not logged in!" message:#"You need to login (or sign up) to successfully post..." delegate:nil cancelButtonTitle:#"Too bad!" otherButtonTitles:nil];
[alert show];
}
}
Just try following thing.
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:fbViewController animated:YES completion:nil];
}];

MFMailComposeViewController won't dismiss on iOS 6

In iOS 6 the presented MFMailComposeViewController will not dismiss if user attempts to send second email...
Everything works perfectly the first go around and email is sent. However, if email option is selected again the MFMailComposeViewController will not dismiss on cancel.
Here is how I implemented it:
- (IBAction)buttonEmailClick:(id)sender {
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Can't send" message:#"This device is unable to send emails." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
NSDictionary *contactsInfo = [self contactsInfoFromPlistNamed:kConfigPlistName];
[mailComposeViewController setToRecipients:[NSArray arrayWithObject:[contactsInfo objectForKey:#"email"]]];
//[mailComposeViewController setSubject:kEmailDefaultSubject];
//[mailComposeViewController setMessageBody:text isHTML:NO];
[self presentModalViewController:mailComposeViewController animated:YES];
}
and then this:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
UIAlertView *alert = nil;
if (result == MFMailComposeResultSent) {
alert = [[UIAlertView alloc] initWithTitle:#"Sent" message:#"Your email was sent." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
else if (result == MFMailComposeResultFailed) {
alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"An error occured and your email was not sent." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
It works fine in iOS 5 but not in iOS 6. I have tried replacing with non deprecated methods for iOS 6, but it doesn't work.
Have you tried creating a fresh MFMailComposeViewController each time they go to send an email? I'm not sure if you should be reusing it.
You can try this:
MFMailComposeViewController * composer = [[MFMailComposeViewController alloc] init];
composer.delegate = self;
-(void)mailComposeController:didFinishWithResult:error: should be called if you assign that class to the delegate

App crashing after touching email text MFMailComposeViewController

I'm implementMFMailComposeViewController in my demp app. However, for some reasons, my app crashes after I touch to add texts in the email text field. But sending WITHOUT adding any text works fine.
My Xcode is not showing too much. Here is what I'm getting:
I'm setting an initial text already in the email text field. Maybe the issue is here? request any code and I'll be happy to include it.
UPDATE:
Here 2 methods where the first method openMail fires up when touching the UIButton
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:#"Feedback from Demo App user"];
NSArray *toRecipients = [NSArray arrayWithObjects:#"myEMAIL#hotmail.com", #"myEMAIL2#gmail.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = #"Happy to hear your feedback!";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(#"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(#"Mail not sent.");
break;
}
// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}
Probably you're using ARC, and you're not have strong pointer to your MFMailComposeViewControllerand after display, ARC is releasing it.
use
#property (nonatomic,stron) MFMailComposeViewController *mail;
and when you're initialize MFMailComposeViewController:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
self.mail = mailer;
Do you still have this line in your code:
[mailer release];
If so that is the problem. If not, then PLEASE update our code sample so its exactly what you are using now.

Not receiving email sent using MessageUI framework

I am using the MessageUI framework to send an email but I never receive that email when sent.
I am importing #import <MessageUI/MessageUI.h>
and then I have the following code
- (void)emailFile
{
if(![MFMailComposeViewController canSendMail]) {
UIAlertView *cantSend = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Device not configured to send email" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[cantSend show];
[cantSend release];
} else {
MFMailComposeViewController *mailView = [[[MFMailComposeViewController alloc] init] autorelease];
mailView.mailComposeDelegate = self;
[mailView setToRecipients:[NSArray arrayWithObject:#"matthew.inman#cdl.co.uk"]];
[mailView setSubject:#"Test"];
[mailView setMessageBody:#"This is a text message" isHTML:NO];
[self presentModalViewController:mailView animated:YES];
}
}
and
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if(error) {
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:#"Mail Error" message:[error localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[errorView show];
[errorView release];
} else {
switch (result) {
case MFMailComposeResultSent:
NSLog(#"Sent Mail");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail Saved");
break;
case MFMailComposeResultCancelled:
NSLog(#"Mail Cancelled");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail Failed");
break;
default:
break;
}
}
[controller dismissModalViewControllerAnimated:YES];
}
I get the message "Sent Mail" in the console but I like I said I never receive the email that I am sending.
I have gone through the apple documentation and can't find anything that helps can anyone else help me please. I'm I doing something wrong?
Make sure you are testing on a device, email will not be sent via the simulator.