From a840d396093ef968f9512862197ac166a1ff9921 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 1 Jun 2016 20:36:27 +0200 Subject: Add authentication tokens to make friends/quit friends --- client/app/login/index.ts | 1 + client/app/login/login.component.html | 14 ++++++++++++++ client/app/login/login.component.ts | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 client/app/login/index.ts create mode 100644 client/app/login/login.component.html create mode 100644 client/app/login/login.component.ts (limited to 'client/app/login') diff --git a/client/app/login/index.ts b/client/app/login/index.ts new file mode 100644 index 000000000..69c16441f --- /dev/null +++ b/client/app/login/index.ts @@ -0,0 +1 @@ +export * from './login.component'; diff --git a/client/app/login/login.component.html b/client/app/login/login.component.html new file mode 100644 index 000000000..940694515 --- /dev/null +++ b/client/app/login/login.component.html @@ -0,0 +1,14 @@ +

Login

+
+
+ + +
+ +
+ + +
+ + +
diff --git a/client/app/login/login.component.ts b/client/app/login/login.component.ts new file mode 100644 index 000000000..50f598d92 --- /dev/null +++ b/client/app/login/login.component.ts @@ -0,0 +1,36 @@ +import { Component } from '@angular/core'; +import { Router } from '@angular/router-deprecated'; + +import { AuthService, AuthStatus, User } from '../shared/index'; + +@Component({ + selector: 'my-login', + templateUrl: 'client/app/login/login.component.html' +}) + +export class LoginComponent { + 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