mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
Show login-buttons and boxes only if providers are configured (#122)
* Hide "Sign-in via ..." box if no provider is enabled * Show sign-in buttons only if auth-providers exist * Rebase fixes * Replaced ternary operators with ShowIf * Added ShowIf on two other code positions
This commit is contained in:
parent
2b4c3c76ba
commit
b051b109e5
3 changed files with 58 additions and 47 deletions
|
@ -2,7 +2,10 @@ import React from 'react'
|
||||||
import { Button } from 'react-bootstrap'
|
import { Button } from 'react-bootstrap'
|
||||||
import { ButtonProps } from 'react-bootstrap/Button'
|
import { ButtonProps } from 'react-bootstrap/Button'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
import { LinkContainer } from 'react-router-bootstrap'
|
import { LinkContainer } from 'react-router-bootstrap'
|
||||||
|
import { ApplicationState } from '../../../../redux'
|
||||||
|
import { ShowIf } from '../../../common/show-if'
|
||||||
|
|
||||||
type SignInButtonProps = {
|
type SignInButtonProps = {
|
||||||
className?: string
|
className?: string
|
||||||
|
@ -10,15 +13,17 @@ type SignInButtonProps = {
|
||||||
|
|
||||||
export const SignInButton: React.FC<SignInButtonProps> = ({ variant, ...props }) => {
|
export const SignInButton: React.FC<SignInButtonProps> = ({ variant, ...props }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const authProviders = useSelector((state: ApplicationState) => state.backendConfig.authProviders)
|
||||||
return (
|
return (
|
||||||
<LinkContainer to="/login" title={t('login.signIn')}>
|
<ShowIf condition={Object.values(authProviders).includes(true)}>
|
||||||
<Button
|
<LinkContainer to="/login" title={t('login.signIn')}>
|
||||||
variant={variant || 'success'}
|
<Button
|
||||||
{...props}
|
variant={variant || 'success'}
|
||||||
>
|
{...props}
|
||||||
<Trans i18nKey="login.signIn"/>
|
>
|
||||||
</Button>
|
<Trans i18nKey="login.signIn"/>
|
||||||
</LinkContainer>
|
</Button>
|
||||||
|
</LinkContainer>
|
||||||
|
</ShowIf>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,14 @@ import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { ApplicationState } from '../../../../../redux'
|
import { ApplicationState } from '../../../../../redux'
|
||||||
|
import { ShowIf } from '../../../../common/show-if'
|
||||||
import { SignInButton } from '../../../layout/navigation/sign-in-button'
|
import { SignInButton } from '../../../layout/navigation/sign-in-button'
|
||||||
import './cover-buttons.scss'
|
import './cover-buttons.scss'
|
||||||
|
|
||||||
export const CoverButtons: React.FC = () => {
|
export const CoverButtons: React.FC = () => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
const user = useSelector((state: ApplicationState) => state.user)
|
const user = useSelector((state: ApplicationState) => state.user)
|
||||||
|
const authProviders = useSelector((state: ApplicationState) => state.backendConfig.authProviders)
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
return null
|
return null
|
||||||
|
@ -22,11 +24,11 @@ export const CoverButtons: React.FC = () => {
|
||||||
variant="success"
|
variant="success"
|
||||||
size="lg"
|
size="lg"
|
||||||
/>
|
/>
|
||||||
|
<ShowIf condition={Object.values(authProviders).includes(true)}>
|
||||||
<span className="m-2">
|
<span className="m-2">
|
||||||
<Trans i18nKey="common.or"/>
|
<Trans i18nKey="common.or"/>
|
||||||
</span>
|
</span>
|
||||||
|
</ShowIf>
|
||||||
<Link to="/features">
|
<Link to="/features">
|
||||||
<Button
|
<Button
|
||||||
className="cover-button"
|
className="cover-button"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { Redirect } from 'react-router'
|
import { Redirect } from 'react-router'
|
||||||
import { ApplicationState } from '../../../../redux'
|
import { ApplicationState } from '../../../../redux'
|
||||||
|
import { ShowIf } from '../../../common/show-if'
|
||||||
import { ViaEMail } from './auth/via-email'
|
import { ViaEMail } from './auth/via-email'
|
||||||
import { ViaLdap } from './auth/via-ldap'
|
import { ViaLdap } from './auth/via-ldap'
|
||||||
import { OneClickType, ViaOneClick } from './auth/via-one-click'
|
import { OneClickType, ViaOneClick } from './auth/via-one-click'
|
||||||
|
@ -18,6 +19,9 @@ export const Login: React.FC = () => {
|
||||||
const ldapForm = authProviders.ldap ? <ViaLdap/> : null
|
const ldapForm = authProviders.ldap ? <ViaLdap/> : null
|
||||||
const openIdForm = authProviders.openid ? <ViaOpenId/> : null
|
const openIdForm = authProviders.openid ? <ViaOpenId/> : null
|
||||||
|
|
||||||
|
const oneClickProviders = [authProviders.dropbox, authProviders.facebook, authProviders.github, authProviders.gitlab,
|
||||||
|
authProviders.google, authProviders.oauth2, authProviders.saml, authProviders.twitter]
|
||||||
|
|
||||||
const oneClickCustomName: (type: OneClickType) => string | undefined = (type) => {
|
const oneClickCustomName: (type: OneClickType) => string | undefined = (type) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OneClickType.SAML:
|
case OneClickType.SAML:
|
||||||
|
@ -39,39 +43,39 @@ export const Login: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<div className="my-3">
|
<div className="my-3">
|
||||||
<Row className="h-100 flex justify-content-center">
|
<Row className="h-100 flex justify-content-center">
|
||||||
{
|
<ShowIf condition={authProviders.email || authProviders.ldap || authProviders.openid}>
|
||||||
authProviders.email || authProviders.ldap || authProviders.openid
|
<Col xs={12} sm={10} lg={4}>
|
||||||
? <Col xs={12} sm={10} lg={4}>
|
{emailForm}
|
||||||
{emailForm}
|
{ldapForm}
|
||||||
{ldapForm}
|
{openIdForm}
|
||||||
{openIdForm}
|
</Col>
|
||||||
</Col>
|
</ShowIf>
|
||||||
: null
|
<ShowIf condition={oneClickProviders.includes(true)}>
|
||||||
}
|
<Col xs={12} sm={10} lg={4}>
|
||||||
<Col xs={12} sm={10} lg={4}>
|
<Card className="bg-dark mb-4">
|
||||||
<Card className="bg-dark mb-4">
|
<Card.Body>
|
||||||
<Card.Body>
|
<Card.Title>
|
||||||
<Card.Title>
|
<Trans i18nKey="login.signInVia" values={{ service: '' }}/>
|
||||||
<Trans i18nKey="login.signInVia" values={{ service: '' }}/>
|
</Card.Title>
|
||||||
</Card.Title>
|
{
|
||||||
{
|
Object.values(OneClickType)
|
||||||
Object.values(OneClickType)
|
.filter((value) => authProviders[value])
|
||||||
.filter((value) => authProviders[value])
|
.map((value) => (
|
||||||
.map((value) => (
|
<div
|
||||||
<div
|
className="p-2 d-flex flex-column social-button-container"
|
||||||
className="p-2 d-flex flex-column social-button-container"
|
key={value}
|
||||||
key={value}
|
>
|
||||||
>
|
<ViaOneClick
|
||||||
<ViaOneClick
|
oneClickType={value}
|
||||||
oneClickType={value}
|
optionalName={oneClickCustomName(value)}
|
||||||
optionalName={oneClickCustomName(value)}
|
/>
|
||||||
/>
|
</div>
|
||||||
</div>
|
))
|
||||||
))
|
}
|
||||||
}
|
</Card.Body>
|
||||||
</Card.Body>
|
</Card>
|
||||||
</Card>
|
</Col>
|
||||||
</Col>
|
</ShowIf>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue