NewMobileViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // NewMobileViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/27/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "RequestHandler.h"
  9. #import "JDJSONModel.h"
  10. #import "CustomTextField.h"
  11. #import "ValidateUtil.h"
  12. #import "NewMobileViewController.h"
  13. #import "LoginViewController.h"
  14. #import "CustomLabel.h"
  15. #import "CustomButton.h"
  16. @interface NewMobileViewController () <CustomTextFieldDelegate> {
  17. }
  18. @end
  19. #pragma mark - Class Definition
  20. @implementation NewMobileViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. [self initUI];
  25. [self prepareViewDidLoad];
  26. }
  27. - (void)initUI {
  28. _txtAuthCode.delegate = self;
  29. _txtAuthCode.keyboardType = UIKeyboardTypeDefault;
  30. _txtAuthCode.returnKeyType = UIReturnKeyDone;
  31. _txtAuthCode.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  32. //Localization
  33. _txtAuthCode.placeholder = NSLocalizedString(@"인증 문자 입력", @"인증 문자 입력");
  34. _lblTitle.text = NSLocalizedString(@"새로운 단말에서\n로그인 하셨군요!", @"새로운 단말에서\n로그인 하셨군요!");
  35. [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  36. [_btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  37. }
  38. - (void)prepareViewDidLoad {
  39. _lblEmailInfo.text = [NSString stringWithFormat:@"본인 확인을 위해\n%@\n으로 발송된 인증 문자를\n입력하세요", [JDFacade facade].tmpEmailId];
  40. }
  41. #pragma mark - Main Logic
  42. - (void)requestNewDevice {
  43. //parameters
  44. NSDictionary *parameter = @{@"key": _txtAuthCode.text,
  45. @"email_id": [JDFacade facade].tmpEmailId,
  46. @"service_id": MOBILE_SERVICE_ID,
  47. @"os_type": MOBILE_DEVICE_TYPE,
  48. @"device_sn": [JDFacade facade].deviceUUID,
  49. @"device_token": [JDFacade facade].APNSToken,
  50. @"device_name": [CommonUtil deviceName],
  51. @"replace_device_sn": _replaceDeviceSn ? _replaceDeviceSn : ksEmptyString};
  52. NSString *path = [NSString stringWithFormat:API_POST_NEW_MOBILE_DEVICE];
  53. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  54. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  55. return;
  56. }
  57. LoginModel *loginInfo = (LoginModel *)responseObject;
  58. if (loginInfo) {//API 성공 ,함
  59. [[JDFacade facade] toast:@"새 단말 이용을 시작합니다"];
  60. LoginViewController *lvc = [[JDFacade facade] viewControllerOnPresentingViewController:self viewControllerClass:[LoginViewController class]];
  61. if ([lvc isKindOfClass:[LoginViewController class]]) {
  62. [lvc actionForLoginSucceed:loginInfo];
  63. }
  64. }
  65. } failure:^(id errorObject) {
  66. JDErrorModel *error = (JDErrorModel *)errorObject;
  67. [[JDFacade facade] alert:error.errorMessage];
  68. }];
  69. }
  70. #pragma mark - UI Events
  71. - (IBAction)btnConfirmTouched:(id)sender {
  72. //validate
  73. if (![ValidateUtil validateTextfiled:_txtAuthCode type:ValidateTypeNull title:NSLocalizedString(@"인증문자", @"인증문자")]) {
  74. return;
  75. }
  76. [self requestNewDevice];
  77. }
  78. - (IBAction)btnCancelTouched:(id)sender {
  79. [self dismissViewControllerAnimated:YES completion:nil];
  80. }
  81. #pragma mark - CustomTextField
  82. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  83. [self btnConfirmTouched:nil];
  84. return YES;
  85. }
  86. #pragma mark - MemoryWarning
  87. - (void)didReceiveMemoryWarning
  88. {
  89. [super didReceiveMemoryWarning];
  90. // Dispose of any resources that can be recreated.
  91. }
  92. @end