Guest User

Untitled

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