- private router: Router
- ) {}
-
- ngOnInit() {
- this.loginForm = new FormGroup({
- username: new FormControl('', [ <any>Validators.required ]),
- password: new FormControl('', [ <any>Validators.required ]),
- });
- }
-
- login() {
- this.authService.login(this.username, this.password).subscribe(
- result => {
- this.error = null;
-
- this.router.navigate(['/videos/list']);
- },
- error => {
- console.error(error);
-
- if (error.error === 'invalid_grant') {
- this.error = 'Credentials are invalid.';
- } else {
- this.error = `${error.error}: ${error.error_description}`;
+ private userService: UserService,
+ private serverService: ServerService,
+ private redirectService: RedirectService,
+ private notifier: Notifier,
+ private i18n: I18n
+ ) {
+ super()
+ }
+
+ get signupAllowed () {
+ return this.serverService.getConfig().signup.allowed === true
+ }
+
+ isEmailDisabled () {
+ return this.serverService.getConfig().email.enabled === false
+ }
+
+ ngOnInit () {
+ this.buildForm({
+ username: this.loginValidatorsService.LOGIN_USERNAME,
+ password: this.loginValidatorsService.LOGIN_PASSWORD
+ })
+
+ this.input.nativeElement.focus()
+ }
+
+ login () {
+ this.error = null
+
+ const { username, password } = this.form.value
+
+ this.authService.login(username, password)
+ .subscribe(
+ () => this.redirectService.redirectToPreviousRoute(),
+
+ err => {
+ if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.')
+ else if (err.message.indexOf('blocked') !== -1) this.error = this.i18n('You account is blocked.')
+ else this.error = err.message