2017-06-08 19:46:36 +02:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {LoginService} from "../services/login-service/login-service";
|
2017-08-01 23:52:10 +02:00
|
|
|
import {RouteConfig} from "../app.config";
|
2017-06-08 19:46:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
moduleId: module.id,
|
|
|
|
templateUrl: './signup.component.html',
|
|
|
|
styleUrls: ['./login.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SignupComponent implements OnInit {
|
|
|
|
|
|
|
|
showErrorLabel = false;
|
|
|
|
|
2017-06-11 13:18:03 +02:00
|
|
|
showSuccessLabel = false;
|
|
|
|
|
|
|
|
error: string;
|
|
|
|
|
2017-06-08 19:46:36 +02:00
|
|
|
loading = false;
|
|
|
|
|
|
|
|
returnUrl: string;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private loginService: LoginService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
// reset login status
|
|
|
|
this.loginService.logout();
|
|
|
|
// redirect on success
|
2017-08-01 23:52:10 +02:00
|
|
|
this.returnUrl = RouteConfig.overviewPath;
|
2017-06-08 19:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
login(username: string, password: string, secret: string) {
|
|
|
|
if (username.length > 0 && password.length > 0 && secret.length > 0) {
|
|
|
|
this.loading = true;
|
|
|
|
this.loginService.signUp(username, password, secret)
|
|
|
|
.subscribe(
|
|
|
|
data => {
|
2017-06-11 13:18:03 +02:00
|
|
|
this.loading = false;
|
|
|
|
this.showSuccessLabel = true;
|
2017-06-08 19:46:36 +02:00
|
|
|
},
|
|
|
|
error => {
|
2017-06-11 13:18:03 +02:00
|
|
|
this.error = error;
|
2017-06-08 19:46:36 +02:00
|
|
|
this.showErrorLabel = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.showErrorLabel = false;
|
|
|
|
}, 4000);
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|