Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  BTMobileLoginInitialViewController.m
  3. //  BT24
  4. //
  5. //  Created by Pedro Pereira on 27/08/2018.
  6. //  Copyright © 2018 ebankIT. All rights reserved.
  7. //
  8.  
  9. #import <ebankITCore/EBKProfileSelectionViewModel.h>
  10.  
  11. #import "BTMobileLoginInitialViewController.h"
  12. #import "BTMobileLoginViewModel.h"
  13. #import "BTValidator.h"
  14. #import "AppDelegate.h"
  15. #import "GroupCredentials.h"
  16. #import "BTCustomTokenManager.h"
  17. #import "ShortcutEventHandler.h"
  18. #import "ContractProfileSelectionViewController.h"
  19. #import "CustomerDetailsViewModel.h"
  20. #import "BTCustomerDetailsManager.h"
  21. #import "Constants.h"
  22. #import "BTLanguageManager.h"
  23. #import "BTMobileLoginRegisterTokenViewController.h"
  24. #import "BTMobileLoginLevel2CredentialsViewController.h"
  25. #import "SessionInfo.h"
  26. #import "BTBiometricHelper.h"
  27.  
  28. @interface BTMobileLoginInitialViewController () <ContractProfileSelectionViewControllerDelegate>
  29.  
  30. @property (weak, nonatomic) IBOutlet EBKCustomTextField *userIDTextField;
  31. @property (weak, nonatomic) IBOutlet EBKCustomTextField *mobilePassword;
  32. @property (weak, nonatomic) IBOutlet UILabel *forgetPassword;
  33. @property (weak, nonatomic) IBOutlet UIImageView *touchIDImage;
  34.  
  35. @property (weak, nonatomic) IBOutlet EBKCustomTextField *passwordToken;
  36.  
  37. @property (weak, nonatomic) IBOutlet UIButton *actionButton;
  38.  
  39. @property (weak, nonatomic) IBOutlet UIImageView* biomericImage;
  40.  
  41. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewConstrain;
  42. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewHeightConstrain;
  43.  
  44. @property (weak, nonatomic) IBOutlet UIView *biometricSugestionView;
  45.  
  46. @property (weak, nonatomic) IBOutlet UIImageView *biometricTypeSugestionImage;
  47.  
  48. @property (weak, nonatomic) IBOutlet UILabel *biometricSugestionLabel;
  49.  
  50. @property (nonatomic, strong) UserProfile *selectedProfile;
  51.  
  52. @property (nonatomic, strong) EBKProfileSelectionViewModel *profileSelectionViewModel;
  53. @property (strong, nonatomic) CustomerDetailsViewModel* customerVM;
  54. @property (strong, nonatomic) BTMobileLoginViewModel *mobileLoginVM;
  55. @property (strong, nonatomic) EBKLoginViewModel *loginVM;
  56.  
  57. @property (nonatomic) BOOL isLogin;
  58. @property (nonatomic) BOOL hasTwoFactor;
  59.  
  60. @end
  61.  
  62. @implementation BTMobileLoginInitialViewController
  63.  
  64. static const int vascoAccessCodeTypeID = 36;
  65. static const int passwordAccessCodeTypeID = 1;
  66. static const int SMSAccessCodeTypeID = 21;
  67. static const int mobileTokenAccessCodeTypeID = 37;
  68. static const CGFloat KlogoViewFinalHeight = 0.41;
  69.  
  70. - (void)viewDidLoad {
  71.     [super viewDidLoad];
  72.    
  73.     self.mobileLoginVM = [[BTMobileLoginViewModel alloc] initWithDelegate:self];
  74.     self.loginVM = [[EBKLoginViewModel alloc] initWithDelegate:self];
  75.    
  76.     [self.navigationController setNavigationBarHidden:YES animated:NO];
  77.    
  78.     UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lostPasswordTapped:)];
  79.     [self.forgetPassword addGestureRecognizer:tapGestureRecognizer];
  80.     self.forgetPassword.userInteractionEnabled = YES;
  81.    
  82.     if(![[BTCustomTokenManager sharedManager] isCustomTokenActive]){
  83.         [self setupUIForRegisterToken];
  84.         self.isLogin = NO;
  85.     }else{
  86.         [self setupUIForLogin];
  87.         self.isLogin = YES;
  88.     }
  89.    
  90.     self.profileSelectionViewModel = [[EBKProfileSelectionViewModel alloc] initWithDelegate:self];
  91.     self.customerVM = [[CustomerDetailsViewModel alloc] initWithDelegate:self];
  92.    
  93.     UITapGestureRecognizer *viewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissControls:)];
  94.     [viewTap setNumberOfTapsRequired:1];
  95.     [viewTap setCancelsTouchesInView:NO];
  96.     [self.view addGestureRecognizer:viewTap];
  97.    
  98.     [self setupInitialUI];
  99. }
  100.  
  101. - (void)viewWillAppear:(BOOL)animated{
  102.     [super viewWillAppear:animated];
  103.      [self.navigationController setNavigationBarHidden:YES animated:NO];
  104. }
  105.  
  106. -(void)setupInitialUI{
  107.     CGRect screenRect = [[UIScreen mainScreen] bounds];
  108.  
  109.     CGFloat screenHeight = screenRect.size.height;
  110.     self.topViewConstrain.constant = screenHeight;
  111.     self.bottomViewHeightConstrain.constant = screenHeight * (1-KlogoViewFinalHeight);
  112. }
  113.  
  114. -(void)viewDidAppear:(BOOL)animated{
  115.     [super viewDidAppear:animated];
  116.     [self executeAnimation];
  117.     [self.mobileLoginVM getServerDate];
  118. }
  119.  
  120. -(void)executeAnimation{
  121.     CGRect screenRect = [[UIScreen mainScreen] bounds];
  122.     CGFloat screenHeight = screenRect.size.height;
  123.    
  124.     self.topViewConstrain.constant = screenHeight * KlogoViewFinalHeight;
  125.     [UIView animateWithDuration:2
  126.                      animations:^{
  127.                          [self.view layoutIfNeeded];
  128.                      }];
  129. }
  130.  
  131. -(void)lostPasswordTapped:(UIGestureRecognizer*) gesture{
  132.     [[BTCustomTokenManager sharedManager] nukeCustomToken];
  133.     [self setupUIForRegisterToken];
  134.     self.isLogin = NO;
  135. }
  136.  
  137. -(void)setupUIForRegisterToken{
  138.     [self.userIDTextField initCustomTextFieldWithLabel:NSLocalizedString(@"login_user_id", nil)
  139.                                                   type:StringTextFieldType
  140.                                                tooltip:nil
  141.                                               andTheme:@"BTViewTheme"];
  142.    
  143.     [self.userIDTextField setRules: @[[[BTValidator alloc] initWithType:TextFieldValidationTypeRequired
  144.                                                            andErrorText:NSLocalizedString(@"login_user_id_missing", nil)]]];
  145.    
  146.     [self.passwordToken initCustomTextFieldWithLabel:NSLocalizedString(@"login_passwordToken", nil)
  147.                                                 type:PasswordFieldType
  148.                                              tooltip:nil
  149.                                             andTheme:@"BTViewTheme"];
  150.    
  151.     [self.passwordToken setRules: @[[[BTValidator alloc] initWithType:TextFieldValidationTypeRequired
  152.                                                          andErrorText:NSLocalizedString(@"login_passwordToken_empty", nil)]]];
  153.    
  154.     [self.actionButton setLocalizedText:NSLocalizedString(@"login_next", nil)];
  155.    
  156.     self.mobilePassword.hidden = YES;
  157.     self.forgetPassword.hidden = YES;
  158.     self.passwordToken.hidden = NO;
  159.     self.userIDTextField.hidden = NO;
  160.     self.biomericImage.hidden = YES;
  161. }
  162.  
  163. -(void)setupUIForLogin{
  164.     [self.mobilePassword initCustomTextFieldWithLabel:NSLocalizedString(@"login_pin", nil)
  165.                                                  type:PasswordFieldType
  166.                                               tooltip:nil
  167.                                              andTheme:@"BTViewTheme"];
  168.    
  169.     [self.mobilePassword setRules: @[[[BTValidator alloc] initWithType:TextFieldValidationTypeRequired
  170.                                                           andErrorText:NSLocalizedString(@"login_pin_empty", nil)],
  171.                                      [[BTValidator alloc] initWithType:InputRegexValidation
  172.                                                        andRegexPattern:kPINRegex
  173.                                                           andErrorText:NSLocalizedString(@"pin_generic_error_info", nil)]]];
  174.    
  175.      [self.actionButton setLocalizedText:NSLocalizedString(@"login_button_enter", nil)];
  176.    
  177.     self.userIDTextField.hidden = YES;
  178.     self.passwordToken.hidden = YES;
  179.     self.mobilePassword.hidden = NO;
  180.     self.forgetPassword.hidden = NO;
  181.     self.biometricSugestionView.hidden = YES;
  182.    
  183.     //first Verify activeBiometrics
  184.    
  185.     if(![BTBiometricHelper isBiometricActiveOnSystem]){
  186.         [[BTCustomTokenManager sharedManager] nukeBiometricToken];
  187.         self.biometricSugestionView.hidden = NO;
  188.         BTBiometricType biometricType = [BTBiometricHelper verifyBiometricTypeEvenNotEnrrolled];
  189.         switch (biometricType) {
  190.             case BTFaceID:
  191.                 self.biometricTypeSugestionImage.image = [UIImage imageNamed:@"face_id"];
  192.                 self.biometricSugestionLabel.text = NSLocalizedString(@"mobile_login_suggestion_faceID", nil);
  193.                 break;
  194.             case BTTouchID:
  195.                 self.biometricTypeSugestionImage.image = [UIImage imageNamed:@"touch_id"];
  196.                 self.biometricSugestionLabel.text = NSLocalizedString(@"mobile_login_suggestion_touchID", nil);
  197.                 break;
  198.             default:
  199.                 self.biometricSugestionView.hidden = YES;
  200.                 break;
  201.         }
  202.     }
  203.    
  204.     if([[BTCustomTokenManager sharedManager] isBiometricTokenActive]){
  205.        
  206.         //verify biometric type
  207.         BTBiometricType biometricType = [BTBiometricHelper verifyBiometricType];
  208.         switch (biometricType) {
  209.             case BTFaceID:
  210.                 self.biomericImage.image = [UIImage imageNamed:@"face_id"];
  211.                 break;
  212.             case BTTouchID:
  213.                 self.biomericImage.image = [UIImage imageNamed:@"touch_id"];
  214.                 break;
  215.             default:
  216.                 self.biomericImage.hidden = YES;
  217.                 break;
  218.         }
  219.        
  220.         self.biomericImage.hidden = NO;
  221.         UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapedBiometric:)];
  222.         [self.biomericImage addGestureRecognizer:tapGestureRecognizer];
  223.         self.biomericImage.userInteractionEnabled = YES;
  224.         //open the Biometric popUp
  225.         [BTBiometricHelper doBiometricAuthWithResult:^(BOOL result) {
  226.             dispatch_async(dispatch_get_main_queue(), ^{
  227.                 if(result){
  228.                     [self executeBiomtricLogin];
  229.                 }
  230.             });
  231.         }];
  232.     }else{
  233.         self.biomericImage.hidden = YES;
  234.     }
  235. }
  236.  
  237. -(void)tapedBiometric:(UITapGestureRecognizer *)sender {
  238.     [BTBiometricHelper doBiometricAuthWithResult:^(BOOL result) {
  239.         dispatch_async(dispatch_get_main_queue(), ^{
  240.             if(result){
  241.                 [self executeBiomtricLogin];
  242.             }
  243.         });
  244.     }];
  245. }
  246.  
  247. -(void)executeBiomtricLogin{
  248.     EBKLoginViewModelInput* loginInput = [EBKLoginViewModelInput new];
  249.     EBKCredentialItem* credentialItem = [EBKCredentialItem new];
  250.     NSMutableArray* credentialsArray = [NSMutableArray new];
  251.    
  252.     credentialItem.password = [[BTCustomTokenManager sharedManager] getTokenFromBiometric];
  253.     credentialItem.otherLoginType = @(mobileTokenAccessCodeTypeID);
  254.     [credentialsArray addObject:credentialItem];
  255.     loginInput.loginType = OtherLogin;
  256.     loginInput.username = [EBKKeyChainManager getUserAlias];
  257.     loginInput.credentialsList = credentialsArray;
  258.    
  259.     [self.genericLoading startLoading];
  260.     self.loginVM.loginInput = loginInput;
  261. }
  262.  
  263. - (IBAction)nextButtonClick:(id)sender {
  264.     [self.view endEditing:YES];
  265.     if(!self.isLogin){
  266.         //validate userID and password Token
  267.         BOOL valid = [self.userIDTextField validate] && [self.passwordToken validate];
  268.        
  269.         if(valid){
  270.             [self.mobileLoginVM callGetAliasAvailableCredentialsWithAliasValue:self.userIDTextField.textUnformated];
  271.             [self.genericLoading startLoading];
  272.         }
  273.     }else{
  274.         if([self.mobilePassword validate]){
  275.             [self.mobileLoginVM callGetAliasAvailableCredentialsWithAliasValue:[EBKKeyChainManager getUserAlias]];
  276.             [self.genericLoading startLoading];
  277.         }
  278.     }
  279. }
  280.  
  281. -(void)callMobileLogin{
  282.     EBKLoginViewModelInput* loginInput = [EBKLoginViewModelInput new];
  283.     EBKCredentialItem* credentialItem = [EBKCredentialItem new];
  284.     NSMutableArray* credentialsArray = [NSMutableArray new];
  285.    
  286.     credentialItem.password = [[BTCustomTokenManager sharedManager] getCurrentTokenWithPassword:self.mobilePassword.textUnformated];
  287.     credentialItem.otherLoginType = @(mobileTokenAccessCodeTypeID);
  288.     [credentialsArray addObject:credentialItem];
  289.     loginInput.loginType = OtherLogin;
  290.     loginInput.username = [EBKKeyChainManager getUserAlias];
  291.     loginInput.credentialsList = credentialsArray;
  292.    
  293.     [self.genericLoading startLoading];
  294.     self.loginVM.loginInput = loginInput;
  295. }
  296.  
  297. - (void)groupCredentialsDidChange:(BTMobileLoginViewModel *)viewModel {
  298.    
  299.     //Verify both Primary credentials and level 1
  300.     NSMutableArray* availableLevel1LoginCredentials = [NSMutableArray new];
  301.     NSMutableArray* availableLevel2LoginCredentials = [NSMutableArray new];
  302.     NSMutableArray* uniqueLevel1Credentials = [NSMutableArray new];
  303.     NSMutableArray* uniqueLevel2Credentials = [NSMutableArray new];
  304.    
  305.     self.hasTwoFactor = NO;
  306.    
  307.     for(GroupCredentials* groupCredentials in viewModel.groupCredentials){
  308.         NSPredicate * predicate = [NSPredicate predicateWithFormat:@"SELF.isPrimary == 1 && SELF.level == 1"];
  309.        
  310.         NSArray* primaryCredentialsArray = [groupCredentials.listCredentials filteredArrayUsingPredicate:predicate];
  311.        
  312.         if(primaryCredentialsArray.count){
  313.             NSMutableArray* tempArray = [NSMutableArray new];
  314.             for(ListCredentials* credentials in primaryCredentialsArray){
  315.                 NSArray* uniqueAccessCodeTypes = [tempArray valueForKey:@"accessCodeTypeId"];
  316.                 if(!uniqueAccessCodeTypes.count){
  317.                     [tempArray addObject:credentials];
  318.                     [uniqueLevel1Credentials addObject:credentials.accessCodeTypeId];
  319.                 }else if(![uniqueAccessCodeTypes containsObject:credentials.accessCodeTypeId]){
  320.                     [tempArray addObject:credentials];
  321.                     [uniqueLevel1Credentials addObject:credentials.accessCodeTypeId];
  322.                 }
  323.             }
  324.            
  325.             [availableLevel1LoginCredentials addObject:tempArray];
  326.         }
  327.        
  328.         NSPredicate * predicateTwoLevel = [NSPredicate predicateWithFormat:@"SELF.isPrimary == 1 && SELF.level == 2"];
  329.        
  330.         NSArray* twoFActorCredentialsArray = [groupCredentials.listCredentials filteredArrayUsingPredicate:predicateTwoLevel];
  331.        
  332.         if(twoFActorCredentialsArray.count){
  333.             NSMutableArray* tempArray = [NSMutableArray new];
  334.             for(ListCredentials* credentials in twoFActorCredentialsArray){
  335.                 NSArray* uniqueAccessCodeTypes = [tempArray valueForKey:@"accessCodeTypeId"];
  336.                 if(!uniqueAccessCodeTypes.count){
  337.                     [tempArray addObject:credentials];
  338.                     [uniqueLevel2Credentials addObject:credentials.accessCodeTypeId];
  339.                 }else if(![uniqueAccessCodeTypes containsObject:credentials.accessCodeTypeId]){
  340.                     [tempArray addObject:credentials];
  341.                     [uniqueLevel2Credentials addObject:credentials.accessCodeTypeId];
  342.                 }
  343.             }
  344.             [availableLevel2LoginCredentials addObject:tempArray];
  345.         }
  346.     }
  347.    
  348.     /* This Logic makes not a lot o sense, however in BT the user either have password(dev phase only), password+SMS or Vasco we need to detect this and redirect a login to that credentials, so I will look for
  349.      - "AccessCodeTypeId": 1, password
  350.      - "AccessCodeTypeId": 36, vasco
  351.      After this look for second level credentials we will force SMS only
  352.      */
  353.    
  354.     //is password?
  355.    
  356.     BOOL hasPassword = [uniqueLevel1Credentials containsObject:@(passwordAccessCodeTypeID)];
  357.     self.hasTwoFactor = [uniqueLevel2Credentials containsObject:@(SMSAccessCodeTypeID)];
  358.     BOOL hasVasco = [uniqueLevel1Credentials containsObject:@(vascoAccessCodeTypeID)];
  359.    
  360.     [self.genericLoading stopLoading];
  361.  
  362.     if (self.isLogin) {
  363.         [self callMobileLogin];
  364.     }else{
  365.        
  366.         if(hasVasco){
  367.             [self loginWithAccesCodeTypeID:@(vascoAccessCodeTypeID)];
  368.         }else if(hasPassword){
  369.             [self loginWithAccesCodeTypeID:@(passwordAccessCodeTypeID)];
  370.         }else{
  371.             //Error no credentials for this user
  372.             [self.topAlertView showMessageWithText:NSLocalizedString(@"login_error_registration", @"")
  373.                                            andType:BTErrorAlertType];
  374.         }
  375.     }
  376.    
  377.     NSLog(@"Credentials type validation finish ...");
  378. }
  379.  
  380. -(void)loginWithAccesCodeTypeID:(NSNumber*)accesCodeTypeID{
  381.     EBKLoginViewModelInput* loginInput = [EBKLoginViewModelInput new];
  382.     EBKCredentialItem* credentialItem = [EBKCredentialItem new];
  383.     NSMutableArray* credentialsArray = [NSMutableArray new];
  384.    
  385.     credentialItem.password = self.passwordToken.textUnformated;
  386.     credentialItem.otherLoginType = accesCodeTypeID;
  387.     [credentialsArray addObject:credentialItem];
  388.     loginInput.loginType = OtherLogin;
  389.     loginInput.username = self.userIDTextField.textUnformated;
  390.     loginInput.credentialsList = credentialsArray;
  391.    
  392.     [self.genericLoading startLoading];
  393.     self.loginVM.loginInput = loginInput;
  394. }
  395.  
  396. - (void)getAliasAvailableCredentialsErrorDidChange:(BTMobileLoginViewModel *)viewModel {
  397.     [self.genericLoading stopLoading];
  398.     [self handleError:viewModel.getAliasAvailableCredentialsError
  399.              withType:BTTopErrorView
  400.                 andId:0];
  401. }
  402.  
  403. #pragma mark - login methods
  404.  
  405. - (void)loginOutputDidChange:(EBKLoginViewModel *)viewModel {
  406.     if(self.isLogin){
  407.         [self handleLoginSuccessWithOutput:viewModel.loginOutput];
  408.     }else{
  409.         [self.genericLoading stopLoading];
  410.         if(self.hasTwoFactor){
  411.             //navigate to two factor
  412.             UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  413.             BTMobileLoginLevel2CredentialsViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"BTMobileLoginLevel2CredentialsViewController"];
  414.             [self.navigationController pushViewController:controller animated:YES];
  415.         }else{
  416.             //navigate to register token
  417.             UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  418.             BTMobileLoginRegisterTokenViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"BTMobileLoginRegisterTokenViewController"];
  419.             [self.navigationController pushViewController:controller animated:YES];
  420.         }
  421.     }
  422. }
  423.  
  424. - (void)loginErrorDidChange:(EBKLoginViewModel *)viewModel {
  425.    
  426.     [self.genericLoading forceStopLoading];
  427.    
  428.     [self handleError:viewModel.loginError
  429.              withType:BTTopErrorView
  430.                 andId:1];
  431. }
  432.  
  433. - (void)handleLoginSuccessWithOutput:(LoginServiceOutput *)loginOutput {
  434.    
  435.     ApplicationPage *pageToNavigate;
  436.     CustomerFavorite *favourite;
  437.     NSDictionary *otherData;
  438.    
  439.     if ([[ShortcutEventHandler sharedHandler] shortcutAfterLogin]) {
  440.         pageToNavigate = [[ShortcutEventHandler sharedHandler] shortcutAfterLogin].page;
  441.         favourite = [ShortcutEventHandler sharedHandler].shortcutAfterLogin.favourite;
  442.         otherData = [ShortcutEventHandler sharedHandler].shortcutAfterLogin.data;
  443.     } else {
  444.         pageToNavigate = [[ApplicationPagesManager sharedManager] tabController];
  445.     }
  446.    
  447.     if (loginOutput.userProfiles.count == 1) {
  448.        
  449.         [self callSelectProfileServicesWithProfile:loginOutput.userProfiles.firstObject];
  450.         [self.genericLoading stopLoading];
  451.        
  452.     } else if (loginOutput.userProfiles.count > 1 && !self.selectedProfile) {
  453.        
  454.         [self.genericLoading stopLoading];
  455.        
  456.         ApplicationPage *profileSelectionPage = [[ApplicationPagesManager sharedManager] contractProfileSelectionPage];
  457.         UIStoryboard *storyboard = [UIStoryboard storyboardWithName:profileSelectionPage.storyboardName bundle:nil];
  458.         ContractProfileSelectionViewController *vc = [storyboard instantiateViewControllerWithIdentifier:[ContractProfileSelectionViewController classString]];
  459.         vc.delegate = self;
  460.         vc.userProfiles = loginOutput.userProfiles;
  461.         [self.profileSelectionViewModel addDelegateClass:vc];
  462.         [self addCustomPushAnimationToViewController:vc];
  463.         [self.genericLoading forceStopLoading];
  464.         [self.navigationController pushViewController:vc animated:NO];
  465.        
  466.     } else {
  467.         NSLog(@"NO PROFILE (SHOULD BE HANDLED BY MW)");
  468.     }
  469. }
  470.  
  471. - (void)callSelectProfileServicesWithProfile:(UserProfile *)selectedProfile {
  472.    
  473.     [self.genericLoading startLoading];
  474.     EBKProfileSelectionViewModelInput *input = [EBKProfileSelectionViewModelInput new];
  475.     input.profileToSelect = selectedProfile;
  476.     [[SessionInfo sharedManager] setSelectProfileWith:selectedProfile];
  477.    
  478.     self.profileSelectionViewModel.profileSelectionInput = input;
  479. }
  480.  
  481. - (void)profileSelectionOutputDidChange:(EBKProfileSelectionViewModel *)viewModel {
  482.     self.profileSelectionViewModel = viewModel;
  483.     [self initCustomerDetails];
  484.     // [self handleProfileSelectionWithVM:self.profileSelectionViewModel];
  485. }
  486.  
  487. -(void)initCustomerDetails{
  488.     CustomerDetailsServiceInput* input = [[CustomerDetailsServiceInput alloc] init];
  489.     input.alias = [EBKUserInfo getCustomerId];
  490.     self.customerVM.customerDetailsInput = input;
  491. }
  492.  
  493. -(void)customerDetailsOutputDidChange:(CustomerDetailsViewModel *)viewModel{
  494.    
  495.     [[BTCustomerDetailsManager sharedManager]initCustomerDetailsWithCustomerDetails:viewModel.customerDetailsOutput];
  496.     [self handleProfileSelectionWithVM:self.profileSelectionViewModel];
  497.    
  498. }
  499.  
  500. -(void)handleProfileSelectionWithVM:(EBKProfileSelectionViewModel *)viewModel{
  501.     [self.genericLoading stopLoading];
  502.     self.selectedProfile = viewModel.profileSelectionInput.profileToSelect;
  503.      [[SessionInfo sharedManager] setSelectProfileWith:self.selectedProfile];
  504.    
  505.     NSDictionary *colors = [Themes getThemeColors];
  506.    
  507.     [[EBKThemeManager sharedManager] loadWithColors:colors fonts:[Themes getFonts] buttons:[Themes getButtonsThemes] views:[Themes getViewsThemes]];
  508.     [self handleLoginCompletion];
  509. }
  510.  
  511. - (void)profileSelectionErrorDidChange:(EBKProfileSelectionViewModel *)viewModel{
  512.    
  513.     [self.genericLoading stopLoading];
  514.     [self.customAlertView alertViewWithTitle:NSLocalizedString(@"error_generic_title", @"")
  515.                                 andErrorText:viewModel.profileSelectionError.localizedDescription
  516.                                   andButton1:NSLocalizedString(@"error_retry", nil)
  517.                                   andButton2:NSLocalizedString(@"general_cancel", nil)
  518.                                      andType:ErrorCustomAlertView
  519.                                        andId:123];
  520.     [self.customAlertView showAlertView];
  521. }
  522.  
  523. - (void)handleLoginCompletion {
  524.    
  525.     [[ApplicationPagesManager sharedManager] configureManager];
  526.     [[NSNotificationCenter defaultCenter] postNotificationName:kUpdateMenuNotification object:self];
  527.    
  528.     ApplicationPage *pageToNavigate;
  529.     CustomerFavorite *favorite;
  530.     NSDictionary *otherData;
  531.     if ([[ShortcutEventHandler sharedHandler] shortcutAfterLogin]) {
  532.         pageToNavigate = [[ShortcutEventHandler sharedHandler] shortcutAfterLogin].page;
  533.         favorite = [ShortcutEventHandler sharedHandler].shortcutAfterLogin.favourite;
  534.         otherData = [ShortcutEventHandler sharedHandler].shortcutAfterLogin.data;
  535.     } else {
  536.         pageToNavigate = [[ApplicationPagesManager sharedManager] tabController];
  537.     }
  538.    
  539.     UIStoryboard *sb = [UIStoryboard storyboardWithName:pageToNavigate.storyboardName bundle:nil];
  540.     BaseViewController *vc = [sb instantiateViewControllerWithIdentifier:pageToNavigate.pageId];
  541.     AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
  542.    
  543.     [appDelegate.mainNavigationController setViewControllers:@[vc] animated:YES];
  544.    
  545.     // Clear page after logging in
  546.     if ([[ShortcutEventHandler sharedHandler] shortcutAfterLogin]) {
  547.         [ShortcutEventHandler sharedHandler].shortcutAfterLogin = nil;
  548.     }
  549.    
  550.     [[NSNotificationCenter defaultCenter] postNotificationName:@"loginNotification" object:self];
  551. }
  552.  
  553. -(void)customerDetailsErrorDidChange:(CustomerDetailsViewModel *)viewModel{
  554.     [self.genericLoading stopLoading];
  555.     [[NSNotificationCenter defaultCenter] postNotificationName:@"logoutNotification" object:self];
  556. }
  557.  
  558. - (void)addCustomPushAnimationToViewController:(UIViewController *)viewController {
  559.    
  560.     CATransition* transition = [CATransition animation];
  561.     transition.duration = 0.3;
  562.     transition.type = kCATransitionPush;
  563.     transition.subtype = [BTLanguageManager isCurrentLanguageRTL] ? kCATransitionFromLeft : kCATransitionFromRight;
  564.     [viewController.view.layer addAnimation:transition forKey:kCATransition];
  565. }
  566.  
  567. - (void)contractProfileSelectionViewController:(ContractProfileSelectionViewController *)viewController didSelectProfile:(UserProfile *)profile {
  568.    
  569.     [self callSelectProfileServicesWithProfile:profile];
  570. }
  571.  
  572. - (void)dismissControls:(UITapGestureRecognizer *)sender {
  573.     [self.view endEditing:YES];
  574. }
  575.  
  576. - (IBAction)oldLogin:(id)sender {
  577.     AppDelegate* appdelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  578.     [appdelegate setupOldLogin];
  579.     //[self.mobileLoginVM getServerDate];
  580. }
  581.  
  582. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement