From 6fe3d083f9c23d11554e9e117342678d88f9cd89 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sat, 13 May 2023 09:03:26 -0400 Subject: [PATCH] Login --- src/app/pages/home/home.page.html | 8 -- src/app/pages/home/home.page.ts | 9 +- src/app/pages/login/login.page.html | 4 +- src/app/pages/login/login.page.ts | 44 ++++++- src/app/services/wrench.service.ts | 6 +- .../session-data-provider.service.spec.ts | 16 +++ .../store/session-data-provider.service.ts | 113 ++++++++++++++++++ src/environments/environment.prod.ts | 4 +- src/environments/environment.ts | 4 +- 9 files changed, 180 insertions(+), 28 deletions(-) create mode 100644 src/app/store/session-data-provider.service.spec.ts create mode 100644 src/app/store/session-data-provider.service.ts diff --git a/src/app/pages/home/home.page.html b/src/app/pages/home/home.page.html index 4bca17c..8a1ddb5 100644 --- a/src/app/pages/home/home.page.html +++ b/src/app/pages/home/home.page.html @@ -1,11 +1,3 @@ -
diff --git a/src/app/pages/home/home.page.ts b/src/app/pages/home/home.page.ts index cf40532..7d17535 100644 --- a/src/app/pages/home/home.page.ts +++ b/src/app/pages/home/home.page.ts @@ -1,13 +1,6 @@ -/* - Authors : initappz (Rahul Jograna) - Website : https://initappz.com/ - App Name : E-Learning App Template - This App Template Source code is licensed as per the - terms found in the Website https://initappz.com/license - Copyright and Good Faith Purchasers © 2021-present initappz. -*/ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; +import { SessionDataProviderService } from 'src/app/store/session-data-provider.service'; @Component({ selector: 'app-home', diff --git a/src/app/pages/login/login.page.html b/src/app/pages/login/login.page.html index bfb6a82..ff14e7b 100644 --- a/src/app/pages/login/login.page.html +++ b/src/app/pages/login/login.page.html @@ -6,12 +6,12 @@ - + - +
diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index d8b93f9..a9b58a3 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -1,5 +1,7 @@ import { Router } from '@angular/router'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { WrenchService } from 'src/app/services/wrench.service'; +import { SessionDataProviderService } from 'src/app/store/session-data-provider.service'; @Component({ selector: 'app-login', @@ -7,16 +9,37 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./login.page.scss'], }) export class LoginPage implements OnInit { - + @ViewChild('username') username; + @ViewChild('password') password; + loginResult: any; constructor( - private router: Router + private router: Router, + private wrenchService: WrenchService, + private sessionDataProviderService:SessionDataProviderService ) { } ngOnInit() { } + loginData: { + username: string, password: string, sessionid: string + }; startLogin() { + if (this.username == null || this.username == '' || this.validateEmail(this.username) == false || this.password == null || this.password == '') { + this.showAlert('Invalid Login', 'Enter username(email) and password to login'); + return; + } + this.loginData = { username: this.username, password: this.password, sessionid: 'DUMMY-APP-SESSION' } + this.wrenchService.loginUser(this.loginData).subscribe( + loginResult => { + this.loginResult = loginResult; + console.log("INTERNAL RETURN->" + this.loginResult.internal_return); + if (loginResult != null && loginResult.internal_return == 100 && this.sessionDataProviderService.ConstructGlobalSessionData(this.loginResult) == true) { + this.router.navigate(['tabs/tab1']); + } + } + ); //this.router.navigate(['tabs/tab1']); } @@ -32,4 +55,19 @@ export class LoginPage implements OnInit { this.router.navigate(['slider']); } + validateEmail(email) { + var re = /\S+@\S+\.\S+/; + return re.test(email); + } + + showAlert(mtitle: string, amessage: string) { + /* let alert = this.alertCtrl.create({ + title: mtitle, + subTitle: amessage, + buttons: ['OK'] + }); + alert.present();*/ + alert(amessage); + } + } diff --git a/src/app/services/wrench.service.ts b/src/app/services/wrench.service.ts index e864829..0788323 100644 --- a/src/app/services/wrench.service.ts +++ b/src/app/services/wrench.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import 'rxjs/add/operator/map'; +//import 'rxjs/add/operator/map'; import { environment } from 'src/environments/environment'; @@ -20,14 +20,14 @@ export class WrenchService { getPostData(reqPath:string, reqData): Observable { return this.http.post( - `${environment.baseUrl}/movie/}`,reqData + `${environment.baseUrl}/${reqPath}`,reqData ); } loginUser(loginData) { - return this.getPostData('getPostData',loginData); + return this.getPostData('userlogin',loginData); } /* registerUser(newUserData) { diff --git a/src/app/store/session-data-provider.service.spec.ts b/src/app/store/session-data-provider.service.spec.ts new file mode 100644 index 0000000..062bbc8 --- /dev/null +++ b/src/app/store/session-data-provider.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { SessionDataProviderService } from './session-data-provider.service'; + +describe('SessionDataProviderService', () => { + let service: SessionDataProviderService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(SessionDataProviderService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/store/session-data-provider.service.ts b/src/app/store/session-data-provider.service.ts new file mode 100644 index 0000000..3103c8a --- /dev/null +++ b/src/app/store/session-data-provider.service.ts @@ -0,0 +1,113 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class SessionDataProviderService { + + constructor() { + console.log('Hello SessionDataProvider Store'); + } + + firstname: string = ""; + lastname:string = ""; + session: string = ""; + balance:number =0; + username:string=""; + last_login:string=""; + member_id:number = 0; + ccard:number=0; + isPedningJob: number = 0; + isOfferJob: number = 0; + profile_pic:string=''; + + session_contructed:boolean = false; + + + ConstructGlobalSessionData(loginResult: any) { + console.log('Hello ConstructGlobalSessionData Provider'); + this.session_contructed=false; + + try { + console.log(loginResult); + + this.firstname = loginResult.firstname; + this.lastname = loginResult.lastname; + this.session = loginResult.session; + this.session_contructed=loginResult.balance; + this.username=loginResult.username; + this.last_login = loginResult.last_login2; + this.member_id = loginResult.member_id; + this.balance = loginResult.balance; + this.ccard=loginResult.ccard; + this.profile_pic=loginResult.profile_pic; + this.isPedningJob = loginResult.pedningjob; + this.isOfferJob = loginResult.offerjob; + + //this.pushNotificationProvider.tagUser(this.session); + + this.session_contructed = true; + + // this.SessionUser.added = loginResult.added; + /* this.SessionUser.added = ""; + this.SessionUser.balance = loginResult.balance; + this.SessionUser.city = loginResult.city; + this.SessionUser.country = loginResult.country; + this.SessionUser.email = loginResult.email; + this.SessionUser.fb_id = loginResult.fb_id; + this.SessionUser.firstname = loginResult.firstname; + this.SessionUser.id = loginResult.id; + this.SessionUser.last_login = loginResult.last_login; + this.SessionUser.loc = loginResult.loc; + this.SessionUser.member_id = loginResult.member_id; + + this.SessionUser.news = loginResult.news; + this.SessionUser.phone = loginResult.phone; + this.SessionUser.post_jobs = loginResult.post_jobs; + this.SessionUser.profile_pic = loginResult.profile_pic; + this.SessionUser.session = loginResult.session; + + this.SessionUser = { + added: loginResult.added, + balance: loginResult.balance, + city: loginResult.city, + country: loginResult.country, + email: loginResult.email, + fb_id: loginResult.fb_id, + firstname: loginResult.firstname, + id: loginResult.id, + last_login: loginResult.last_login, + lastname: loginResult.lastname, + loc: loginResult.loc, + member_id: loginResult.member_id, + news: loginResult.news, + phone: loginResult.phone, + post_jobs: loginResult.post_jobs, + profile_pic: loginResult.profile_pic, + refer: loginResult.refer, + session: loginResult.session, + state: loginResult.state, + status: loginResult.status, + username: loginResult.username + }; + + + this.storage.set('sessionuser', JSON.stringify(this.SessionUser)); + */ + } catch (error) { + console.log("LOGIN STORAGE ERROR->" + error); + } + + + + return this.session_contructed; + } + + profilePicture(){ + var profile_p = ''; + if (this.profile_pic !=''){ + profile_p="https://www.wrenchboard.com/smedia/LIVE/profile/"+this.profile_pic; + } + return profile_p; + } +} diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 66f2c1c..148fa4f 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,6 @@ export const environment = { production: true, apiKey: '', // <-- Enter your own key here!' - baseUrl: 'https://api.themoviedb.org/3', - images: 'http://image.tmdb.org/t/p', + baseUrl: 'https://orion.lotus.g1.wrenchboard.com/svs/user', + images: 'https://orion.lotus.g1.wrenchboard.com/svs/user', }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 68facc1..52d3249 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,7 +1,7 @@ export const environment = { production: false, apiKey: '', // <-- Enter your own key here!' - baseUrl: 'https://api.themoviedb.org/3', - images: 'http://image.tmdb.org/t/p', + baseUrl: 'https://apigate.lotus.g1.wrenchboard.com/svs/user', + images: 'https://apigate.lotus.g1.wrenchboard.com/svs/user', };