UNPKG

stackpress

Version:

Incept is a content management framework.

64 lines (63 loc) 4.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Head = void 0; exports.ApiOauthForm = ApiOauthForm; exports.OAuthBody = OAuthBody; exports.ApiOauthHead = ApiOauthHead; exports.ApiOauthPage = ApiOauthPage; const jsx_runtime_1 = require("react/jsx-runtime"); const r22n_1 = require("r22n"); const Button_1 = __importDefault(require("frui/form/Button")); const Switch_1 = __importDefault(require("frui/field/Switch")); const LayoutBlank_js_1 = __importDefault(require("../../view/layout/LayoutBlank.js")); const hooks_js_1 = require("../../view/server/hooks.js"); function ApiOauthForm(props) { const { appName, revert, items } = props; const { _ } = (0, r22n_1.useLanguage)(); return ((0, jsx_runtime_1.jsxs)("form", { className: "oauth-form auth-form", method: "post", children: [items.length > 0 ? ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { className: "instructions", children: _('Grant the following permissions:') }), items.map((item, index) => ((0, jsx_runtime_1.jsxs)("div", { className: "scope", children: [(0, jsx_runtime_1.jsxs)("div", { className: "container", children: [(0, jsx_runtime_1.jsxs)("span", { children: [item.icon ? ((0, jsx_runtime_1.jsx)("i", { className: `fas fa-fw fa-${item.icon}` })) : null, item.name] }), !!item.description ? ((0, jsx_runtime_1.jsx)("p", { children: item.description })) : null] }), (0, jsx_runtime_1.jsx)(Switch_1.default, { name: "scopes[]", value: item.id })] }, index)))] })) : ((0, jsx_runtime_1.jsx)("p", { className: "instructions", children: _('%s is asking permissions to access your personal information.', appName) })), (0, jsx_runtime_1.jsxs)("div", { className: "action", children: [(0, jsx_runtime_1.jsx)(Button_1.default, { className: "submit", type: "submit", children: _('Grant') }), (0, jsx_runtime_1.jsx)("a", { className: "deny", href: revert, children: _('Deny') })] })] })); } function OAuthBody() { const { config, request, response } = (0, hooks_js_1.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 === null || application === void 0 ? void 0 : 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 { _ } = (0, r22n_1.useLanguage)(); return ((0, jsx_runtime_1.jsx)("main", { className: "oauth-page auth-page", children: (0, jsx_runtime_1.jsxs)("div", { className: "container", children: [config.has('brand', 'logo') ? ((0, jsx_runtime_1.jsx)("img", { height: "50", alt: config.path('brand.name'), src: config.path('brand.logo'), className: "logo" })) : ((0, jsx_runtime_1.jsx)("h2", { className: "brand", children: config.path('brand.name') })), (0, jsx_runtime_1.jsxs)("section", { className: "theme-bg-bg1 theme-bc-bd3 border px-w-360", children: [(0, jsx_runtime_1.jsxs)("header", { children: [(0, jsx_runtime_1.jsx)("i", { className: "fas fa-fw fa-user" }), (0, jsx_runtime_1.jsx)("h3", { className: "label", children: _('Sign Up') })] }), (0, jsx_runtime_1.jsx)(ApiOauthForm, { appName: appName, revert: revert, items: items })] })] }) })); } function ApiOauthHead(props) { const { data, styles = [] } = props; const { favicon = '/favicon.ico' } = (data === null || data === void 0 ? void 0 : data.brand) || {}; const { _ } = (0, r22n_1.useLanguage)(); const mimetype = favicon.endsWith('.png') ? 'image/png' : favicon.endsWith('.svg') ? 'image/svg+xml' : 'image/x-icon'; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("title", { children: _('Grant Access') }), favicon && (0, jsx_runtime_1.jsx)("link", { rel: "icon", type: mimetype, href: favicon }), (0, jsx_runtime_1.jsx)("link", { rel: "stylesheet", type: "text/css", href: "/styles/global.css" }), styles.map((href, index) => ((0, jsx_runtime_1.jsx)("link", { rel: "stylesheet", type: "text/css", href: href }, index)))] })); } function ApiOauthPage(props) { return ((0, jsx_runtime_1.jsx)(LayoutBlank_js_1.default, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(OAuthBody, {}) }))); } exports.Head = ApiOauthHead; exports.default = ApiOauthPage;