ChangePasswordViewController.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. NSString* opwd = self.editopwd.text;
  23. NSString* pwd = self.editnpwd.text;
  24. NSString* cpwd = self.editcpwd.text;
  25. if(![opwd isEqualToString: appDelegate.password])
  26. {
  27. [RAUtils message_box:@"Warrning" message:@"Password incorrect." completion:nil];
  28. return;
  29. }
  30. if(![RAUtils checkPassword:pwd])
  31. {
  32. [RAUtils message_box:@"Warrning" message:@"Password must be 8-16 characters and contain numbers and letters." completion:nil];
  33. return;
  34. }
  35. if(![pwd isEqualToString:cpwd])
  36. {
  37. [RAUtils message_box:@"Warrning" message:@"Password does not equal" completion:nil];
  38. return;
  39. }
  40. // __block UIAlertController * waitalert =[RAUtils waiting_alert:self title:@"Change Password" completion:nil];
  41. PopWaitAlert* pop = [RAUtils waiting_pop:@"Change Password" completion:nil];
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. [RADataProvider request_change_password:pwd completionHandler:^(NSMutableDictionary *result) {
  44. // [waitalert dismissViewControllerAnimated:true completion:^{
  45. [pop hide];
  46. NSMutableDictionary* return_json = result;
  47. if([[return_json valueForKey:@"result"] intValue]==2)
  48. {
  49. [RAUtils message_box:@"Change Password" message:@"Successful" completion:^{
  50. appDelegate.password = pwd;
  51. [self dismissViewControllerAnimated:true completion:nil];
  52. }];
  53. }
  54. else
  55. {
  56. [RAUtils message_box:@"Change Password" message:[return_json valueForKey:@"err_msg"] completion:nil];
  57. }
  58. // }];
  59. }];
  60. });
  61. }
  62. - (IBAction)onCloseClick:(id)sender {
  63. [self dismissViewControllerAnimated:true completion:nil];
  64. }
  65. /*
  66. #pragma mark - Navigation
  67. // In a storyboard-based application, you will often want to do a little preparation before navigation
  68. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  69. // Get the new view controller using [segue destinationViewController].
  70. // Pass the selected object to the new view controller.
  71. }
  72. */
  73. @end