diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 162cc64b..98f0aaae 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -29,6 +29,7 @@ import { MatInputModule } from "@angular/material/input"; import { MatFormFieldModule } from "@angular/material/form-field"; import {MatTabsModule} from "@angular/material/tabs"; import {PasswordValidator} from "./misc/password-validator"; +import {MatCheckboxModule} from "@angular/material/checkbox"; @NgModule({ declarations: [ @@ -64,7 +65,8 @@ import {PasswordValidator} from "./misc/password-validator"; MatInputModule, MatFormFieldModule, FormsModule, - MatTabsModule + MatTabsModule, + MatCheckboxModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index e08a8b68..0b7772a3 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -3,38 +3,37 @@
- -
+ + - Email - - - An email is required - - - Please enter a valid email + Username + + + An username is required

Password - - A password is required - Error: {{signinPassword.getError("passwordError")["error"]}} + Error: {{loginPassword.getError("passwordError")["error"]}} - -
-
- -
+
+ Stay logged in +
+
+ +
+

@@ -64,7 +63,7 @@ Password - diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index feb6d9e2..69f06ed8 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,5 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; import {AuthService} from "../services/auth.service"; +import {ActivatedRoute, Router} from "@angular/router"; @Component({ selector: 'app-login', @@ -8,15 +9,33 @@ import {AuthService} from "../services/auth.service"; }) export class LoginComponent { - loginInformation: {email: string, password: string} = {email: "", password: ""}; + loginInformation: {username: string, password: string, stayLoggedIn: boolean} = {username: "", password: "", stayLoggedIn: false}; signinInformation: {email: string, username: string, password: string} = {email: "", username: "", password: ""}; hidePassword: boolean = true; + redirectURI: string = "/"; - constructor(private authService: AuthService) { } + constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute) + { + if (this.route.snapshot.queryParams["redirectURI"]) + this.redirectURI = this.route.snapshot.queryParams["redirectURI"]; + if (this.route.snapshot.queryParams["otac"]) + this.useOTAC(this.route.snapshot.queryParams["otac"]); + } async login() { - + this.authService.login(this.loginInformation) + .subscribe(() => + { + this.router.navigateByUrl(this.redirectURI); + }, error => { + console.log("Login error: " + error); + }); + } + + useOTAC(otac: string) + { + console.log("Got an OTAC: " + otac); } async signin() @@ -24,10 +43,9 @@ export class LoginComponent this.authService.register(this.signinInformation) .subscribe(result => { - console.log("Sucess: " + result); + this.useOTAC(result); }, error => { console.log("Register error: " + error); }); - console.log("Register returned"); } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 87b89846..891cec2a 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { UserManager, UserManagerSettings, User } from 'oidc-client'; import {HttpClient} from "@angular/common/http"; import { catchError } from 'rxjs/operators'; -import {EMPTY} from "rxjs"; +import {EMPTY, Observable} from "rxjs"; import {MatSnackBar} from "@angular/material/snack-bar"; @Injectable({ @@ -23,14 +23,20 @@ export class AuthService }); } - login() + login(loginInformation: any) { - return this._userManager.signinRedirect(); + return this.http.post("/api/account/login", loginInformation).pipe(catchError((error => + { + console.log(error.status + " - " + error.message); + this.snackBar.open(`An unknown error occured: ${error.message}.`, null, { horizontalPosition: "left", panelClass: ['snackError'], duration: 2500 }); + return EMPTY; + }))); } - register(userRegistration: any) + register(userRegistration: any) : Observable { - return this.http.post("/api/account/register", userRegistration).pipe(catchError((error => + // @ts-ignore + return this.http.post("/api/account/register", userRegistration, {responseType: "text"}).pipe(catchError((error => { console.log(error.status + " - " + error.message); this.snackBar.open(`An unknown error occured: ${error.message}.`, null, { horizontalPosition: "left", panelClass: ['snackError'], duration: 2500 });