RetrievePasswordViewController.m 5.1 KB

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