Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // *------------------------------------------*
  2. // [JAKISCOMPONENT] WOLA LOGINSERVICE
  3. // *------------------------------------------*
  4.  
  5. ({
  6.     /**
  7.     * HELPER
  8.     */
  9.     handleLogin: function(component, hasVerificationCode) {
  10.         this.loginService.invokeLogin(
  11.             component.get('v.loginParams'),
  12.             decodeURIComponent(component.get('v.startUrl')),
  13.             (hasVerificationCode ? '' : component.get('v.verificationCode'))
  14.         ).then(res => {
  15.             if(component.get('v.showError')) {
  16.                 this.toggleError(component, '', false);
  17.             }
  18.  
  19.             if(res.isTFALoginRequired) {
  20.                 component.set('v.maskedUsername', this.maskUsername(component.get('v.loginParams.username')));
  21.                 this.handleTwoFactorAuthLogin(component, res);
  22.             } else if(res.isInvalidAuthCode) {
  23.                 this.toggleError(component, 'Invalid verification code.', true);
  24.             } else {
  25.                 this.handleLoginSuccess(component, res);
  26.             }
  27.         }).catch(err => {
  28.             this.toggleError(component, err[0].message);
  29.         });
  30.     }
  31. })
  32.  
  33.  
  34. // *------------------------------------------*
  35. // [LOGINSERVICE] WOLA APEXPROXY
  36. // *------------------------------------------*
  37.  
  38. /*
  39. * TEMPLATE
  40. */
  41.     <aura:method name="invokeLogin">
  42.         <aura:attribute name="loginParams" type="Map" />
  43.         <aura:attribute name="startUrl" type="String" />
  44.         <aura:attribute name="verificationCode" type="String" />
  45.     </aura:method>
  46.  
  47. ({
  48.     /*
  49.     * CONTROLLER
  50.     */
  51.     invokeLogin: function(component, event, helper) {
  52.         const args = event.getParam("arguments");
  53.         return helper.invokeLogin(component, args);
  54.     },
  55.  
  56.     /*
  57.     * HELPER
  58.     */
  59.  
  60.     /**
  61.      * Invokes a server-side action responsible for handling login functionality.
  62.      * @param component {Object} component instance.
  63.      * @param args {Object} a map of parameters passed to the server-side action.
  64.      * @returns {Promise} A promise that will resolve/reject after login is complete.
  65.      */
  66.     invokeLogin: function(component, args) {
  67.         const apexProxy = component.find('apexProxy');
  68.         return apexProxy.invoke(component, 'login', {
  69.             username: args.loginParams.username,
  70.             password: args.loginParams.password,
  71.             startUrl: args.startUrl,
  72.             verificationCode: args.verificationCode
  73.         });
  74.     }
  75. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement