diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 17:23:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch) | |
tree | 31a36b252df32be83ceb77658a53b57f9d15e8ac /shared/extra-utils/users | |
parent | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff) | |
download | PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip |
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r-- | shared/extra-utils/users/login.ts | 19 | ||||
-rw-r--r-- | shared/extra-utils/users/users.ts | 8 |
2 files changed, 23 insertions, 4 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index ddeb9df2a..f9bfb3cb3 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | 2 | ||
3 | import { ServerInfo } from '../server/servers' | 3 | import { ServerInfo } from '../server/servers' |
4 | import { getClient } from '../server/clients' | ||
4 | 5 | ||
5 | type Client = { id: string, secret: string } | 6 | type Client = { id: string, secret: string } |
6 | type User = { username: string, password: string } | 7 | type User = { username: string, password: string } |
@@ -38,6 +39,23 @@ async function userLogin (server: Server, user: User, expectedStatus = 200) { | |||
38 | return res.body.access_token as string | 39 | return res.body.access_token as string |
39 | } | 40 | } |
40 | 41 | ||
42 | async function getAccessToken (url: string, username: string, password: string) { | ||
43 | const resClient = await getClient(url) | ||
44 | const client = { | ||
45 | id: resClient.body.client_id, | ||
46 | secret: resClient.body.client_secret | ||
47 | } | ||
48 | |||
49 | const user = { username, password } | ||
50 | |||
51 | try { | ||
52 | const res = await login(url, client, user) | ||
53 | return res.body.access_token | ||
54 | } catch (err) { | ||
55 | throw new Error('Cannot authenticate. Please check your username/password.') | ||
56 | } | ||
57 | } | ||
58 | |||
41 | function setAccessTokensToServers (servers: ServerInfo[]) { | 59 | function setAccessTokensToServers (servers: ServerInfo[]) { |
42 | const tasks: Promise<any>[] = [] | 60 | const tasks: Promise<any>[] = [] |
43 | 61 | ||
@@ -55,6 +73,7 @@ export { | |||
55 | login, | 73 | login, |
56 | serverLogin, | 74 | serverLogin, |
57 | userLogin, | 75 | userLogin, |
76 | getAccessToken, | ||
58 | setAccessTokensToServers, | 77 | setAccessTokensToServers, |
59 | Server, | 78 | Server, |
60 | Client, | 79 | Client, |
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index 1c39881d6..5fa8cde0c 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' | 2 | import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' |
3 | |||
4 | import { UserCreate, UserRole } from '../../index' | ||
5 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' | 3 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' |
6 | import { ServerInfo, userLogin } from '..' | ||
7 | import { UserAdminFlag } from '../../models/users/user-flag.model' | 4 | import { UserAdminFlag } from '../../models/users/user-flag.model' |
8 | import { UserRegister } from '../../models/users/user-register.model' | 5 | import { UserRegister } from '../../models/users/user-register.model' |
6 | import { UserRole } from '../../models/users/user-role' | ||
7 | import { ServerInfo } from '../server/servers' | ||
8 | import { userLogin } from './login' | ||
9 | 9 | ||
10 | type CreateUserArgs = { url: string, | 10 | type CreateUserArgs = { url: string, |
11 | accessToken: string, | 11 | accessToken: string, |