mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Implement user requests autorizations in the client side
This commit is contained in:
parent
0c1cbbfe29
commit
1553e15d82
10 changed files with 122 additions and 33 deletions
|
@ -3,13 +3,27 @@ export class Token {
|
|||
refresh_token: string;
|
||||
token_type: string;
|
||||
|
||||
constructor (hash) {
|
||||
this.access_token = hash.access_token;
|
||||
this.refresh_token = hash.refresh_token;
|
||||
this.token_type = hash.token_type;
|
||||
constructor (hash?: any) {
|
||||
if (hash) {
|
||||
this.access_token = hash.access_token;
|
||||
this.refresh_token = hash.refresh_token;
|
||||
if (hash.token_type === 'bearer') {
|
||||
this.token_type = 'Bearer';
|
||||
} else {
|
||||
this.token_type = hash.token_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
save() {
|
||||
static load(): Token {
|
||||
return new Token({
|
||||
access_token: localStorage.getItem('access_token'),
|
||||
refresh_token: localStorage.getItem('refresh_token'),
|
||||
token_type: localStorage.getItem('token_type')
|
||||
});
|
||||
}
|
||||
|
||||
save():void {
|
||||
localStorage.setItem('access_token', this.access_token);
|
||||
localStorage.setItem('refresh_token', this.refresh_token);
|
||||
localStorage.setItem('token_type', this.token_type);
|
||||
|
|
20
client/angular/users/models/user.ts
Normal file
20
client/angular/users/models/user.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Token } from './token';
|
||||
|
||||
export class User {
|
||||
username: string;
|
||||
token: Token;
|
||||
|
||||
constructor (username: string, hash_token: any) {
|
||||
this.username = username;
|
||||
this.token = new Token(hash_token);
|
||||
}
|
||||
|
||||
static load(): User {
|
||||
return new User(localStorage.getItem('username'), Token.load());
|
||||
}
|
||||
|
||||
save(): void {
|
||||
localStorage.setItem('username', this.username);
|
||||
this.token.save();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue