opt-cc/static/src/app/login/signup.component.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-03-07 11:56:50 +01:00
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';
2017-06-08 19:46:36 +02:00
@Component({
moduleId: module.id,
templateUrl: './signup.component.html',
styleUrls: ['./login.component.scss']
2017-06-08 19:46:36 +02:00
})
export class SignupComponent implements OnInit {
loading = false;
returnUrl: string;
constructor(private route: ActivatedRoute,
private router: Router,
private loginService: LoginService,
private snackBarService: SnackBarService) {
2017-06-08 19:46:36 +02:00
}
ngOnInit() {
// reset login status
this.loginService.logout();
// redirect on success
this.returnUrl = RouteConfig.overviewPath;
2017-06-08 19:46:36 +02:00
}
2018-10-02 12:56:51 +02:00
signup(username: string, password: string, secret: string) {
2017-06-08 19:46:36 +02:00
if (username.length > 0 && password.length > 0 && secret.length > 0) {
this.loading = true;
this.loginService.signUp(username, password, secret)
2018-02-26 09:04:27 +01:00
.subscribe(
data => {
this.loading = false;
2018-10-05 15:51:46 +02:00
this.snackBarService.showSuccess('generic.signup.success');
2018-02-26 09:04:27 +01:00
},
error => {
this.loading = false;
2018-10-05 15:51:46 +02:00
this.snackBarService.showError('generic.signup.error', 6000);
2018-02-26 09:04:27 +01:00
});
2017-06-08 19:46:36 +02:00
}
}
}