ChangePasswordViewController.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // ChangePasswordViewController.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 4/8/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ChangePasswordViewController.h"
  9. #import "AppDelegate.h"
  10. #import "RAUtils.h"
  11. #import "RADataProvider.h"
  12. @interface ChangePasswordViewController ()
  13. @end
  14. @implementation ChangePasswordViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. }
  19. - (IBAction)onChangeClick:(id)sender {
  20. UIApplication * app = [UIApplication sharedApplication];
  21. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  22. // if(appDelegate.user.length==0)
  23. // {
  24. // [RAUtils message_alert:@"You must sign in first." title:@"Delete Account" controller:self];
  25. // return;
  26. // }
  27. NSString* opwd = self.editopwd.text;
  28. NSString* pwd = self.editnpwd.text;
  29. NSString* cpwd = self.editcpwd.text;
  30. if(![opwd isEqualToString: appDelegate.password])
  31. {
  32. [RAUtils message_alert:@"Password incorrect." title:@"Warrning" controller:self];
  33. return;
  34. }
  35. if(![RAUtils checkPassword:pwd])
  36. {
  37. [RAUtils message_alert:@"Password must be 8-16 characters and contain numbers and letters." title:@"Warrning" controller:self];
  38. return;
  39. }
  40. if(![pwd isEqualToString:cpwd])
  41. {
  42. [RAUtils message_alert:@"Password does not equal" title:@"Warrning" controller:self];
  43. return;
  44. }
  45. __block UIAlertController * waitalert =[RAUtils waiting_alert:self title:@"Change Password" completion:nil];
  46. dispatch_async(dispatch_get_main_queue(), ^{
  47. [RADataProvider request_change_password:pwd completionHandler:^(NSMutableDictionary *result) {
  48. [waitalert dismissViewControllerAnimated:true completion:^{
  49. NSMutableDictionary* return_json = result;
  50. if([[return_json valueForKey:@"result"] intValue]==2)
  51. {
  52. [RAUtils message_alert:@"Change password successful" title:@"Change Password" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
  53. appDelegate.password = pwd;
  54. [self dismissViewControllerAnimated:true completion:nil];
  55. } completion:nil];
  56. }
  57. else
  58. {
  59. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Change Password" controller:self] ;
  60. }
  61. }];
  62. }];
  63. });
  64. }
  65. - (IBAction)onCloseClick:(id)sender {
  66. [self dismissViewControllerAnimated:true completion:nil];
  67. }
  68. /*
  69. #pragma mark - Navigation
  70. // In a storyboard-based application, you will often want to do a little preparation before navigation
  71. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  72. // Get the new view controller using [segue destinationViewController].
  73. // Pass the selected object to the new view controller.
  74. }
  75. */
  76. @end