import { ActivatedRoute } from '@angular/router'
import { AuthService, Notifier, RedirectService, UserService } from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
-import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/form-validators/login-validators'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
+import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models'
})
export class LoginComponent extends FormReactive implements OnInit, AfterViewInit {
- @ViewChild('usernameInput', { static: false }) usernameInput: ElementRef
@ViewChild('forgotPasswordModal', { static: true }) forgotPasswordModal: ElementRef
accordion: NgbAccordion
private redirectService: RedirectService,
private notifier: Notifier,
private hooks: HooksService
- ) {
+ ) {
super()
}
}
ngAfterViewInit () {
- if (this.usernameInput) {
- this.usernameInput.nativeElement.focus()
- }
-
this.hooks.runAction('action:login.init', 'login')
}
const { username, password } = this.form.value
this.authService.login(username, password)
- .subscribe(
- () => this.redirectService.redirectToPreviousRoute(),
+ .subscribe({
+ next: () => this.redirectService.redirectToPreviousRoute(),
- err => this.handleError(err)
- )
+ error: err => this.handleError(err)
+ })
}
askResetPassword () {
this.userService.askResetPassword(this.forgotPasswordEmail)
- .subscribe(
- () => {
+ .subscribe({
+ next: () => {
const message = $localize`An email with the reset password instructions will be sent to ${this.forgotPasswordEmail}.
The link will expire within 1 hour.`
this.hideForgotPasswordModal()
},
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
openForgotPasswordModal () {
this.accordion = instanceAboutAccordion.accordion
}
+ hasUsernameUppercase () {
+ return this.form.value['username'].match(/[A-Z]/)
+ }
+
private loadExternalAuthToken (username: string, token: string) {
this.isAuthenticatedWithExternalAuth = true
this.authService.login(username, null, token)
- .subscribe(
- () => this.redirectService.redirectToPreviousRoute(),
-
- err => {
- this.handleError(err)
- this.isAuthenticatedWithExternalAuth = false
- }
- )
+ .subscribe({
+ next: () => this.redirectService.redirectToPreviousRoute(),
+
+ error: err => {
+ this.handleError(err)
+ this.isAuthenticatedWithExternalAuth = false
+ }
+ })
}
private handleError (err: any) {