49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {LoginService} from '../services/app-user-service/login-service';
|
|
import {RouteConfig} from '../app.config';
|
|
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
|
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
templateUrl: './signup.component.html',
|
|
styleUrls: ['./login.component.scss']
|
|
})
|
|
|
|
export class SignupComponent implements OnInit {
|
|
|
|
loading = false;
|
|
|
|
returnUrl: string;
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
private router: Router,
|
|
private loginService: LoginService,
|
|
private snackBarService: SnackBarService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
// reset login status
|
|
this.loginService.logout();
|
|
// redirect on success
|
|
this.returnUrl = RouteConfig.overviewPath;
|
|
}
|
|
|
|
signup(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 => {
|
|
this.loading = false;
|
|
this.snackBarService.showSuccess('generic.signup.success');
|
|
},
|
|
error => {
|
|
this.loading = false;
|
|
this.snackBarService.showError('generic.signup.error', 6000);
|
|
});
|
|
}
|
|
}
|
|
}
|