import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
-import { Notifier, RedirectService, ServerService } from '@app/core'
+import { Notifier, RedirectService } from '@app/core'
import { UserService } from '@app/shared'
import { AuthService } from '../core'
import { FormReactive } from '../shared'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { LoginValidatorsService } from '@app/shared/forms/form-validators/login-validators.service'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
-import { ActivatedRoute, Router } from '@angular/router'
-import { ServerConfig } from '@shared/models'
+import { ActivatedRoute } from '@angular/router'
+import { ServerConfig } from '@shared/models/server/server-config.model'
@Component({
selector: 'my-login',
error: string = null
forgotPasswordEmail = ''
+ isAuthenticatedWithExternalAuth = false
private openedForgotPasswordModal: NgbModalRef
private serverConfig: ServerConfig
}
ngOnInit () {
- this.serverConfig = this.route.snapshot.data.serverConfig
+ const snapshot = this.route.snapshot
+
+ this.serverConfig = snapshot.data.serverConfig
+
+ if (snapshot.queryParams.externalAuthToken) {
+ this.loadExternalAuthToken(snapshot.queryParams.username, snapshot.queryParams.externalAuthToken)
+ return
+ }
this.buildForm({
username: this.loginValidatorsService.LOGIN_USERNAME,
.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
- }
+ err => this.handleError(err)
)
}
hideForgotPasswordModal () {
this.openedForgotPasswordModal.close()
}
+
+ 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
+ }
+ )
+ }
+
+ private handleError (err: any) {
+ 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
+ }
}