Commit f9fda747 by Muhammad Usman

social login added

parent b31b005b
...@@ -36,12 +36,12 @@ ...@@ -36,12 +36,12 @@
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<button class="action-btn google-login" (click)="socicalMediaLogin('google')" [disabled]="isLoading">Sign in with Google</button> <button class="action-btn google-login" (click)="socialMediaLogin('google')" [disabled]="isLoading">Sign in with Google</button>
</div> </div>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<button class="action-btn linkedin-login" (click)="socicalMediaLogin('linkedIn')" [disabled]="isLoading">Sign in with Linkedin</button> <button class="action-btn linkedin-login" (click)="socialMediaLogin('linkedIn')" [disabled]="isLoading">Sign in with Linkedin</button>
</div> </div>
</form> </form>
</div> </div>
......
import { Component, ViewChild } from '@angular/core'; import { Component, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms'; import { NgForm } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { environment } from '../../../../../environments/environment'; import { environment } from '../../../../../environments/environment';
import { AppService } from '../../../../app.service'; import { AppService } from '../../../../app.service';
...@@ -18,7 +17,6 @@ import { HelperService } from '../../services/helper.service'; ...@@ -18,7 +17,6 @@ import { HelperService } from '../../services/helper.service';
export class LoginComponent extends BaseComponent { export class LoginComponent extends BaseComponent {
year = new Date().getFullYear(); year = new Date().getFullYear();
subscriptions: Array<Subscription> = [];
loginForm = { loginForm = {
username: '', username: '',
...@@ -30,7 +28,7 @@ export class LoginComponent extends BaseComponent { ...@@ -30,7 +28,7 @@ export class LoginComponent extends BaseComponent {
private hs: HelperService, private hs: HelperService,
private as: AuthService, private as: AuthService,
private r: Router, private r: Router,
private appService: AppService private aps: AppService
) { ) {
super(); super();
} }
...@@ -57,57 +55,27 @@ export class LoginComponent extends BaseComponent { ...@@ -57,57 +55,27 @@ export class LoginComponent extends BaseComponent {
}); });
} }
googleLogin(): void { socialMediaLogin(type: 'google' | 'linkedIn') {
this.isLoading = true;
this.as.googleLogin()
.pipe(takeUntil(this.componentInView))
.subscribe(response => {
this.hs.oneItHttpResponse(response);
// if (response.status === 'error') {
// this.loginForm.password = '';
// }
this.isLoading = false;
}, err => {
this.hs.handleHttpError(err);
this.isLoading = false;
});
}
linkedInLogin(): void {
this.isLoading = true;
this.as.linkedinLogin()
.pipe(takeUntil(this.componentInView))
.subscribe(response => {
this.hs.oneItHttpResponse(response);
// if (response.status === 'error') {
// this.loginForm.password = '';
// }
this.isLoading = false;
}, err => {
this.hs.handleHttpError(err);
this.isLoading = false;
});
}
socicalMediaLogin(type : string) {
const params = { const params = {
environment: environment.envName, environment: environment.envName,
nextPage: window.location.href.split('/#/')[0] + '/#/my-career-web/dashboard/home' nextPage: window.location.href.split('/#/')[0] + '/#/my-career-web/dashboard/home'
}; };
const svc = type === 'linkedIn' ? 'LoginWithLinkedIn' : 'LoginWithGoogle'; const svc = type === 'linkedIn' ? 'LoginWithLinkedIn' : 'LoginWithGoogle';
this.isLoading = true;
this.subscriptions.push(this.appService.socicalMediaLogin(svc,params) this.aps.socicalMediaLogin(svc, params)
.subscribe( .pipe(takeUntil(this.componentInView))
data => { .subscribe(data => {
this.isLoading = false;
if (data.destination) { if (data.destination) {
window.location.href = data.destination; window.location.href = data.destination;
return; return;
} }
}, },
error => { err => {
this.hs.handleHttpError(err);
this.isLoading = false;
} }
) )
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment