SignUpViewController.m 2.6 KB

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