aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/login/login.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-28 14:49:03 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commit4a8d113b9b57d97ff13ad1608798eabca99643e4 (patch)
tree7c6e1ba86bff31680ba6c8ba4bd903b997592269 /client/src/app/login/login.component.ts
parent98813e69bccc568eff771cfcaf907ccdd82ce3f1 (diff)
downloadPeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.gz
PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.zst
PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.zip
Begin support for external auths
Diffstat (limited to 'client/src/app/login/login.component.ts')
-rw-r--r--client/src/app/login/login.component.ts36
1 files changed, 30 insertions, 6 deletions
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts
index 580f28822..9c8f5c52e 100644
--- a/client/src/app/login/login.component.ts
+++ b/client/src/app/login/login.component.ts
@@ -22,6 +22,7 @@ export class LoginComponent extends FormReactive implements OnInit {
22 22
23 error: string = null 23 error: string = null
24 forgotPasswordEmail = '' 24 forgotPasswordEmail = ''
25 isAuthenticatedWithExternalAuth = false
25 26
26 private openedForgotPasswordModal: NgbModalRef 27 private openedForgotPasswordModal: NgbModalRef
27 private serverConfig: ServerConfig 28 private serverConfig: ServerConfig
@@ -49,7 +50,14 @@ export class LoginComponent extends FormReactive implements OnInit {
49 } 50 }
50 51
51 ngOnInit () { 52 ngOnInit () {
52 this.serverConfig = this.route.snapshot.data.serverConfig 53 const snapshot = this.route.snapshot
54
55 this.serverConfig = snapshot.data.serverConfig
56
57 if (snapshot.queryParams.externalAuthToken) {
58 this.loadExternalAuthToken(snapshot.queryParams.username, snapshot.queryParams.externalAuthToken)
59 return
60 }
53 61
54 this.buildForm({ 62 this.buildForm({
55 username: this.loginValidatorsService.LOGIN_USERNAME, 63 username: this.loginValidatorsService.LOGIN_USERNAME,
@@ -68,11 +76,7 @@ export class LoginComponent extends FormReactive implements OnInit {
68 .subscribe( 76 .subscribe(
69 () => this.redirectService.redirectToPreviousRoute(), 77 () => this.redirectService.redirectToPreviousRoute(),
70 78
71 err => { 79 err => this.handleError(err)
72 if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.')
73 else if (err.message.indexOf('blocked') !== -1) this.error = this.i18n('You account is blocked.')
74 else this.error = err.message
75 }
76 ) 80 )
77 } 81 }
78 82
@@ -99,4 +103,24 @@ export class LoginComponent extends FormReactive implements OnInit {
99 hideForgotPasswordModal () { 103 hideForgotPasswordModal () {
100 this.openedForgotPasswordModal.close() 104 this.openedForgotPasswordModal.close()
101 } 105 }
106
107 private loadExternalAuthToken (username: string, token: string) {
108 this.isAuthenticatedWithExternalAuth = true
109
110 this.authService.login(username, null, token)
111 .subscribe(
112 () => this.redirectService.redirectToPreviousRoute(),
113
114 err => {
115 this.handleError(err)
116 this.isAuthenticatedWithExternalAuth = false
117 }
118 )
119 }
120
121 private handleError (err: any) {
122 if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.')
123 else if (err.message.indexOf('blocked') !== -1) this.error = this.i18n('You account is blocked.')
124 else this.error = err.message
125 }
102} 126}