RetrievePasswordViewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // RetrievePasswordViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-3-17.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RetrievePasswordViewController.h"
  9. @interface RetrievePasswordViewController ()
  10. @end
  11. @implementation RetrievePasswordViewController
  12. - (IBAction)OnCancel:(UIButton *)sender {
  13. [self dismissViewControllerAnimated:true completion:^{
  14. ;
  15. }];
  16. }
  17. - (BOOL)shouldAutorotate
  18. {
  19. return YES;
  20. }
  21. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  22. {
  23. return UIInterfaceOrientationMaskPortrait;
  24. }
  25. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  26. {
  27. return UIInterfaceOrientationPortrait;
  28. }
  29. - (IBAction)OnOk:(UIButton *)sender {
  30. NSString* user = self.editUser.text;
  31. NSString* email = self.editEmail.text;
  32. if(user.length==0||email.length==0)
  33. {
  34. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", @"Error") message:NSLocalizedString(@"alert_msg_uecanotempty", @"User&Email can not be empty!") preferredStyle:UIAlertControllerStyleAlert];
  35. UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  36. }];
  37. [alertVC addAction:action];
  38. [self presentViewController:alertVC animated:YES completion:nil];
  39. return;
  40. }
  41. self.btnOk.enabled = false;
  42. self.btnCancel.enabled=false;
  43. self.mum.hidden=false;
  44. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  45. int ret = [RADataProvider requestRetrievePassword:user email:email];
  46. dispatch_async(dispatch_get_main_queue(), ^{
  47. self.mum.hidden=true;
  48. self.btnOk.enabled = true;
  49. self.btnCancel.enabled=true;
  50. if (ret==RESULT_TRUE)
  51. {
  52. [self dismissViewControllerAnimated:true completion:^{
  53. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_retrieve_success", @"Retrieve successfully!!") message:NSLocalizedString(@"alert_msg_email_sent", @"Email has been sent.") preferredStyle:UIAlertControllerStyleAlert];
  54. UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  55. }];
  56. [alertVC addAction:action];
  57. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  58. // [appDelegate.window.rootViewController presentViewController:alertVC animated:YES completion:nil];
  59. }];
  60. }
  61. else
  62. {
  63. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", @"Error") message:[NSString stringWithFormat:NSLocalizedString(@"alert_msg_failed_retrieve_password", @"Failed to retrieve password code %d"),ret] preferredStyle:UIAlertControllerStyleAlert];
  64. UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", @"Ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  65. }];
  66. [alertVC addAction:action];
  67. [self presentViewController:alertVC animated:YES completion:nil];
  68. }
  69. });
  70. });
  71. }
  72. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  73. {
  74. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  75. if (self) {
  76. // Custom initialization
  77. }
  78. return self;
  79. }
  80. - (void)viewDidLoad
  81. {
  82. [super viewDidLoad];
  83. // Do any additional setup after loading the view.
  84. }
  85. - (void)didReceiveMemoryWarning
  86. {
  87. [super didReceiveMemoryWarning];
  88. // Dispose of any resources that can be recreated.
  89. }
  90. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  91. [[self view] endEditing:YES];
  92. }
  93. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  94. [textField resignFirstResponder];
  95. return YES;
  96. }
  97. /*
  98. #pragma mark - Navigation
  99. // In a storyboard-based application, you will often want to do a little preparation before navigation
  100. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  101. {
  102. // Get the new view controller using [segue destinationViewController].
  103. // Pass the selected object to the new view controller.
  104. }
  105. */
  106. @end