File

src/app/sign-in/sign-in.page.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(systemSettingsService: SystemSettingsService, preferences: SharedPreferences, appHeaderService: AppHeaderService, commonUtilService: CommonUtilService, router: Router, formAndFrameworkUtilService: FormAndFrameworkUtilService, sbProgressLoader: SbProgressLoader, loginNavigationHandlerService: LoginNavigationHandlerService, googlePlusLogin: GooglePlus, location: Location, signInWithApple: SignInWithApple, platform: Platform, appGlobalService: AppGlobalService)
Parameters :
Name Type Optional
systemSettingsService SystemSettingsService No
preferences SharedPreferences No
appHeaderService AppHeaderService No
commonUtilService CommonUtilService No
router Router No
formAndFrameworkUtilService FormAndFrameworkUtilService No
sbProgressLoader SbProgressLoader No
loginNavigationHandlerService LoginNavigationHandlerService No
googlePlusLogin GooglePlus No
location Location No
signInWithApple SignInWithApple No
platform Platform No
appGlobalService AppGlobalService No

Methods

Async appleSignIn
appleSignIn()
Returns : any
ionViewWillEnter
ionViewWillEnter()
Returns : void
ionViewWillLeave
ionViewWillLeave()
Returns : void
Async login
login()
Returns : any
Async loginWithKeyCloak
loginWithKeyCloak()
Returns : any
Async loginWithStateSystem
loginWithStateSystem()
Returns : any
Private navigateBack
navigateBack(skipNavigation)
Parameters :
Name Optional
skipNavigation No
Returns : void
Async ngOnInit
ngOnInit()
Returns : any
onFormLoginChange
onFormLoginChange(event)
Parameters :
Name Optional
event No
Returns : void
Async onLabelClickEvent
onLabelClickEvent()
Returns : any
Async register
register()
Returns : any
Async signInWithGoogle
signInWithGoogle()
Returns : any

Properties

appName
Type : string
Default value : ''
loginButtonValidation
Type : boolean
Default value : false
loginConfig
Type : FieldConfig<any>[]
Default value : []
loginDet
Type : any
Public platform
Type : Platform
skipNavigation
Type : any
import {Component, Inject, OnInit} from '@angular/core';
import {
    AppGlobalService,
    AppHeaderService,
    CommonUtilService,
    FormAndFrameworkUtilService,
    InteractSubtype,
    InteractType,
} from '@app/services';
import {
    WebviewStateSessionProviderConfig,
    WebviewRegisterSessionProviderConfig,
    WebviewStateSessionProvider,
    WebviewSessionProviderConfig,
    WebviewLoginSessionProvider,
    NativeGoogleSessionProvider,
    SystemSettingsService,
    SignInError,
    SharedPreferences,
    NativeAppleSessionProvider,
    NativeKeycloakSessionProvider
} from 'sunbird-sdk';
import {Router} from '@angular/router';
import {SbProgressLoader} from '@app/services/sb-progress-loader.service';
import {LoginNavigationHandlerService} from '@app/services/login-navigation-handler.service';
import {GooglePlus} from '@ionic-native/google-plus/ngx';
import {PreferenceKey, SystemSettingsIds} from '@app/app/app.constant';
import {Location} from '@angular/common';
import {
    SignInWithApple,
    AppleSignInResponse,
    AppleSignInErrorResponse,
    ASAuthorizationAppleIDRequest
} from '@ionic-native/sign-in-with-apple/ngx';
import { Platform } from '@ionic/angular';
import { FieldConfig } from 'common-form-elements';

@Component({
    selector: 'app-sign-in',
    templateUrl: './sign-in.page.html',
    styleUrls: ['./sign-in.page.scss'],
    providers: [LoginNavigationHandlerService]
})
export class SignInPage implements OnInit {
    appName = '';
    skipNavigation: any;
    loginConfig: FieldConfig<any>[] = [];
    loginButtonValidation: boolean = false;
    loginDet: any;

    constructor(
        @Inject('SYSTEM_SETTINGS_SERVICE') private systemSettingsService: SystemSettingsService,
        @Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
        private appHeaderService: AppHeaderService,
        private commonUtilService: CommonUtilService,
        private router: Router,
        private formAndFrameworkUtilService: FormAndFrameworkUtilService,
        private sbProgressLoader: SbProgressLoader,
        private loginNavigationHandlerService: LoginNavigationHandlerService,
        private googlePlusLogin: GooglePlus,
        private location: Location,
        private signInWithApple: SignInWithApple,
        public platform: Platform,
        private appGlobalService: AppGlobalService,
    ) {
        const extrasData = this.router.getCurrentNavigation().extras.state;
        this.skipNavigation = extrasData;
        this.appHeaderService.hideHeader();
        if (this.platform.is('ios')) {
            // this one is to make sure keyboard has done button on top to close the keyboard
            window.cordova['plugins'].Keyboard.hideKeyboardAccessoryBar(false);
        }
    }
            
