mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-15 09:49:01 +05:30
Заимплементил finish state
This commit is contained in:
parent
779cf2d187
commit
e0d93c3058
@ -151,6 +151,7 @@ export function oAuthComplete(params = {}) {
|
|||||||
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
||||||
// user declined permissions
|
// user declined permissions
|
||||||
return {
|
return {
|
||||||
|
success: false,
|
||||||
redirectUri: resp.redirectUri
|
redirectUri: resp.redirectUri
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -168,6 +169,18 @@ export function oAuthComplete(params = {}) {
|
|||||||
error.acceptRequired = true;
|
error.acceptRequired = true;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.then((resp) => {
|
||||||
|
if (resp.redirectUri === 'static_page' || resp.redirectUri === 'static_page_with_code') {
|
||||||
|
resp.displayCode = resp.redirectUri === 'static_page_with_code';
|
||||||
|
dispatch(setOAuthCode({
|
||||||
|
success: resp.success,
|
||||||
|
code: resp.code,
|
||||||
|
displayCode: resp.displayCode
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -224,6 +237,18 @@ export function setOAuthRequest(oauth) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const SET_OAUTH_RESULT = 'set_oauth_result';
|
||||||
|
export function setOAuthCode(oauth) {
|
||||||
|
return {
|
||||||
|
type: SET_OAUTH_RESULT,
|
||||||
|
payload: {
|
||||||
|
success: oauth.success,
|
||||||
|
code: oauth.code,
|
||||||
|
displayCode: oauth.displayCode
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const SET_SCOPES = 'set_scopes';
|
export const SET_SCOPES = 'set_scopes';
|
||||||
export function setScopes(scopes) {
|
export function setScopes(scopes) {
|
||||||
if (!(scopes instanceof Array)) {
|
if (!(scopes instanceof Array)) {
|
||||||
|
@ -104,9 +104,9 @@ class Finish extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect((state) => ({
|
export default connect(({auth}) => ({
|
||||||
appName: state.auth.client ? state.auth.client.name : 'Undefined',
|
appName: auth.client.name,
|
||||||
code: 'HW9vkZA6Y4vRN3ciSm1IIDk98PHLkPPlv3jvo1MX',
|
code: auth.oauth.code,
|
||||||
displayCode: true,
|
displayCode: auth.oauth.displayCode,
|
||||||
success: true
|
success: auth.oauth.success
|
||||||
}))(Finish);
|
}))(Finish);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
|
|
||||||
import { ERROR, SET_CLIENT, SET_OAUTH, SET_SCOPES } from './actions';
|
import { ERROR, SET_CLIENT, SET_OAUTH, SET_OAUTH_RESULT, SET_SCOPES } from './actions';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
error,
|
error,
|
||||||
@ -56,6 +56,14 @@ function oauth(
|
|||||||
state: payload.state
|
state: payload.state
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case SET_OAUTH_RESULT:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
success: payload.success,
|
||||||
|
code: payload.code,
|
||||||
|
displayCode: payload.displayCode
|
||||||
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,6 @@ import { connect } from 'react-redux';
|
|||||||
import AppInfo from 'components/auth/appInfo/AppInfo';
|
import AppInfo from 'components/auth/appInfo/AppInfo';
|
||||||
import PanelTransition from 'components/auth/PanelTransition';
|
import PanelTransition from 'components/auth/PanelTransition';
|
||||||
|
|
||||||
import Finish from 'components/auth/Finish';
|
|
||||||
|
|
||||||
import styles from './auth.scss';
|
import styles from './auth.scss';
|
||||||
|
|
||||||
class AuthPage extends Component {
|
class AuthPage extends Component {
|
||||||
|
@ -16,7 +16,7 @@ import Password from 'components/auth/password/Password';
|
|||||||
import Logout from 'components/auth/Logout';
|
import Logout from 'components/auth/Logout';
|
||||||
import PasswordChange from 'components/auth/passwordChange/PasswordChange';
|
import PasswordChange from 'components/auth/passwordChange/PasswordChange';
|
||||||
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
|
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
|
||||||
import Finish from 'components/auth/Finish';
|
import Finish from 'components/auth/finish/Finish';
|
||||||
|
|
||||||
import authFlow from 'services/authFlow';
|
import authFlow from 'services/authFlow';
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ export default function routesFactory(store) {
|
|||||||
<Route path="/register" components={new Register()} {...onEnter} />
|
<Route path="/register" components={new Register()} {...onEnter} />
|
||||||
<Route path="/activation" components={new Activation()} {...onEnter} />
|
<Route path="/activation" components={new Activation()} {...onEnter} />
|
||||||
<Route path="/oauth/permissions" components={new Permissions()} {...onEnter} />
|
<Route path="/oauth/permissions" components={new Permissions()} {...onEnter} />
|
||||||
<Route path="/oauth/finish" component={Finish} />
|
<Route path="/oauth/finish" component={Finish} {...onEnter} />
|
||||||
<Route path="/password-change" components={new PasswordChange()} {...onEnter} />
|
<Route path="/password-change" components={new PasswordChange()} {...onEnter} />
|
||||||
<Route path="/forgot-password" components={new ForgotPassword()} {...onEnter} />
|
<Route path="/forgot-password" components={new ForgotPassword()} {...onEnter} />
|
||||||
</Route>
|
</Route>
|
||||||
|
@ -93,6 +93,7 @@ export default class AuthFlow {
|
|||||||
case '/activation':
|
case '/activation':
|
||||||
case '/password-change':
|
case '/password-change':
|
||||||
case '/oauth/permissions':
|
case '/oauth/permissions':
|
||||||
|
case '/oauth/finish':
|
||||||
this.setState(new LoginState());
|
this.setState(new LoginState());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -3,8 +3,18 @@ import LoginState from './LoginState';
|
|||||||
import PermissionsState from './PermissionsState';
|
import PermissionsState from './PermissionsState';
|
||||||
import ActivationState from './ActivationState';
|
import ActivationState from './ActivationState';
|
||||||
import ChangePasswordState from './ChangePasswordState';
|
import ChangePasswordState from './ChangePasswordState';
|
||||||
|
import FinishState from './FinishState';
|
||||||
|
|
||||||
export default class CompleteState extends AbstractState {
|
export default class CompleteState extends AbstractState {
|
||||||
|
constructor(options = {}) {
|
||||||
|
super(options);
|
||||||
|
|
||||||
|
if ('accept' in options) {
|
||||||
|
this.isPermissionsAccepted = options.accept;
|
||||||
|
this.isUserReviewedPermissions = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enter(context) {
|
enter(context) {
|
||||||
const {auth, user} = context.getState();
|
const {auth, user} = context.getState();
|
||||||
|
|
||||||
@ -15,16 +25,32 @@ export default class CompleteState extends AbstractState {
|
|||||||
} else if (user.shouldChangePassword) {
|
} else if (user.shouldChangePassword) {
|
||||||
context.setState(new ChangePasswordState());
|
context.setState(new ChangePasswordState());
|
||||||
} else if (auth.oauth) {
|
} else if (auth.oauth) {
|
||||||
context.run('oAuthComplete').then((resp) => {
|
if (auth.oauth.code) {
|
||||||
location.href = resp.redirectUri;
|
context.setState(new FinishState());
|
||||||
}, (resp) => {
|
} else {
|
||||||
// TODO
|
let data = {};
|
||||||
if (resp.unauthorized) {
|
if (this.isUserReviewedPermissions) {
|
||||||
context.setState(new LoginState());
|
data.accept = this.isPermissionsAccepted;
|
||||||
} else if (resp.acceptRequired) {
|
|
||||||
context.setState(new PermissionsState());
|
|
||||||
}
|
}
|
||||||
});
|
context.run('oAuthComplete', data).then((resp) => {
|
||||||
|
switch (resp.redirectUri) {
|
||||||
|
case 'static_page':
|
||||||
|
case 'static_page_with_code':
|
||||||
|
context.setState(new FinishState());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
location.href = resp.redirectUri;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, (resp) => {
|
||||||
|
// TODO
|
||||||
|
if (resp.unauthorized) {
|
||||||
|
context.setState(new LoginState());
|
||||||
|
} else if (resp.acceptRequired) {
|
||||||
|
context.setState(new PermissionsState());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context.navigate('/');
|
context.navigate('/');
|
||||||
}
|
}
|
||||||
|
7
src/services/authFlow/FinishState.js
Normal file
7
src/services/authFlow/FinishState.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import AbstractState from './AbstractState';
|
||||||
|
|
||||||
|
export default class CompleteState extends AbstractState {
|
||||||
|
enter(context) {
|
||||||
|
context.navigate('/oauth/finish');
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import AbstractState from './AbstractState';
|
import AbstractState from './AbstractState';
|
||||||
|
import CompleteState from './CompleteState';
|
||||||
|
|
||||||
export default class PermissionsState extends AbstractState {
|
export default class PermissionsState extends AbstractState {
|
||||||
enter(context) {
|
enter(context) {
|
||||||
@ -14,8 +15,8 @@ export default class PermissionsState extends AbstractState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process(context, accept) {
|
process(context, accept) {
|
||||||
context.run('oAuthComplete', {
|
context.setState(new CompleteState({
|
||||||
accept
|
accept
|
||||||
}).then((resp) => location.href = resp.redirectUri);
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user