From 41a2aee38cf812510010da09de9bae53590ec119 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 16:23:10 +0200 Subject: Follow the angular styleguide for the directories structure --- client/app/users/login/login.component.ts | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 client/app/users/login/login.component.ts (limited to 'client/app/users/login/login.component.ts') diff --git a/client/app/users/login/login.component.ts b/client/app/users/login/login.component.ts new file mode 100644 index 000000000..33590ad4c --- /dev/null +++ b/client/app/users/login/login.component.ts @@ -0,0 +1,34 @@ +import { Component } from '@angular/core'; +import { Router } from '@angular/router-deprecated'; + +import { AuthService, AuthStatus, User } from '../shared/index'; + +@Component({ + selector: 'my-user-login', + styleUrls: [ 'client/app/users/login/login.component.css' ], + templateUrl: 'client/app/users/login/login.component.html' +}) + +export class UserLoginComponent { + constructor(private _authService: AuthService, private _router: Router) {} + + login(username: string, password: string) { + this._authService.login(username, password).subscribe( + result => { + const user = new User(username, result); + user.save(); + + this._authService.setStatus(AuthStatus.LoggedIn); + + this._router.navigate(['VideosList']); + }, + error => { + if (error.error === 'invalid_grant') { + alert('Credentials are invalid.'); + } else { + alert(`${error.error}: ${error.error_description}`); + } + } + ); + } +} -- cgit v1.2.3