fix login service
parent
21615b5532
commit
42cf1c9aa4
|
@ -17,10 +17,10 @@
|
||||||
"description": "Nicht länger als 15 Minuten... ",
|
"description": "Nicht länger als 15 Minuten... ",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"assignee": {
|
"assignee": {
|
||||||
"name": "John Doe",
|
"name": "",
|
||||||
"email": "john@doe.com"
|
"email": ""
|
||||||
},
|
},
|
||||||
"state": "BACKLOG"
|
"state": "IN_PROGRESS"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Test der Websocket-Funktionalität",
|
"title": "Test der Websocket-Funktionalität",
|
||||||
|
|
|
@ -18,8 +18,7 @@ export class LoginComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
login(userName: string, password: string) {
|
login(userName: string, password: string) {
|
||||||
const result = this.loginService.login(userName, password);
|
if (this.loginService.login(userName, password)) {
|
||||||
if (result) {
|
|
||||||
const queryParams = this.route.snapshot.queryParams;
|
const queryParams = this.route.snapshot.queryParams;
|
||||||
const redirect = queryParams['redirect'] || '/';
|
const redirect = queryParams['redirect'] || '/';
|
||||||
this.router.navigateByUrl(decodeURI(redirect));
|
this.router.navigateByUrl(decodeURI(redirect));
|
||||||
|
|
|
@ -19,27 +19,28 @@ export class LoginService {
|
||||||
|
|
||||||
users$: Observable<User[]>;
|
users$: Observable<User[]>;
|
||||||
|
|
||||||
|
results$: User[];
|
||||||
|
|
||||||
constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled = false, private http: Http, private userStore: UserStore,
|
constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled = false, private http: Http, private userStore: UserStore,
|
||||||
@Inject(SOCKET_IO) socketIO) {
|
@Inject(SOCKET_IO) socketIO) {
|
||||||
this.users$ = userStore.items$;
|
this.users$ = userStore.items$;
|
||||||
this.socket = socketIO(WEB_SOCKET_URL);
|
this.socket = socketIO(WEB_SOCKET_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser(name: string): User[] {
|
getUser(name: string) {
|
||||||
let results;
|
this.http.get(BASE_URL + "?name=" + name).subscribe(result => this.results$ = result.json());
|
||||||
this.http.get(BASE_URL + "?name=" + name).subscribe(result => results = result.json());
|
return this.results$;
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
login(name, password) {
|
login(name, password) : boolean {
|
||||||
let results = this.getUser(name);
|
if (this.getUser(name)) {
|
||||||
if (results) {
|
let user = this.results$[0];
|
||||||
let user = results[0];
|
|
||||||
let passMd5 = Md5.hashStr(password);
|
let passMd5 = Md5.hashStr(password);
|
||||||
if (user && user.password === passMd5) {
|
if (user && user.password === passMd5) {
|
||||||
localStorage.setItem(CURRENT_USER, JSON.stringify(user));
|
localStorage.setItem(CURRENT_USER, JSON.stringify(user));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ describe('Login-Service', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
it('should trigger a HTTP-GET and receive Task', (() => {
|
it('should trigger a HTTP-GET and receive Task', (() => {
|
||||||
console.log(userStore.items$);
|
|
||||||
mockBackend.connections.subscribe(connection => {
|
mockBackend.connections.subscribe(connection => {
|
||||||
const expectedUrl = 'http://localhost:3000/api/users/';
|
const expectedUrl = 'http://localhost:3000/api/users/';
|
||||||
expect(connection.request.url).toBe(expectedUrl);
|
expect(connection.request.url).toBe(expectedUrl);
|
||||||
|
|
|
@ -11,7 +11,6 @@ export class TaskStore {
|
||||||
items$ = new BehaviorSubject<Task[]>([]);
|
items$ = new BehaviorSubject<Task[]>([]);
|
||||||
|
|
||||||
dispatch(action) {
|
dispatch(action) {
|
||||||
console.log("dispatched")
|
|
||||||
this.tasks = this._reduce(this.tasks, action);
|
this.tasks = this._reduce(this.tasks, action);
|
||||||
this.items$.next(this.tasks);
|
this.items$.next(this.tasks);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ export class UserStore {
|
||||||
items$ = new BehaviorSubject<User[]>([]);
|
items$ = new BehaviorSubject<User[]>([]);
|
||||||
|
|
||||||
dispatch(action) {
|
dispatch(action) {
|
||||||
console.log("dispatched")
|
|
||||||
this.users = this._reduce(this.users, action);
|
this.users = this._reduce(this.users, action);
|
||||||
this.items$.next(this.users);
|
this.items$.next(this.users);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue