NewMobileViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. [_lblEmailInfo setColor:kUITextColor02 text:[JDFacade facade].tmpEmailId];
  41. }
  42. #pragma mark - Main Logic
  43. - (void)requestNewDevice {
  44. //parameters
  45. NSDictionary *parameter = @{@"key": _txtAuthCode.text,
  46. @"email_id": [JDFacade facade].tmpEmailId,
  47. @"service_id": MOBILE_SERVICE_ID,
  48. @"os_type": MOBILE_DEVICE_TYPE,
  49. @"device_sn": [JDFacade facade].deviceUUID,
  50. @"device_token": [JDFacade facade].APNSToken,
  51. @"device_name": [CommonUtil deviceName],
  52. @"replace_device_sn": _replaceDeviceSn ? _replaceDeviceSn : ksEmptyString};
  53. NSString *path = [NSString stringWithFormat:API_POST_NEW_MOBILE_DEVICE];
  54. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  55. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  56. return;
  57. }
  58. LoginModel *loginInfo = (LoginModel *)responseObject;
  59. if (loginInfo) {//API 성공 ,함
  60. [[JDFacade facade] toast:@"새 단말 이용을 시작합니다"];
  61. LoginViewController *lvc = [[JDFacade facade] viewControllerOnPresentingViewController:self viewControllerClass:[LoginViewController class]];
  62. if ([lvc isKindOfClass:[LoginViewController class]]) {
  63. [lvc actionForLoginSucceed:loginInfo];
  64. }
  65. }
  66. } failure:^(id errorObject) {
  67. JDErrorModel *error = (JDErrorModel *)errorObject;
  68. [[JDFacade facade] alert:error.errorMessage];
  69. }];
  70. }
  71. #pragma mark - UI Events
  72. - (IBAction)btnConfirmTouched:(id)sender {
  73. //validate
  74. if (![ValidateUtil validateTextfiled:_txtAuthCode type:ValidateTypeNull title:NSLocalizedString(@"인증문자", @"인증문자")]) {
  75. return;
  76. }
  77. [self requestNewDevice];
  78. }
  79. - (IBAction)btnCancelTouched:(id)sender {
  80. [self dismissViewControllerAnimated:YES completion:nil];
  81. }
  82. #pragma mark - CustomTextField
  83. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  84. [self btnConfirmTouched:nil];
  85. return YES;
  86. }
  87. #pragma mark - MemoryWarning
  88. - (void)didReceiveMemoryWarning
  89. {
  90. [super didReceiveMemoryWarning];
  91. // Dispose of any resources that can be recreated.
  92. }
  93. @end