Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. @Injectable()
  2. export class UsersInfoService {
  3. private _users: User[]=[];
  4. private isLoggedIn = false;
  5. private URL = '/assets/data';
  6. constructor(private http: Http) {
  7. this.getData();
  8. }
  9.  
  10. addUser(user: User) {
  11. this._users.push(user);
  12. }
  13.  
  14. getUser(id) {
  15. console.log(this._users);
  16. this._users.find(user =>user.id === id);
  17. }
  18.  
  19. getUsers() {
  20. return this._users;
  21. }
  22.  
  23. getData(){
  24. this.http.get(this.URL + '/user.json')
  25. .map(res => res.json() as User[])
  26. .subscribe((res) => {
  27. this._users.push(res);
  28. },
  29. err => console.error(err),
  30. () => console.log('done')
  31. );
  32. console.log(this._users);
  33. }
  34. checkAuth(emailAddress, password) {
  35. console.log("checkAuth :" + this._users);
  36. this._users.forEach(user => {
  37. if (user.emailAddress === emailAddress && user.password === password) {
  38. return true
  39. }
  40. });
  41. return false;
  42. }
  43. }
  44.  
  45. [
  46. {
  47. "id":"1",
  48. "userName":"admin@site.com",
  49. "firstName":"admin",
  50. "lastName": "admin",
  51. "dateOfBirth":"05/05/1985",
  52. "emailAddress":"admin@site.com",
  53. "password":"admin123"
  54. },
  55. {
  56. "id":"2",
  57. "userName":"admin2@site.com",
  58. "firstName":"admin2",
  59. "lastName": "admin2",
  60. "dateOfBirth":"05/05/1985",
  61. "emailAddress":"admin2@site.com",
  62. "password":"admin456"
  63. }
  64. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement