From 3741b37ff4bf36fd0cb7f26940b2f1736c9b6136 Mon Sep 17 00:00:00 2001 From: ansible user/allowed to read system logs Date: Wed, 26 Jul 2023 21:04:50 -0700 Subject: [PATCH] working on slack login --- client/package.json | 2 +- client/src/components/groups/groupPanel.tsx | 1 + client/src/components/join/joinForm.tsx | 25 +++++++ client/src/components/join/joinPlatform.tsx | 44 +++++++++++++ client/src/components/panels/joinPanel.tsx | 72 ++++++++++++++++++++- client/src/components/panels/joinSlack.tsx | 7 ++ client/src/sass/index.scss | 1 + client/src/sass/typography.scss | 17 +++++ client/src/sass/variables.scss | 5 +- client/src/types/group.tsx | 8 +++ server/src/app.ts | 8 +-- server/src/controllers/group.controller.ts | 24 +++++++ server/src/controllers/slack.controller.ts | 24 +++++++ server/src/matterbridge/config.ts | 1 - server/src/routes/group.routes.ts | 7 +- 15 files changed, 237 insertions(+), 9 deletions(-) create mode 100644 client/src/components/join/joinForm.tsx create mode 100644 client/src/components/join/joinPlatform.tsx create mode 100644 client/src/components/panels/joinSlack.tsx create mode 100644 client/src/sass/typography.scss create mode 100644 client/src/types/group.tsx diff --git a/client/package.json b/client/package.json index ec3e989..4212c53 100644 --- a/client/package.json +++ b/client/package.json @@ -19,7 +19,7 @@ "web-vitals": "^2.1.4" }, "scripts": { - "start": "NODE_ENV=development webpack -c ./config/webpack.dev.js --mode development", + "start": "NODE_ENV=development webpack serve -c ./config/webpack.dev.js --mode development", "build": "NODE_ENV=production webpack --config ./config/webpack.prod.js", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/client/src/components/groups/groupPanel.tsx b/client/src/components/groups/groupPanel.tsx index c13230a..0a9cecd 100644 --- a/client/src/components/groups/groupPanel.tsx +++ b/client/src/components/groups/groupPanel.tsx @@ -29,6 +29,7 @@ export default function GroupPanel({ {groups ? groups.map((group) => ( { + const [platform, setPlatform] = useState(); + + return ( + <> +
+ Joining group: {group.name} +
+ + + ) +} \ No newline at end of file diff --git a/client/src/components/join/joinPlatform.tsx b/client/src/components/join/joinPlatform.tsx new file mode 100644 index 0000000..90d04b6 --- /dev/null +++ b/client/src/components/join/joinPlatform.tsx @@ -0,0 +1,44 @@ +/* +Select which platform you're joining from! + */ + +import React, {useState} from 'react'; +import Box from '@mui/material/Box'; +import InputLabel from '@mui/material/InputLabel'; +import MenuItem from '@mui/material/MenuItem'; +import FormControl from '@mui/material/FormControl'; +import Select from '@mui/material/Select'; + +import {JoinSlack} from "../panels/joinSlack"; + +const PLATFORMS = { + 'Slack': JoinSlack +} + +export const JoinPlatform = ({ + platformSetter + }) => { + const [platform, setPlatform] = useState() + + const handleSelect = (event) => { + setPlatform(event.target.value); + platformSetter(event.target.value); + } + + return( +
+ + Select Platform + + + +
+ ) +} \ No newline at end of file diff --git a/client/src/components/panels/joinPanel.tsx b/client/src/components/panels/joinPanel.tsx index 14d438e..9c6bdef 100644 --- a/client/src/components/panels/joinPanel.tsx +++ b/client/src/components/panels/joinPanel.tsx @@ -1,9 +1,79 @@ +import React from 'react'; +import {useState, useEffect} from "react"; +import TextField from '@mui/material/TextField'; +import Button from '@mui/material/Button'; +import {JoinForm} from "../join/joinForm"; +import {Group} from "../../types/group"; export default function JoinPanel(){ + const [text, setText] = useState(''); + const [authError, setAuthError] = useState(false); + const [errorText, setErrorText] = useState(''); + const [group, setGroup] = useState(undefined); + + const getGroup = () => { + fetch('api/groups/invite', { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + token: text + }) + }) + .then(result => result.json()) + .then( + response => { + if (response.status !== "success"){ + setAuthError(true); + setErrorText(response.message); + setGroup(undefined); + } else if (response.status === "success"){ + setAuthError(false); + setErrorText(''); + setGroup(response.data) + console.log(response) + } + + } + ) + } + + const handleClick = () => { + getGroup() + } + + const textChanged = (event: React.ChangeEvent) => { + setText(event.target.value) + } return(
- +
+ + +
+ { group ? + : undefined + }
) } \ No newline at end of file diff --git a/client/src/components/panels/joinSlack.tsx b/client/src/components/panels/joinSlack.tsx new file mode 100644 index 0000000..e9ba57f --- /dev/null +++ b/client/src/components/panels/joinSlack.tsx @@ -0,0 +1,7 @@ + + +export const JoinSlack = () => { + return( + <> + ) +} \ No newline at end of file diff --git a/client/src/sass/index.scss b/client/src/sass/index.scss index d766cdb..1ed96c0 100644 --- a/client/src/sass/index.scss +++ b/client/src/sass/index.scss @@ -3,5 +3,6 @@ @import './variables.scss'; @import './base.scss'; @import './App.scss'; +@import './typography.scss'; @import './tabs.scss'; @import './input.scss'; \ No newline at end of file diff --git a/client/src/sass/typography.scss b/client/src/sass/typography.scss new file mode 100644 index 0000000..4f4a696 --- /dev/null +++ b/client/src/sass/typography.scss @@ -0,0 +1,17 @@ +.section-header { + color: $color-text; + font-size: 2rem; + margin: { + top: 1rem; + } +} + +code { + font: { + family: 'Courier', 'Courier New', monospace; + } + background-color: $color-primary-background; + padding: 0 0.2em; + border-radius: 0.1em; + border: 1px solid $color-primary-border; +} \ No newline at end of file diff --git a/client/src/sass/variables.scss b/client/src/sass/variables.scss index 53cc0bf..aa5d3e8 100644 --- a/client/src/sass/variables.scss +++ b/client/src/sass/variables.scss @@ -1,4 +1,7 @@ $color-primary: #DED03A; $color-primary-darker: scale-color($color-primary, $lightness: -10%); +$color-primary-background: adjust-color($color-primary, $alpha: -0.9, $saturation: -50%); +$color-primary-border: adjust-color($color-primary, $alpha: -0.9, $lightness: 50%, $saturation: -50%); $color-secondary: #A167A5; -$color-background: #1C1B22; \ No newline at end of file +$color-background: #1C1B22; +$color-text: white; \ No newline at end of file diff --git a/client/src/types/group.tsx b/client/src/types/group.tsx new file mode 100644 index 0000000..e19950a --- /dev/null +++ b/client/src/types/group.tsx @@ -0,0 +1,8 @@ +export interface Group { + created_at: string; + enable: boolean; + id: string; + invite_token: string; + name: string; + updated_at: string; +} \ No newline at end of file diff --git a/server/src/app.ts b/server/src/app.ts index d6073f0..0aedfe3 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -50,9 +50,9 @@ AppDataSource.initialize() console.log(`Server started on port: ${port}`) - await MatterbridgeManager.spawnAll(); - console.log('Spawned group processes:'); - let proclist = await MatterbridgeManager.processes; - console.log(proclist); + // await MatterbridgeManager.spawnAll(); + // console.log('Spawned group processes:'); + // let proclist = await MatterbridgeManager.processes; + // console.log(proclist); }) diff --git a/server/src/controllers/group.controller.ts b/server/src/controllers/group.controller.ts index 99ac368..58b0654 100644 --- a/server/src/controllers/group.controller.ts +++ b/server/src/controllers/group.controller.ts @@ -73,6 +73,30 @@ export const getGroupHandler = async( } }; +export const getGroupWithInviteHandler = async( + req: Request, + res:Response, + next: NextFunction +) => { + let group = await groupRepository.findOneBy({invite_token: req.body.token}) + if (!group) { + return res.status(404).json({ + status: 'failed', + message: `No group with matching invite code exists.` + }) + } else { + req.session.groups = req.session.groups || []; + if (!req.session.groups.includes(req.body.token)) { + req.session.groups.push(req.body.token); + } + return res.status(200).json({ + status: 'success', + data: group + }) + } + +} + export const getGroupsHandler = async( req: Request, res: Response diff --git a/server/src/controllers/slack.controller.ts b/server/src/controllers/slack.controller.ts index 9110384..cef9019 100644 --- a/server/src/controllers/slack.controller.ts +++ b/server/src/controllers/slack.controller.ts @@ -5,6 +5,7 @@ import {AppDataSource} from "../db/data-source"; import {Bridge} from "../entities/bridge.entity"; import {Group} from "../entities/group.entity"; import { randomUUID } from "crypto"; +import {log} from "util"; const scopes = ['bot', 'channels:write', 'chat:write:bot', 'chat:write:user', 'users.profile:read']; const bridgeRepository = AppDataSource.getRepository(Bridge) @@ -40,6 +41,29 @@ export const SlackInstallHandler = async( }); } +export const SlackInstallLinkHandler = async( + req: Request, + res: Response +) => { + let login_token = randomUUID() + + const url = await installer.generateInstallUrl({ + scopes, + metadata: {token: login_token, group: req.query.group} + }); + + res.status(200).json({ + status: 'success', + data: { + url, + login_token + } + }) + +} + + + export const SlackCallbackHandler = async( req: Request, diff --git a/server/src/matterbridge/config.ts b/server/src/matterbridge/config.ts index 231f58c..33db295 100644 --- a/server/src/matterbridge/config.ts +++ b/server/src/matterbridge/config.ts @@ -153,7 +153,6 @@ export const GatewayToTOML = (gateway: Gateway) => { protocols[bridge.protocol][bridge.name] = TOML.Section(bridgeEntry) }) - console.log('protocols', protocols) return { ...protocols, diff --git a/server/src/routes/group.routes.ts b/server/src/routes/group.routes.ts index 0b03476..22f686f 100644 --- a/server/src/routes/group.routes.ts +++ b/server/src/routes/group.routes.ts @@ -2,7 +2,8 @@ import express from 'express'; import { createGroupHandler, - getGroupHandler + getGroupHandler, + getGroupWithInviteHandler } from "../controllers/group.controller"; import { @@ -19,4 +20,8 @@ router .post(validate(createGroupSchema), requireAdmin, createGroupHandler) .get(requireAdmin, getGroupHandler) +router + .route('/invite') + .post(getGroupWithInviteHandler) + export default router