ChangePasswordViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // ChangePasswordViewController.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 "ChangePasswordViewController.h"
  9. @interface ChangePasswordViewController ()
  10. @end
  11. @implementation ChangePasswordViewController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  13. {
  14. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  15. if (self) {
  16. // Custom initialization
  17. }
  18. return self;
  19. }
  20. - (BOOL)shouldAutorotate
  21. {
  22. return YES;
  23. }
  24. - (NSUInteger)supportedInterfaceOrientations
  25. {
  26. return UIInterfaceOrientationMaskPortrait;
  27. }
  28. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  29. {
  30. return UIInterfaceOrientationPortrait;
  31. }
  32. - (void)viewDidLoad
  33. {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. }
  37. - (void)didReceiveMemoryWarning
  38. {
  39. [super didReceiveMemoryWarning];
  40. // Dispose of any resources that can be recreated.
  41. }
  42. - (IBAction)onChange:(UIButton *)sender {
  43. NSString* oldpass = self.editOld.text;
  44. NSString* newpass = self.editNew.text;
  45. NSString* confirmpass = self.editConfirm.text;
  46. ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  47. NSString* user = appDelegate.user;
  48. if(oldpass.length==0||oldpass.length==0||confirmpass.length==0)
  49. {
  50. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert_title_error", nil) message:NSLocalizedString(@"alert_msg_fieldscanotempty", nil)delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  51. // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  52. [alert show];
  53. return;
  54. }
  55. if(! [newpass isEqualToString:confirmpass])
  56. {
  57. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert_title_error", nil) message:NSLocalizedString(@"alert_msg_password_notequal", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  58. // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  59. [alert show];
  60. return;
  61. }
  62. self.btnChange.enabled = false;
  63. self.mum.hidden=false;
  64. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  65. int ret=[ApexMobileNetwork ChangePassword:newpass user:user oldpass:oldpass];
  66. dispatch_async(dispatch_get_main_queue(), ^{
  67. self.mum.hidden=true;
  68. self.btnChange.enabled = true;
  69. if (ret==RESULT_TRUE)
  70. {
  71. ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  72. appDelegate.password = newpass;
  73. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert_title_success", nil) message:NSLocalizedString(@"alert_msg_change_success", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  74. [alert show];
  75. [self.navigationController popViewControllerAnimated:true ];
  76. }
  77. else
  78. {
  79. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert_title_error", nil) message:[NSString stringWithFormat:NSLocalizedString(@"alert_msg_failed_change_password", nil),ret] delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  80. [alert show];
  81. }
  82. });
  83. });
  84. }
  85. - (IBAction)onCancel:(UIButton *)sender {
  86. }
  87. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  88. [[self view] endEditing:YES];
  89. }
  90. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  91. [textField resignFirstResponder];
  92. return YES;
  93. }
  94. /*
  95. #pragma mark - Navigation
  96. // In a storyboard-based application, you will often want to do a little preparation before navigation
  97. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  98. {
  99. // Get the new view controller using [segue destinationViewController].
  100. // Pass the selected object to the new view controller.
  101. }
  102. */
  103. @end