mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-28 13:48:49 +08:00

* MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Add SPDX license and copyright headers Signed-off-by: Ivan Milošević <iva@blokovi.com> * MF-325 - Change mainflux version from 0.4.0 to 0.5.0 Signed-off-by: Ivan Milošević <iva@blokovi.com>
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
/*
|
|
* Copyright (c) 2018
|
|
* Mainflux
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
import { User } from '../store/models';
|
|
|
|
export const MOCK_USER = {
|
|
email: 'asdf@asdf.com',
|
|
password: 'asdf'
|
|
};
|
|
|
|
export const EXISTING_USER = {
|
|
email: '1234@1234.com',
|
|
password: '1234'
|
|
};
|
|
|
|
export const INVALID_CREDENTIALS_USER = {
|
|
email: 'pera@pera.com',
|
|
password: 'pera'
|
|
};
|
|
|
|
@Injectable()
|
|
export class MockAuthService {
|
|
public signup(user: User): Observable<User> {
|
|
if (user.email === MOCK_USER.email) {
|
|
return Observable.of(user).delay(5000);
|
|
}
|
|
|
|
if (user.email === EXISTING_USER.email) {
|
|
return Observable.throw(new Error('User with email already exists.'));
|
|
}
|
|
|
|
return Observable.throw(new Error('Failed connecting to server.'));
|
|
}
|
|
|
|
public login(user: User): Observable<User> {
|
|
if (user.email === MOCK_USER.email) {
|
|
return Observable.of(user).delay(1000);
|
|
}
|
|
|
|
if (user.email === INVALID_CREDENTIALS_USER.email) {
|
|
return Observable.throw(new Error('Invalid credentials'));
|
|
}
|
|
|
|
return Observable.throw(new Error('Cannot connect to server'));
|
|
}
|
|
}
|