UNPKG

stackpress

Version:

Incept is a content management framework.

54 lines (53 loc) 3.83 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useLanguage } from 'r22n'; import Button from 'frui/form/Button'; import Switch from 'frui/field/Switch'; import LayoutBlank from '../../view/layout/LayoutBlank.js'; import { useServer } from '../../view/server/hooks.js'; export function ApiOauthForm(props) { const { appName, revert, items } = props; const { _ } = useLanguage(); return (_jsxs("form", { className: "oauth-form auth-form", method: "post", children: [items.length > 0 ? (_jsxs("div", { children: [_jsx("p", { className: "instructions", children: _('Grant the following permissions:') }), items.map((item, index) => (_jsxs("div", { className: "scope", children: [_jsxs("div", { className: "container", children: [_jsxs("span", { children: [item.icon ? (_jsx("i", { className: `fas fa-fw fa-${item.icon}` })) : null, item.name] }), !!item.description ? (_jsx("p", { children: item.description })) : null] }), _jsx(Switch, { name: "scopes[]", value: item.id })] }, index)))] })) : (_jsx("p", { className: "instructions", children: _('%s is asking permissions to access your personal information.', appName) })), _jsxs("div", { className: "action", children: [_jsx(Button, { className: "submit", type: "submit", children: _('Grant') }), _jsx("a", { className: "deny", href: revert, children: _('Deny') })] })] })); } export function OAuthBody() { const { config, request, response } = useServer(); const redirect = request.data.path('redirect_uri', '/'); const [uri, query] = redirect.split('?'); const params = new URLSearchParams(query); params.set('error', 'denied'); const revert = `${uri}?${params.toString()}`; const scope = request.data.path('scope', ''); const scopes = config.path('api.scopes', {}); const permissions = scope ? scope.split(' ') : []; const application = response.results; const appName = application?.name || 'Unknown'; const items = permissions.map(name => { const scope = scopes[name]; if (!scope) return false; return { id: name, icon: scope.icon, name: scope.name, description: scope.description }; }).filter(Boolean); const { _ } = useLanguage(); return (_jsx("main", { className: "oauth-page auth-page", children: _jsxs("div", { className: "container", children: [config.has('brand', 'logo') ? (_jsx("img", { height: "50", alt: config.path('brand.name'), src: config.path('brand.logo'), className: "logo" })) : (_jsx("h2", { className: "brand", children: config.path('brand.name') })), _jsxs("section", { className: "theme-bg-bg1 theme-bc-bd3 border px-w-360", children: [_jsxs("header", { children: [_jsx("i", { className: "fas fa-fw fa-user" }), _jsx("h3", { className: "label", children: _('Sign Up') })] }), _jsx(ApiOauthForm, { appName: appName, revert: revert, items: items })] })] }) })); } export function ApiOauthHead(props) { const { data, styles = [] } = props; const { favicon = '/favicon.ico' } = data?.brand || {}; const { _ } = useLanguage(); const mimetype = favicon.endsWith('.png') ? 'image/png' : favicon.endsWith('.svg') ? 'image/svg+xml' : 'image/x-icon'; return (_jsxs(_Fragment, { children: [_jsx("title", { children: _('Grant Access') }), favicon && _jsx("link", { rel: "icon", type: mimetype, href: favicon }), _jsx("link", { rel: "stylesheet", type: "text/css", href: "/styles/global.css" }), styles.map((href, index) => (_jsx("link", { rel: "stylesheet", type: "text/css", href: href }, index)))] })); } export function ApiOauthPage(props) { return (_jsx(LayoutBlank, { ...props, children: _jsx(OAuthBody, {}) })); } export const Head = ApiOauthHead; export default ApiOauthPage;