    ionViewWillEnter() {
        this.appHeaderService.hideStatusBar();
    }

    ionViewWillLeave() {
        this.appHeaderService.showStatusBar();
        this.appHeaderService.showHeaderWithHomeButton(['download', 'notification'])
    }

    async ngOnInit() {
        this.appName = await this.commonUtilService.getAppName();
        this.login();
    }

    async login() {
        this.loginConfig = [
            {
                code: "Email",
                type: "input",
                templateOptions: {
                    type: "text",
                    label: "Enter Email address / mobile number",
                    placeHolder: "user@example.com / 9XXXXXXXX9"
                }
            },
            {
                code: "Password",
                type: "input",
                templateOptions: {
                    type: "password",
                    label: "Password",
                    placeHolder: "Enter your password",
                    showIcon: {
                        show: true,
                        image: {
                            active: 'assets/imgs/eye.svg',
                            inactive: 'assets/imgs/eye-off.svg'
                        },
                        direction: 'right'
                    },
                    labelHtml: {
                        contents: `<span aria-label="Forgot Password link,  Double tap to activate"  class="fgt-pwsd-lbl">Forgot Password ?</span>`,
                    }
                }
            }
        ]
    }

    onFormLoginChange(event) {
        this.loginDet = {username: event.Email, password: event.Password };
        this.loginButtonValidation = Object.values(event).every(x => (x !== null && x !== ''));
    }
                
    async onLabelClickEvent() {
        const webviewSessionProviderConfigLoader = await this.commonUtilService.getLoader();
        let webviewForgotPasswordSessionProviderConfig: WebviewSessionProviderConfig;
        let webviewMigrateSessionProviderConfig: WebviewSessionProviderConfig;
        await webviewSessionProviderConfigLoader.present();
        try {
            webviewForgotPasswordSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('login');
            webviewForgotPasswordSessionProviderConfig.context = "password";
            webviewMigrateSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('migrate');
            await webviewSessionProviderConfigLoader.dismiss();
        } catch (e) {
            await this.sbProgressLoader.hide({id: 'login'});
            await webviewSessionProviderConfigLoader.dismiss();
            this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
            return;
        }
        const webViewForgotPasswordSession = new WebviewLoginSessionProvider(
            webviewForgotPasswordSessionProviderConfig,
            webviewMigrateSessionProviderConfig
        );
        await this.loginNavigationHandlerService.setSession(webViewForgotPasswordSession, this.skipNavigation, InteractSubtype.KEYCLOAK)
        .then(() => {
            this.navigateBack(this.skipNavigation);
        });
    }

    async loginWithKeyCloak() {
        this.appGlobalService.resetSavedQuizContent();
        if (!this.commonUtilService.networkInfo.isNetworkAvailable) {
        } else {
            this.loginNavigationHandlerService.generateLoginInteractTelemetry(InteractType.LOGIN_INITIATE, InteractSubtype.KEYCLOAK, '');
            const loginSessionProviderConfigloader = await this.commonUtilService.getLoader();
            
            let keycloakLoginSessionProviderConfig: WebviewSessionProviderConfig;
            let keycloakMigrateSessionProviderConfig: WebviewSessionProviderConfig;
            
            await loginSessionProviderConfigloader.present();
            try {
                keycloakLoginSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('login');
                keycloakMigrateSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('migrate');
                await loginSessionProviderConfigloader.dismiss();
            } catch (e) {
                this.sbProgressLoader.hide({id: 'login'});
                await loginSessionProviderConfigloader.dismiss();
                this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
                return;
            }
            const nativeSessionKeycloakProvider = new NativeKeycloakSessionProvider(keycloakLoginSessionProviderConfig, this.loginDet)
            await this.loginNavigationHandlerService.setSession(nativeSessionKeycloakProvider, this.skipNavigation, InteractSubtype.KEYCLOAK)
            .then(() => {
                this.navigateBack(this.skipNavigation);
            })
        }
    }

