[Glitch] Add direct link to the Single-Sign On provider if there is only one sign up method available (#26083)

Port 120f5802c0 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
main-unfiltered
CSDUMMI 2023-08-03 16:43:15 +02:00 committed by Claire
parent 1461cc53ed
commit 64fc66d3db
4 changed files with 74 additions and 31 deletions

View File

@ -13,7 +13,7 @@ import { openModal, closeModal } from 'flavours/glitch/actions/modal';
import api from 'flavours/glitch/api'; import api from 'flavours/glitch/api';
import Button from 'flavours/glitch/components/button'; import Button from 'flavours/glitch/components/button';
import { Icon } from 'flavours/glitch/components/icon'; import { Icon } from 'flavours/glitch/components/icon';
import { registrationsOpen } from 'flavours/glitch/initial_state'; import { registrationsOpen, sso_redirect } from 'flavours/glitch/initial_state';
const messages = defineMessages({ const messages = defineMessages({
loginPrompt: { id: 'interaction_modal.login.prompt', defaultMessage: 'Domain of your home server, e.g. mastodon.social' }, loginPrompt: { id: 'interaction_modal.login.prompt', defaultMessage: 'Domain of your home server, e.g. mastodon.social' },
@ -331,18 +331,36 @@ class InteractionModal extends React.PureComponent {
} }
let signupButton; let signupButton;
let signUpOrSignInButton;
if (registrationsOpen) { if (sso_redirect) {
signupButton = ( signUpOrSignInButton = (
<a href='/auth/sign_up' className='link-button'> <a href={sso_redirect} data-method='post' className='button button--block button-tertiary'>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /> <FormattedMessage id='sign_in_banner.sso_redirect' defaultMessage='Login or Register' />
</a> </a>
); )
} else { } else {
signupButton = ( if(registrationsOpen) {
<button className='link-button' onClick={this.handleSignupClick}> signupButton = (
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /> <a href='/auth/sign_up' className='link-button'>
</button> <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</a>
);
} else {
signupButton = (
<button className='button button--block button-tertiary' onClick={this.handleSignupClick}>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</button>
);
}
signUpOrSignInButton = (
<>
<a href='/auth/sign_in' className='button button--block'>
<FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Login' />
</a>
{signupButton}
</>
); );
} }
@ -353,6 +371,13 @@ class InteractionModal extends React.PureComponent {
<p>{actionDescription} <strong><FormattedMessage id='interaction_modal.sign_in' defaultMessage='You are not logged in to this server. Where is your account hosted?' /></strong></p> <p>{actionDescription} <strong><FormattedMessage id='interaction_modal.sign_in' defaultMessage='You are not logged in to this server. Where is your account hosted?' /></strong></p>
</div> </div>
<div className='interaction-modal__choices'>
<div className='interaction-modal__choices__choice'>
<h3><FormattedMessage id='interaction_modal.on_this_server' defaultMessage='On this server' /></h3>
{signUpOrSignInButton}
</div>
</div>
<IntlLoginForm resourceUrl={url} /> <IntlLoginForm resourceUrl={url} />
<p className='hint'><FormattedMessage id='interaction_modal.sign_in_hint' defaultMessage="Tip: That's the website where you signed up. If you don't remember, look for the welcome e-mail in your inbox. You can also enter your full username! (e.g. @Mastodon@mastodon.social)" /></p> <p className='hint'><FormattedMessage id='interaction_modal.sign_in_hint' defaultMessage="Tip: That's the website where you signed up. If you don't remember, look for the welcome e-mail in your inbox. You can also enter your full username! (e.g. @Mastodon@mastodon.social)" /></p>

View File

@ -13,7 +13,7 @@ import { Avatar } from 'flavours/glitch/components/avatar';
import { Icon } from 'flavours/glitch/components/icon'; import { Icon } from 'flavours/glitch/components/icon';
import { WordmarkLogo, SymbolLogo } from 'flavours/glitch/components/logo'; import { WordmarkLogo, SymbolLogo } from 'flavours/glitch/components/logo';
import Permalink from 'flavours/glitch/components/permalink'; import Permalink from 'flavours/glitch/components/permalink';
import { registrationsOpen, me } from 'flavours/glitch/initial_state'; import { registrationsOpen, me, sso_redirect } from 'flavours/glitch/initial_state';
const Account = connect(state => ({ const Account = connect(state => ({
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
@ -74,28 +74,35 @@ class Header extends PureComponent {
</> </>
); );
} else { } else {
let signupButton;
if (registrationsOpen) { if (sso_redirect) {
signupButton = ( content = (
<a href={signupUrl} className='button'> <a href={sso_redirect} data-method='post' className='button button--block button-tertiary'><FormattedMessage id='sign_in_banner.sso_redirect' defaultMessage='Login or Register' /></a>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /> )
</a>
);
} else { } else {
signupButton = ( let signupButton;
<button className='button' onClick={openClosedRegistrationsModal}>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /> if (registrationsOpen) {
</button> signupButton = (
<a href={signupUrl} className='button'>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</a>
);
} else {
signupButton = (
<button className='button' onClick={openClosedRegistrationsModal}>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</button>
);
}
content = (
<>
{signupButton}
<a href='/auth/sign_in' className='button button-tertiary'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Login' /></a>
</>
); );
} }
content = (
<>
{signupButton}
<a href='/auth/sign_in' className='button button-tertiary'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Login' /></a>
</>
);
} }
return ( return (

View File

@ -3,7 +3,7 @@ import { useCallback } from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { openModal } from 'flavours/glitch/actions/modal'; import { openModal } from 'flavours/glitch/actions/modal';
import { registrationsOpen } from 'flavours/glitch/initial_state'; import { registrationsOpen, sso_redirect } from 'flavours/glitch/initial_state';
import { useAppDispatch, useAppSelector } from 'flavours/glitch/store'; import { useAppDispatch, useAppSelector } from 'flavours/glitch/store';
const SignInBanner = () => { const SignInBanner = () => {
@ -16,7 +16,16 @@ const SignInBanner = () => {
let signupButton; let signupButton;
const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], null) || '/auth/sign_up'); const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], null) || '/auth/sign_up');
if (sso_redirect) {
return (
<div className='sign-in-banner'>
<p><FormattedMessage id='sign_in_banner.text' defaultMessage='Login to follow profiles or hashtags, favorite, share and reply to posts. You can also interact from your account on a different server.' /></p>
<a href={sso_redirect} data-method='post' className='button button--block button-tertiary'><FormattedMessage id='sign_in_banner.sso_redirect' defaultMessage='Login or Register' /></a>
</div>
)
}
if (registrationsOpen) { if (registrationsOpen) {
signupButton = ( signupButton = (

View File

@ -82,6 +82,7 @@
* @property {boolean} use_blurhash * @property {boolean} use_blurhash
* @property {boolean=} use_pending_items * @property {boolean=} use_pending_items
* @property {string} version * @property {string} version
* @property {string} sso_redirect
* @property {boolean} translation_enabled * @property {boolean} translation_enabled
* @property {string} status_page_url * @property {string} status_page_url
* @property {boolean} system_emoji_font * @property {boolean} system_emoji_font
@ -160,6 +161,7 @@ export const usePendingItems = getMeta('use_pending_items');
export const version = getMeta('version'); export const version = getMeta('version');
export const languages = initialState?.languages; export const languages = initialState?.languages;
export const statusPageUrl = getMeta('status_page_url'); export const statusPageUrl = getMeta('status_page_url');
export const sso_redirect = getMeta('sso_redirect');
// Glitch-soc-specific settings // Glitch-soc-specific settings
export const maxChars = (initialState && initialState.max_toot_chars) || 500; export const maxChars = (initialState && initialState.max_toot_chars) || 500;