SecureChangeViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // SecureChangeViewController.h
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/27/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "ValidateUtil.h"
  12. #import "CustomTextField.h"
  13. #import "CustomLabel.h"
  14. #import "QRCodeViewController.h"
  15. #import "SecureChangeViewController.h"
  16. #import "CustomButton.h"
  17. @interface SecureChangeViewController () <CustomTextFieldDelegate> {
  18. }
  19. @end
  20. #pragma mark - Class Definition
  21. @implementation SecureChangeViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self initUI];
  26. [self prepareViewDidLoad];
  27. }
  28. - (void)initUI {
  29. self.title = NSLocalizedString(@"장치등록 보안키 확인",nil);
  30. _txtSecureCode.secureTextEntry = YES;
  31. _txtSecureCode.delegate = self;
  32. _txtSecureCode.returnKeyType = UIReturnKeyDone;
  33. _txtSecureCode.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  34. _txtSecureCode.placeholder = NSLocalizedString(@"보안키 입력", @"보안키 입력");
  35. _lblDesc.text = NSLocalizedString(@"이 장치를 사용 중인 다른 홈이 있다면\n더 이상 사용할 수 없게 됩니다", @"이 장치를 사용 중인 다른 홈이 있다면\n더 이상 사용할 수 없게 됩니다");
  36. [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  37. [_btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  38. }
  39. - (void)prepareViewDidLoad {
  40. NSString *actitle = _qrcodeType == QRCodeTypeCommaxWallpad ? NSLocalizedString(@"코맥스 월패드", @"코맥스 월패드"): NSLocalizedString(@"다원 스마트 플러그", @"다원 스마트 플러그");
  41. _lblTitle.text = [NSString stringWithFormat:NSLocalizedString(@"[%@]에 [%@] 장치를 등록하려면 장치등록 보안키를 입력하세요", @"[%@]에 [%@] 장치를 등록하려면 장치등록 보안키를 입력하세요"), [JDFacade facade].loginHomeGroup.homegrpName, actitle];
  42. }
  43. #pragma mark - Main Logic
  44. - (void)requestSecureKeyConfirm {
  45. //parameters
  46. NSDictionary *parameter = @{@"device_id": _deviceId,
  47. @"user_device_password": _txtSecureCode.text};
  48. NSString *path = [NSString stringWithFormat:API_POST_PARTNER_PASSWD];
  49. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  50. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddCompleteViewController" storyboardName:@"Things"];
  51. [[JDFacade facade] presentViewControllerByPush:vc pvc:self];
  52. } failure:^(id errorObject) {
  53. JDErrorModel *error = (JDErrorModel *)errorObject;
  54. [[JDFacade facade] alert:error.errorMessage];
  55. }];
  56. }
  57. #pragma mark - UI Events
  58. - (void)btnBackTouched:(id)sender {
  59. [self btnCancelTouched:nil];
  60. }
  61. - (IBAction)btnConfirmTouched:(id)sender {
  62. [self.view endEditing:YES];
  63. //1.validate
  64. if (![ValidateUtil validateTextfiled:_txtSecureCode type:ValidateTypeNull title:NSLocalizedString(@"보안키", @"보안키")]) {
  65. return;
  66. }
  67. //보안키 확인
  68. [self requestSecureKeyConfirm];
  69. }
  70. - (IBAction)btnCancelTouched:(id)sender {
  71. [[JDFacade facade] dismissViewControllerByPush:self];
  72. }
  73. #pragma mark - CustomTextField
  74. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  75. [self btnConfirmTouched:nil];
  76. return YES;
  77. }
  78. #pragma mark - MemoryWarning
  79. - (void)didReceiveMemoryWarning
  80. {
  81. [super didReceiveMemoryWarning];
  82. // Dispose of any resources that can be recreated.
  83. }
  84. @end