Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import { Injectable } from 'angular2/core';
  2. import { Subject } from 'rxjs';
  3. import { Storage } from './storage';
  4. import { CurrentUser } from '../interfaces/common';
  5.  
  6. @Injectable()
  7. export class Authentication{
  8. private _storageService : Storage;
  9. private _userKey : string = "CURRENT_USER";
  10.  
  11. constructor(storageService : Storage){
  12. this._storageService = storageService;
  13. }
  14.  
  15. authenticate(name : string, password: string){
  16. return new Promise((resolve, reject) => {
  17. setTimeout(() => {
  18. this.currentUser = {
  19. name,
  20. roles : ['ADMIN']
  21. };
  22. resolve(true);
  23. }, 100);
  24. });
  25. }
  26.  
  27. logOut(){
  28. this._storageService.removeStorage(this._userKey);
  29. }
  30.  
  31. get userRoles() : Array<string> {
  32. const user = this._storageService.getStorage(this._userKey);
  33. return user ? user.roles : [];
  34. }
  35.  
  36. get currentUser() : CurrentUser {
  37. return this._storageService.getStorage(this._userKey);
  38. }
  39.  
  40. set currentUser(user : CurrentUser){
  41. this._storageService.setStorage(this._userKey, user);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement