Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import { BrowserModule } from '@angular/platform-browser';
  2. import { NgModule } from '@angular/core';
  3. import { FormsModule } from "@angular/forms";
  4. import { AppRoutingModule } from './app-routing.module';
  5. import { AppComponent } from './app.component';
  6. import { LoginPageComponent } from './login-page/login-page.component';
  7. import { NavHeaderComponent } from './nav-header/nav-header.component';
  8. import {LoginService} from "./login.service";
  9. @NgModule({
  10. declarations: [
  11. AppComponent,
  12. LoginPageComponent,
  13. NavHeaderComponent
  14. ],
  15. imports: [
  16. BrowserModule,
  17. AppRoutingModule,
  18. FormsModule
  19. ],
  20. bootstrap: [AppComponent]
  21. })
  22. export class AppModule { }
  23.  
  24. import { Component } from '@angular/core';
  25. import { LoginService } from "./login.service";
  26. @Component({
  27. selector: 'app-root',
  28. templateUrl: './app.component.html',
  29. styleUrls: ['./app.component.scss'],
  30. })
  31. export class AppComponent {
  32. private title : string = '*******';
  33. private isLoggedIn : Boolean ;
  34. constructor(loginService : LoginService){
  35. this.isLoggedIn = loginService.CheckLoginStatus();
  36. }
  37. }
  38.  
  39. import { Injectable } from '@angular/core';
  40. @Injectable({
  41. providedIn: 'root'
  42. })
  43. export class LoginService {
  44. private username = "***";
  45. private password = "***";
  46. private isLogin : Boolean = false;
  47. // Variable to check whether the user has logged in or not
  48. constructor(isLogin:Boolean) {
  49. this.isLogin = isLogin;
  50. }
  51. /* Function to check login status */
  52. CheckLoginStatus() {
  53. return this.isLogin;
  54. }
  55. /* Function to call after the user is logged in */
  56. HasLoggedIn() {
  57. this.isLogin = true;
  58. }
  59. /* Function to call after the user is logged out */
  60. HasLoggedOut() {
  61. this.isLogin = false;
  62. }
  63. /*Function to validate User */
  64. validateLogin(username : string , password : string)
  65. {
  66. if(username===this.username && password===this.password)
  67. this.HasLoggedIn();
  68. return this.isLogin;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement