mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Тесты для стейтов AuthFlow
This commit is contained in:
@@ -10,14 +10,13 @@ import ForgotPasswordState from './ForgotPasswordState';
|
||||
|
||||
const availableActions = {
|
||||
...actions,
|
||||
updateUser
|
||||
updateUser,
|
||||
redirect(url) {
|
||||
location.href = url;
|
||||
}
|
||||
};
|
||||
|
||||
export default class AuthFlow {
|
||||
constructor(states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
setStore(store) {
|
||||
this.navigate = (route) => {
|
||||
const {routing} = this.getState();
|
||||
|
||||
@@ -9,14 +9,11 @@ export default class CompleteState extends AbstractState {
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
|
||||
if ('accept' in options) {
|
||||
this.isPermissionsAccepted = options.accept;
|
||||
this.isUserReviewedPermissions = true;
|
||||
}
|
||||
this.isPermissionsAccepted = options.accept;
|
||||
}
|
||||
|
||||
enter(context) {
|
||||
const {auth, user} = context.getState();
|
||||
const {auth = {}, user} = context.getState();
|
||||
|
||||
if (user.isGuest) {
|
||||
context.setState(new LoginState());
|
||||
@@ -28,18 +25,19 @@ export default class CompleteState extends AbstractState {
|
||||
if (auth.oauth.code) {
|
||||
context.setState(new FinishState());
|
||||
} else {
|
||||
let data = {};
|
||||
if (this.isUserReviewedPermissions) {
|
||||
const data = {};
|
||||
if (typeof this.isPermissionsAccepted !== 'undefined') {
|
||||
data.accept = this.isPermissionsAccepted;
|
||||
}
|
||||
context.run('oAuthComplete', data).then((resp) => {
|
||||
if (resp.redirectUri.startsWith('static_page')) {
|
||||
// TODO: пусть в стейт попадает флаг или тип авторизации
|
||||
// вместо волшебства над редирект урлой
|
||||
if (resp.redirectUri.indexOf('static_page') === 0) {
|
||||
context.setState(new FinishState());
|
||||
} else {
|
||||
location.href = resp.redirectUri;
|
||||
context.run('redirect', resp.redirectUri);
|
||||
}
|
||||
}, (resp) => {
|
||||
// TODO
|
||||
if (resp.unauthorized) {
|
||||
context.setState(new LoginState());
|
||||
} else if (resp.acceptRequired) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import AbstractState from './AbstractState';
|
||||
|
||||
export default class CompleteState extends AbstractState {
|
||||
export default class FinishState extends AbstractState {
|
||||
enter(context) {
|
||||
context.navigate('/oauth/finish');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user