Merge pull request #5423 from matrix-org/t3chguy/sso
Redirect user home from auth screens if they are already logged in
This commit is contained in:
commit
11fb081f7a
3 changed files with 20 additions and 121 deletions
|
@ -87,38 +87,37 @@ import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
|
||||||
export enum Views {
|
export enum Views {
|
||||||
// a special initial state which is only used at startup, while we are
|
// a special initial state which is only used at startup, while we are
|
||||||
// trying to re-animate a matrix client or register as a guest.
|
// trying to re-animate a matrix client or register as a guest.
|
||||||
LOADING = 0,
|
LOADING,
|
||||||
|
|
||||||
// we are showing the welcome view
|
// we are showing the welcome view
|
||||||
WELCOME = 1,
|
WELCOME,
|
||||||
|
|
||||||
// we are showing the login view
|
// we are showing the login view
|
||||||
LOGIN = 2,
|
LOGIN,
|
||||||
|
|
||||||
// we are showing the registration view
|
// we are showing the registration view
|
||||||
REGISTER = 3,
|
REGISTER,
|
||||||
|
|
||||||
// completing the registration flow
|
|
||||||
POST_REGISTRATION = 4,
|
|
||||||
|
|
||||||
// showing the 'forgot password' view
|
// showing the 'forgot password' view
|
||||||
FORGOT_PASSWORD = 5,
|
FORGOT_PASSWORD,
|
||||||
|
|
||||||
// showing flow to trust this new device with cross-signing
|
// showing flow to trust this new device with cross-signing
|
||||||
COMPLETE_SECURITY = 6,
|
COMPLETE_SECURITY,
|
||||||
|
|
||||||
// flow to setup SSSS / cross-signing on this account
|
// flow to setup SSSS / cross-signing on this account
|
||||||
E2E_SETUP = 7,
|
E2E_SETUP,
|
||||||
|
|
||||||
// we are logged in with an active matrix client. The logged_in state also
|
// we are logged in with an active matrix client. The logged_in state also
|
||||||
// includes guests users as they too are logged in at the client level.
|
// includes guests users as they too are logged in at the client level.
|
||||||
LOGGED_IN = 8,
|
LOGGED_IN,
|
||||||
|
|
||||||
// We are logged out (invalid token) but have our local state again. The user
|
// We are logged out (invalid token) but have our local state again. The user
|
||||||
// should log back in to rehydrate the client.
|
// should log back in to rehydrate the client.
|
||||||
SOFT_LOGOUT = 9,
|
SOFT_LOGOUT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AUTH_SCREENS = ["register", "login", "forgot_password", "start_sso", "start_cas"];
|
||||||
|
|
||||||
// Actions that are redirected through the onboarding process prior to being
|
// Actions that are redirected through the onboarding process prior to being
|
||||||
// re-dispatched. NOTE: some actions are non-trivial and would require
|
// re-dispatched. NOTE: some actions are non-trivial and would require
|
||||||
// re-factoring to be included in this list in future.
|
// re-factoring to be included in this list in future.
|
||||||
|
@ -562,11 +561,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
ThemeController.isLogin = true;
|
ThemeController.isLogin = true;
|
||||||
this.themeWatcher.recheck();
|
this.themeWatcher.recheck();
|
||||||
break;
|
break;
|
||||||
case 'start_post_registration':
|
|
||||||
this.setState({
|
|
||||||
view: Views.POST_REGISTRATION,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 'start_password_recovery':
|
case 'start_password_recovery':
|
||||||
this.setStateForNewView({
|
this.setStateForNewView({
|
||||||
view: Views.FORGOT_PASSWORD,
|
view: Views.FORGOT_PASSWORD,
|
||||||
|
@ -1555,6 +1549,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
showScreen(screen: string, params?: {[key: string]: any}) {
|
showScreen(screen: string, params?: {[key: string]: any}) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const isLoggedOutOrGuest = !cli || cli.isGuest();
|
||||||
|
if (!isLoggedOutOrGuest && AUTH_SCREENS.includes(screen)) {
|
||||||
|
// user is logged in and landing on an auth page which will uproot their session, redirect them home instead
|
||||||
|
dis.dispatch({ action: "view_home_page" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (screen === 'register') {
|
if (screen === 'register') {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'start_registration',
|
action: 'start_registration',
|
||||||
|
@ -1571,7 +1573,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
params: params,
|
params: params,
|
||||||
});
|
});
|
||||||
} else if (screen === 'soft_logout') {
|
} else if (screen === 'soft_logout') {
|
||||||
if (MatrixClientPeg.get() && MatrixClientPeg.get().getUserId() && !Lifecycle.isSoftLogout()) {
|
if (cli.getUserId() && !Lifecycle.isSoftLogout()) {
|
||||||
// Logged in - visit a room
|
// Logged in - visit a room
|
||||||
this.viewLastRoom();
|
this.viewLastRoom();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1622,14 +1624,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'view_my_groups',
|
action: 'view_my_groups',
|
||||||
});
|
});
|
||||||
} else if (screen === 'complete_security') {
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'start_complete_security',
|
|
||||||
});
|
|
||||||
} else if (screen === 'post_registration') {
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'start_post_registration',
|
|
||||||
});
|
|
||||||
} else if (screen.indexOf('room/') === 0) {
|
} else if (screen.indexOf('room/') === 0) {
|
||||||
// Rooms can have the following formats:
|
// Rooms can have the following formats:
|
||||||
// #room_alias:domain or !opaque_id:domain
|
// #room_alias:domain or !opaque_id:domain
|
||||||
|
@ -1800,14 +1794,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
return Lifecycle.setLoggedIn(credentials);
|
return Lifecycle.setLoggedIn(credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFinishPostRegistration = () => {
|
|
||||||
// Don't confuse this with "PageType" which is the middle window to show
|
|
||||||
this.setState({
|
|
||||||
view: Views.LOGGED_IN,
|
|
||||||
});
|
|
||||||
this.showScreen("settings");
|
|
||||||
};
|
|
||||||
|
|
||||||
onSendEvent(roomId: string, event: MatrixEvent) {
|
onSendEvent(roomId: string, event: MatrixEvent) {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
if (!cli) {
|
if (!cli) {
|
||||||
|
@ -1972,13 +1958,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||||
accountPassword={this.accountPassword}
|
accountPassword={this.accountPassword}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (this.state.view === Views.POST_REGISTRATION) {
|
|
||||||
// needs to be before normal PageTypes as you are logged in technically
|
|
||||||
const PostRegistration = sdk.getComponent('structures.auth.PostRegistration');
|
|
||||||
view = (
|
|
||||||
<PostRegistration
|
|
||||||
onComplete={this.onFinishPostRegistration} />
|
|
||||||
);
|
|
||||||
} else if (this.state.view === Views.LOGGED_IN) {
|
} else if (this.state.view === Views.LOGGED_IN) {
|
||||||
// store errors stop the client syncing and require user intervention, so we'll
|
// store errors stop the client syncing and require user intervention, so we'll
|
||||||
// be showing a dialog. Don't show anything else.
|
// be showing a dialog. Don't show anything else.
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import * as sdk from '../../../index';
|
|
||||||
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
|
||||||
import { _t } from '../../../languageHandler';
|
|
||||||
import AuthPage from "../../views/auth/AuthPage";
|
|
||||||
|
|
||||||
export default class PostRegistration extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
onComplete: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
state = {
|
|
||||||
avatarUrl: null,
|
|
||||||
errorString: null,
|
|
||||||
busy: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
// There is some assymetry between ChangeDisplayName and ChangeAvatar,
|
|
||||||
// as ChangeDisplayName will auto-get the name but ChangeAvatar expects
|
|
||||||
// the URL to be passed to you (because it's also used for room avatars).
|
|
||||||
const cli = MatrixClientPeg.get();
|
|
||||||
this.setState({busy: true});
|
|
||||||
const self = this;
|
|
||||||
cli.getProfileInfo(cli.credentials.userId).then(function(result) {
|
|
||||||
self.setState({
|
|
||||||
avatarUrl: MatrixClientPeg.get().mxcUrlToHttp(result.avatar_url),
|
|
||||||
busy: false,
|
|
||||||
});
|
|
||||||
}, function(error) {
|
|
||||||
self.setState({
|
|
||||||
errorString: _t("Failed to fetch avatar URL"),
|
|
||||||
busy: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const ChangeDisplayName = sdk.getComponent('settings.ChangeDisplayName');
|
|
||||||
const ChangeAvatar = sdk.getComponent('settings.ChangeAvatar');
|
|
||||||
const AuthHeader = sdk.getComponent('auth.AuthHeader');
|
|
||||||
const AuthBody = sdk.getComponent("auth.AuthBody");
|
|
||||||
return (
|
|
||||||
<AuthPage>
|
|
||||||
<AuthHeader />
|
|
||||||
<AuthBody>
|
|
||||||
<div className="mx_Login_profile">
|
|
||||||
{ _t('Set a display name:') }
|
|
||||||
<ChangeDisplayName />
|
|
||||||
{ _t('Upload an avatar:') }
|
|
||||||
<ChangeAvatar
|
|
||||||
initialAvatarUrl={this.state.avatarUrl} />
|
|
||||||
<button onClick={this.props.onComplete}>{ _t('Continue') }</button>
|
|
||||||
{ this.state.errorString }
|
|
||||||
</div>
|
|
||||||
</AuthBody>
|
|
||||||
</AuthPage>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2459,9 +2459,6 @@
|
||||||
"Signing In...": "Signing In...",
|
"Signing In...": "Signing In...",
|
||||||
"If you've joined lots of rooms, this might take a while": "If you've joined lots of rooms, this might take a while",
|
"If you've joined lots of rooms, this might take a while": "If you've joined lots of rooms, this might take a while",
|
||||||
"Create account": "Create account",
|
"Create account": "Create account",
|
||||||
"Failed to fetch avatar URL": "Failed to fetch avatar URL",
|
|
||||||
"Set a display name:": "Set a display name:",
|
|
||||||
"Upload an avatar:": "Upload an avatar:",
|
|
||||||
"Unable to query for supported registration methods.": "Unable to query for supported registration methods.",
|
"Unable to query for supported registration methods.": "Unable to query for supported registration methods.",
|
||||||
"Registration has been disabled on this homeserver.": "Registration has been disabled on this homeserver.",
|
"Registration has been disabled on this homeserver.": "Registration has been disabled on this homeserver.",
|
||||||
"This server does not support authentication with a phone number.": "This server does not support authentication with a phone number.",
|
"This server does not support authentication with a phone number.": "This server does not support authentication with a phone number.",
|
||||||
|
|
Loading…
Reference in a new issue