Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Injectable()
- export class UsersInfoService {
- private _users: User[]=[];
- private isLoggedIn = false;
- private URL = '/assets/data';
- constructor(private http: Http) {
- this.getData();
- }
- addUser(user: User) {
- this._users.push(user);
- }
- getUser(id) {
- console.log(this._users);
- this._users.find(user =>user.id === id);
- }
- getUsers() {
- return this._users;
- }
- getData(){
- this.http.get(this.URL + '/user.json')
- .map(res => res.json() as User[])
- .subscribe((res) => {
- this._users.push(res);
- },
- err => console.error(err),
- () => console.log('done')
- );
- console.log(this._users);
- }
- checkAuth(emailAddress, password) {
- console.log("checkAuth :" + this._users);
- this._users.forEach(user => {
- if (user.emailAddress === emailAddress && user.password === password) {
- return true
- }
- });
- return false;
- }
- }
- [
- {
- "id":"1",
- "userName":"admin@site.com",
- "firstName":"admin",
- "lastName": "admin",
- "dateOfBirth":"05/05/1985",
- "emailAddress":"admin@site.com",
- "password":"admin123"
- },
- {
- "id":"2",
- "userName":"admin2@site.com",
- "firstName":"admin2",
- "lastName": "admin2",
- "dateOfBirth":"05/05/1985",
- "emailAddress":"admin2@site.com",
- "password":"admin456"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement