From 8d2be0ed7bb87283a1ec98609df6b82d83db706a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jul 2019 17:23:24 +0200 Subject: WIP plugins: move plugin CLI in peertube script Install/uninstall/list plugins remotely --- shared/extra-utils/users/login.ts | 19 +++++++++++++++++++ shared/extra-utils/users/users.ts | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'shared/extra-utils/users') 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 @@ import * as request from 'supertest' import { ServerInfo } from '../server/servers' +import { getClient } from '../server/clients' type Client = { id: string, secret: string } type User = { username: string, password: string } @@ -38,6 +39,23 @@ async function userLogin (server: Server, user: User, expectedStatus = 200) { return res.body.access_token as string } +async function getAccessToken (url: string, username: string, password: string) { + const resClient = await getClient(url) + const client = { + id: resClient.body.client_id, + secret: resClient.body.client_secret + } + + const user = { username, password } + + try { + const res = await login(url, client, user) + return res.body.access_token + } catch (err) { + throw new Error('Cannot authenticate. Please check your username/password.') + } +} + function setAccessTokensToServers (servers: ServerInfo[]) { const tasks: Promise[] = [] @@ -55,6 +73,7 @@ export { login, serverLogin, userLogin, + getAccessToken, setAccessTokensToServers, Server, 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 @@ import * as request from 'supertest' -import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' - -import { UserCreate, UserRole } from '../../index' +import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' -import { ServerInfo, userLogin } from '..' import { UserAdminFlag } from '../../models/users/user-flag.model' import { UserRegister } from '../../models/users/user-register.model' +import { UserRole } from '../../models/users/user-role' +import { ServerInfo } from '../server/servers' +import { userLogin } from './login' type CreateUserArgs = { url: string, accessToken: string, -- cgit v1.2.3