fix login service

merge-requests/1/head
Florian Hartwich 2017-04-11 03:27:12 +02:00
parent 21615b5532
commit 42cf1c9aa4
6 changed files with 14 additions and 17 deletions

View File

@ -17,10 +17,10 @@
"description": "Nicht länger als 15 Minuten... ",
"tags": [],
"assignee": {
"name": "John Doe",
"email": "john@doe.com"
"name": "",
"email": ""
},
"state": "BACKLOG"
"state": "IN_PROGRESS"
},
{
"title": "Test der Websocket-Funktionalität",

View File

@ -18,8 +18,7 @@ export class LoginComponent {
}
login(userName: string, password: string) {
const result = this.loginService.login(userName, password);
if (result) {
if (this.loginService.login(userName, password)) {
const queryParams = this.route.snapshot.queryParams;
const redirect = queryParams['redirect'] || '/';
this.router.navigateByUrl(decodeURI(redirect));

View File

@ -19,27 +19,28 @@ export class LoginService {
users$: Observable<User[]>;
results$: User[];
constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled = false, private http: Http, private userStore: UserStore,
@Inject(SOCKET_IO) socketIO) {
this.users$ = userStore.items$;
this.socket = socketIO(WEB_SOCKET_URL);
}
getUser(name: string): User[] {
let results;
this.http.get(BASE_URL + "?name=" + name).subscribe(result => results = result.json());
return results;
getUser(name: string) {
this.http.get(BASE_URL + "?name=" + name).subscribe(result => this.results$ = result.json());
return this.results$;
}
login(name, password) {
let results = this.getUser(name);
if (results) {
let user = results[0];
login(name, password) : boolean {
if (this.getUser(name)) {
let user = this.results$[0];
let passMd5 = Md5.hashStr(password);
if (user && user.password === passMd5) {
localStorage.setItem(CURRENT_USER, JSON.stringify(user));
return true;
}
return false;
}
}

View File

@ -39,7 +39,6 @@ describe('Login-Service', () => {
);
it('should trigger a HTTP-GET and receive Task', (() => {
console.log(userStore.items$);
mockBackend.connections.subscribe(connection => {
const expectedUrl = 'http://localhost:3000/api/users/';
expect(connection.request.url).toBe(expectedUrl);

View File

@ -11,7 +11,6 @@ export class TaskStore {
items$ = new BehaviorSubject<Task[]>([]);
dispatch(action) {
console.log("dispatched")
this.tasks = this._reduce(this.tasks, action);
this.items$.next(this.tasks);
}

View File

@ -9,7 +9,6 @@ export class UserStore {
items$ = new BehaviorSubject<User[]>([]);
dispatch(action) {
console.log("dispatched")
this.users = this._reduce(this.users, action);
this.items$.next(this.users);
}