SHARE
TWEET

Untitled

a guest Aug 17th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2.  
  3. @Injectable({
  4.   providedIn: 'root'
  5. })
  6. export class AuthService {
  7.  
  8.   constructor() { }
  9.   /*
  10.   The login method will return true if the provided user/password pair
  11.   equals 'user' and 'password', respectively. Also, when it is matched, it’s
  12.   going to use localStorage to save the username. This will also serve as a flag
  13.   to indicate whether or not there is an active logged user.
  14.    */
  15.   login(user: string, password: string): boolean {
  16.     if (user === 'user' && password === 'password') {
  17.       localStorage.setItem('username', user);
  18.       return true;
  19.     }
  20.     return false;
  21.   }
  22.   // The logout method just clears the username value:
  23.   logout(): void {
  24.     localStorage.removeItem('username');
  25.   }
  26.   // getUser returns the username or null
  27.   getUser(): any {
  28.     return localStorage.getItem('username');
  29.   }
  30.   // isLoggedIn uses getUser() to return true if we have a user
  31.   isLoggedIn(): boolean {
  32.     return this.getUser() !== null;
  33.   }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top