    async loginWithStateSystem() {
        this.loginNavigationHandlerService.generateLoginInteractTelemetry
        (InteractType.LOGIN_INITIATE, InteractSubtype.STATE, '');
        const webviewSessionProviderConfigLoader = await this.commonUtilService.getLoader();
        let webviewStateSessionProviderConfig: WebviewStateSessionProviderConfig;
        let webviewMigrateSessionProviderConfig: WebviewSessionProviderConfig;
        await webviewSessionProviderConfigLoader.present();
        try {
            webviewStateSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('state');
            webviewMigrateSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('migrate');
            await webviewSessionProviderConfigLoader.dismiss();
        } catch (e) {
            await this.sbProgressLoader.hide({id: 'login'});
            await webviewSessionProviderConfigLoader.dismiss();
            this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
            return;
        }
        const webViewStateSession = new WebviewStateSessionProvider(
            webviewStateSessionProviderConfig,
            webviewMigrateSessionProviderConfig
        );
        await this.loginNavigationHandlerService.setSession(webViewStateSession, this.skipNavigation, InteractSubtype.STATE).then(() => {
            this.navigateBack(this.skipNavigation);
        });
    }

    async signInWithGoogle() {
        this.loginNavigationHandlerService.generateLoginInteractTelemetry
        (InteractType.LOGIN_INITIATE, InteractSubtype.GOOGLE, '');
        const clientId = await this.systemSettingsService.getSystemSettings({id: SystemSettingsIds.GOOGLE_CLIENT_ID}).toPromise();
        this.googlePlusLogin.login({
            webClientId: clientId.value
        }).then(async (result) => {
            await this.sbProgressLoader.show({id: 'login'});
            const nativeSessionGoogleProvider = new NativeGoogleSessionProvider(() => result);
            await this.preferences.putBoolean(PreferenceKey.IS_GOOGLE_LOGIN, true).toPromise();
            await this.loginNavigationHandlerService.setSession(nativeSessionGoogleProvider, this.skipNavigation, InteractSubtype.GOOGLE)
            .then(() => {
                this.navigateBack(this.skipNavigation);
            });
        }).catch(async (err) => {
            await this.sbProgressLoader.hide({id: 'login'});
            if (err instanceof SignInError) {
                this.commonUtilService.showToast(err.message);
            } else {
                this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
            }
        });
    }

    async register() {
        const webviewSessionProviderConfigLoader = await this.commonUtilService.getLoader();
        let webviewRegisterSessionProviderConfig: WebviewRegisterSessionProviderConfig;
        let webviewMigrateSessionProviderConfig: WebviewSessionProviderConfig;
        await webviewSessionProviderConfigLoader.present();
        try {
            webviewRegisterSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('register');
            webviewMigrateSessionProviderConfig = await this.formAndFrameworkUtilService.getWebviewSessionProviderConfig('migrate');
            await webviewSessionProviderConfigLoader.dismiss();
        } catch (e) {
            await this.sbProgressLoader.hide({id: 'login'});
            await webviewSessionProviderConfigLoader.dismiss();
            this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
            return;
        }
        const webViewRegisterSession = new WebviewLoginSessionProvider(
            webviewRegisterSessionProviderConfig,
            webviewMigrateSessionProviderConfig
        );
        await this.loginNavigationHandlerService.setSession(webViewRegisterSession, this.skipNavigation, InteractSubtype.KEYCLOAK)
        .then(() => {
            this.navigateBack(this.skipNavigation);
        });
    }

    private navigateBack(skipNavigation) {
        if ((skipNavigation && skipNavigation.navigateToCourse) ||
            (skipNavigation && (skipNavigation.source === 'user' ||
                skipNavigation.source === 'resources'))) {
            this.location.back();
        }
    }

    async appleSignIn() {
        this.loginNavigationHandlerService.generateLoginInteractTelemetry
        (InteractType.TOUCH, InteractSubtype.LOGIN_INITIATE, '');
        this.signInWithApple.signin({
            requestedScopes: [
              ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
            ]
          })
          .then(async (res: AppleSignInResponse) => {
            // https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
            await this.sbProgressLoader.show({id: 'login'});
            const nativeSessionAppleProvider = new NativeAppleSessionProvider(() => res as any);
            await this.preferences.putBoolean(PreferenceKey.IS_APPLE_LOGIN, true).toPromise();
            await this.loginNavigationHandlerService.setSession(nativeSessionAppleProvider, this.skipNavigation,
                 InteractSubtype.APPLE).then(() => {
                this.navigateBack(this.skipNavigation);
            }).catch(err => {
                this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
            });
          })
          .catch((error: AppleSignInErrorResponse) => {
            this.commonUtilService.showToast('ERROR_WHILE_LOGIN');
          });
    }
}
<ion-content class="signinpage">
    <div class="img-con">
        <img class="img-container" src="assets/imgs/ic_launcher.png" alt="app logo">
    </div>
    <div class="title-head">
        <h3>Welcome To {{appName}}</h3>
        <p>LOGIN</p>
    </div>
    <div class="login-div">
        <sb-form *ngIf="loginConfig && loginConfig.length"
        [config]='loginConfig'
        [platform]="'mobile'"
        (valueChanges)="onFormLoginChange($event)"
        (labelClickEvent)="onLabelClickEvent($event)">
        </sb-form>
        <button [ngClass]="loginButtonValidation ? 'validLoginButton':'log-in-button'" (click)="loginWithKeyCloak()" [disabled]="!loginButtonValidation">
            <p class="text-overlay">{{'OVERLAY_SIGN_IN' | translate }}</p>
        </button>

        <div class="account-info"><p>Don't have an account ? <span aria-label="Register here link" class="hyper-link" (click)="register()">Register here</span>
            <span> to access relevant learning material and enroll for courses</span></p>
        </div>
        <div class="option-or">
            <hr>
            <span>{{'OR' | translate}}</span>
            <hr>
        </div>

        <button class="signin"  (click)="signInWithGoogle()">
            <img class="icon-logo" src="assets/imgs/ic_google_icon.svg" alt="google-logo">
            <p class="text-overlay">{{'GOOGLE_LOGIN' | translate}}</p>
        </button>
        <button class="signin statesignin" (click)="loginWithStateSystem()">
            <p class="text-overlay"> {{'STATE_LOGIN' | translate}}</p>
        </button>

        <button *ngIf="platform.is('ios')" class="signin" (click)="appleSignIn()">
            <img class="icon-logo" src="assets/imgs/apple_black.png" alt="google-logo">
            <p class="text-overlay">{{'APPLE_LOGIN' | translate}}</p>
        </button>

    </div>
</ion-content>

./sign-in.page.scss

@import "src/assets/styles/variables";
@import "src/assets/styles/base/_variables.scss";
@import "src/assets/styles/_custom-mixins";
@import "src/assets/styles/fonts";
@import "src/assets/styles/_variables.scss";

.login-div {
  margin-top: 2vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.signin {
  margin: 1rem;
  position: relative;
  color: var(--app-gray) !important;
  height: 3rem !important;
  width: 86vw !important;
  border: 1px solid map-get($colors , light_shade_gray );
  box-sizing: border-box;
  border-radius: 16px !important;
  background-color: map-get($colors ,white ) !important;
  box-shadow: 5px 5px 2px 0 rgb(0 0 0 / 10%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.statesignin {
  margin-top: -8px !important;
}

.log-in-button {
  height: 3rem;
  width: 86vw;
  border-radius: 16px;
  background-color: map-get($colors , medium_light_shade_gray );
  box-shadow: 5px 5px 2px 0 rgba(0,0,0,0.1);
  margin-top: 9px;
  margin-bottom: 12px;
}

.validLoginButton {
  height: 3rem;
  width: 86vw;
  border-radius: 16px;
  background-color: map-get($colors , light_green );
  box-shadow: 5px 5px 2px 0 rgba(0,0,0,0.1);
  margin-top: 9px;
  margin-bottom: 12px;
}

.signinpage {
  --background: map-get($colors ,white );
  background: map-get($colors ,white ) !important;
}

.img-con {
  margin-top: 10px;
  width: 100%;
  display: flex;
  justify-content: center;
}

.img-container {
  max-width: 20%;
}

.header {
  margin-left: 2rem;
}

.settings-item-style {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

.title-logo {
  position: absolute;
  left: 8.5rem;
}

.icon-logo {
  width: 1.5rem;
  height: 1.5rem;
}

.hyper-link {
  color: #024F9D;
  font-weight: bold;
}
.account-info {
  width: 85%;
  p {
   font-size: 11px;
   color: map-get($colors , medium_light_shade_gray );
   font-family: "Noto Sans";
   font-size: 12px;
   letter-spacing: 0;
   line-height: 17px;
   text-align: center;
  }
}

.title-head {
  width: 100%;
  text-align: center;
  padding-top: 10px;
  margin-top: 10px;
  h3 {
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 0;
    line-height: 33px;
     }
  p {
    font-size: 16px;
    letter-spacing: 0;
    line-height: 22px;
  }  
  }


.option-or {
  font-size: 1rem;
  color: var(--app-gray);
  display: flex;
  align-items: center;
  width: 85%;

  hr {
    flex: 1;
    background-color: var(--app-light-gray);
    width: 50vw;
  }

  span {
    color: map-get($colors , medium_light_shade_gray );
    font-family: "Noto Sans";
    font-size: 14px;
    letter-spacing: 0;
    line-height: 19px;
    padding: 0 0.75rem;
    text-transform: uppercase;
  }
}

.sign-in-button {
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-to {
  font-size: 1.25rem;
}

.text-overlay {
  margin: 0.85rem;
}

.p-lr-0 {
  margin-left: 0px !important;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""