// // RetrievePasswordViewController.m // Apex Mobile // // Created by Ray on 14-3-17. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "RetrievePasswordViewController.h" #import "AppDelegate.h" @interface RetrievePasswordViewController () @end @implementation RetrievePasswordViewController - (IBAction)OnCancel:(UIButton *)sender { [self dismissViewControllerAnimated:true completion:^{ ; }]; } - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } - (IBAction)OnOk:(UIButton *)sender { NSString* user = self.editUser.text; NSString* email = self.editEmail.text; if(user.length==0||email.length==0) { UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", @"Error") message:NSLocalizedString(@"alert_msg_uecanotempty", @"User&Email can not be empty!") preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:action]; [self presentViewController:alertVC animated:YES completion:nil]; return; } self.btnOk.enabled = false; self.btnCancel.enabled=false; self.mum.hidden=false; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary *json = [RADataProvider requestRetrievePassword:user email:email]; dispatch_async(dispatch_get_main_queue(), ^{ self.mum.hidden=true; self.btnOk.enabled = true; self.btnCancel.enabled=true; int ret = [[json objectForKey:@"result"] intValue]; if (ret==RESULT_TRUE) { [self dismissViewControllerAnimated:true completion:^{ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_retrieve_success", @"Retrieve successfully!!") message:NSLocalizedString(@"alert_msg_email_sent", @"Email has been sent.") preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:action]; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate.window.rootViewController presentViewController:alertVC animated:YES completion:nil]; }]; } else { NSString *msg = [json objectForKey:@"err_msg"]; if (msg.length == 0) { msg = [NSString stringWithFormat:NSLocalizedString(@"alert_msg_failed_retrieve_password", @"Failed to retrieve password code %d"),ret]; } UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", @"Error") message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:action]; [self presentViewController:alertVC animated:YES completion:nil]; } }); }); } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[self view] endEditing:YES]; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end