aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
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
parent98813e69bccc568eff771cfcaf907ccdd82ce3f1 (diff)
downloadPeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.gz
PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.zst
PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.zip
Begin support for external auths
Diffstat (limited to 'client')
-rw-r--r--client/src/app/core/auth/auth.service.ts4
-rw-r--r--client/src/app/core/server/server.service.ts4
-rw-r--r--client/src/app/login/login.component.html88
-rw-r--r--client/src/app/login/login.component.ts36
4 files changed, 81 insertions, 51 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 9ae008e39..61d755ba0 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -145,7 +145,7 @@ export class AuthService {
145 return !!this.getAccessToken() 145 return !!this.getAccessToken()
146 } 146 }
147 147
148 login (username: string, password: string) { 148 login (username: string, password: string, token?: string) {
149 // Form url encoded 149 // Form url encoded
150 const body = { 150 const body = {
151 client_id: this.clientId, 151 client_id: this.clientId,
@@ -157,6 +157,8 @@ export class AuthService {
157 password 157 password
158 } 158 }
159 159
160 if (token) Object.assign(body, { externalAuthToken: token })
161
160 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') 162 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
161 return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, objectToUrlEncoded(body), { headers }) 163 return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, objectToUrlEncoded(body), { headers })
162 .pipe( 164 .pipe(
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts
index da7832b32..eac8f85e4 100644
--- a/client/src/app/core/server/server.service.ts
+++ b/client/src/app/core/server/server.service.ts
@@ -54,7 +54,9 @@ export class ServerService {
54 } 54 }
55 }, 55 },
56 plugin: { 56 plugin: {
57 registered: [] 57 registered: [],
58 registeredExternalAuths: [],
59 registeredIdAndPassAuths: []
58 }, 60 },
59 theme: { 61 theme: {
60 registered: [], 62 registered: [],
diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html
index 3a2d4b876..3e53e5854 100644
--- a/client/src/app/login/login.component.html
+++ b/client/src/app/login/login.component.html
@@ -3,59 +3,61 @@
3 Login 3 Login
4 </div> 4 </div>
5 5
6 <div class="alert alert-info" *ngIf="signupAllowed === false" role="alert"> 6 <ng-container *ngIf="!isAuthenticatedWithExternalAuth">
7 <h6 class="alert-heading" i18n> 7 <div class="alert alert-info" *ngIf="signupAllowed === false" role="alert">
8 If you are looking for an account… 8 <h6 class="alert-heading" i18n>
9 </h6> 9 If you are looking for an account…
10 </h6>
10 11
11 <div i18n> 12 <div i18n>
12 Currently this instance doesn't allow for user registration, but you can find an instance 13 Currently this instance doesn't allow for user registration, but you can find an instance
13 that gives you the possibility to sign up for an account and upload your videos there. 14 that gives you the possibility to sign up for an account and upload your videos there.
14 15
15 <br /> 16 <br />
16 17
17 Find yours among multiple instances at <a class="alert-link" href="https://joinpeertube.org/instances" target="_blank" rel="noopener noreferrer">https://joinpeertube.org/instances</a>. 18 Find yours among multiple instances at <a class="alert-link" href="https://joinpeertube.org/instances" target="_blank" rel="noopener noreferrer">https://joinpeertube.org/instances</a>.
18 </div>
19 </div>
20
21 <div *ngIf="error" class="alert alert-danger">{{ error }}
22 <span *ngIf="error === 'User email is not verified.'"> <a i18n routerLink="/verify-account/ask-send-email">Request new verification email.</a></span>
23 </div>
24
25 <form role="form" (ngSubmit)="login()" [formGroup]="form">
26 <div class="form-group">
27 <div>
28 <label i18n for="username">User</label>
29 <input
30 type="text" id="username" i18n-placeholder placeholder="Username or email address" required tabindex="1"
31 formControlName="username" class="form-control" [ngClass]="{ 'input-error': formErrors['username'] }" #emailInput
32 >
33 <a i18n *ngIf="signupAllowed === true" routerLink="/signup" class="create-an-account">
34 or create an account
35 </a>
36 </div> 19 </div>
20 </div>
37 21
38 <div *ngIf="formErrors.username" class="form-error"> 22 <div *ngIf="error" class="alert alert-danger">{{ error }}
39 {{ formErrors.username }} 23 <span *ngIf="error === 'User email is not verified.'"> <a i18n routerLink="/verify-account/ask-send-email">Request new verification email.</a></span>
40 </div>
41 </div> 24 </div>
42 25
43 <div class="form-group"> 26 <form role="form" (ngSubmit)="login()" [formGroup]="form">
44 <label i18n for="password">Password</label> 27 <div class="form-group">
45 <div> 28 <div>
46 <input 29 <label i18n for="username">User</label>
47 type="password" name="password" id="password" i18n-placeholder placeholder="Password" required tabindex="2" autocomplete="current-password" 30 <input
48 formControlName="password" class="form-control" [ngClass]="{ 'input-error': formErrors['password'] }" 31 type="text" id="username" i18n-placeholder placeholder="Username or email address" required tabindex="1"
49 > 32 formControlName="username" class="form-control" [ngClass]="{ 'input-error': formErrors['username'] }" #emailInput
50 <a i18n-title class="forgot-password-button" (click)="openForgotPasswordModal()" title="Click here to reset your password">I forgot my password</a> 33 >
34 <a i18n *ngIf="signupAllowed === true" routerLink="/signup" class="create-an-account">
35 or create an account
36 </a>
37 </div>
38
39 <div *ngIf="formErrors.username" class="form-error">
40 {{ formErrors.username }}
41 </div>
51 </div> 42 </div>
52 <div *ngIf="formErrors.password" class="form-error"> 43
53 {{ formErrors.password }} 44 <div class="form-group">
45 <label i18n for="password">Password</label>
46 <div>
47 <input
48 type="password" name="password" id="password" i18n-placeholder placeholder="Password" required tabindex="2" autocomplete="current-password"
49 formControlName="password" class="form-control" [ngClass]="{ 'input-error': formErrors['password'] }"
50 >
51 <a i18n-title class="forgot-password-button" (click)="openForgotPasswordModal()" title="Click here to reset your password">I forgot my password</a>
52 </div>
53 <div *ngIf="formErrors.password" class="form-error">
54 {{ formErrors.password }}
55 </div>
54 </div> 56 </div>
55 </div>
56 57
57 <input type="submit" i18n-value value="Login" [disabled]="!form.valid"> 58 <input type="submit" i18n-value value="Login" [disabled]="!form.valid">
58 </form> 59 </form>
60 </ng-container>
59</div> 61</div>
60 62
61<ng-template #forgotPasswordModal> 63<ng-template #forgotPasswordModal>
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}