Рендеринг списка скоупов на oauth/permissions

This commit is contained in:
SleepWalker 2016-02-29 20:16:33 +02:00
parent 17bdf52496
commit 5e7d063449
4 changed files with 52 additions and 11 deletions

View File

@ -18,14 +18,13 @@ class Body extends BaseAuthBody {
oAuthComplete: PropTypes.func.isRequired,
auth: PropTypes.shape({
error: PropTypes.string,
login: PropTypes.shape({
login: PropTypes.stirng
})
scopes: PropTypes.array.isRequired
})
};
render() {
const {user} = this.props;
const scopes = this.props.auth.scopes;
return (
<div>
@ -53,10 +52,9 @@ class Body extends BaseAuthBody {
<Message {...messages.theAppNeedsAccess2} />
</div>
<ul className={styles.permissionsList}>
<li>Authorization for Minecraft servers</li>
<li>Manage your skins directory and additional rows for multiline</li>
<li>Change the active skin</li>
<li>View your E-mail address</li>
{scopes.map((scope) => (
<li>{<Message {...messages[`scope_${scope}`]} />}</li>
))}
</ul>
</div>
</div>
@ -83,8 +81,14 @@ export default function Permissions() {
<Message {...messages.approve} />
</button>
),
Links: () => (
<a href="#">
Links: (props) => (
<a href="#" onClick={(event) => {
event.preventDefault();
props.onAuthComplete({
accept: false
});
}}>
<Message {...messages.decline} />
</a>
)

View File

@ -29,5 +29,15 @@ export default defineMessages({
approve: {
id: 'approve',
defaultMessage: 'Approve'
},
scope_minecraft_server_session: {
id: 'scope_minecraft_server_session',
defaultMessage: 'Authorization data for minecraft server'
},
scope_offline_access: {
id: 'scope_offline_access',
defaultMessage: 'Access to your profile data, when you offline'
}
});

View File

@ -155,6 +155,7 @@ export function oAuthValidate(oauth) {
.then((resp) => {
dispatch(setClient(resp.client));
dispatch(setOAuthRequest(resp.oAuth));
dispatch(setScopes(resp.session.scopes));
})
.catch((resp = {}) => { // TODO
handleOauthParamsValidation(resp);
@ -246,3 +247,15 @@ export function setOAuthRequest(oauth) {
}
};
}
export const SET_SCOPES = 'set_scopes';
export function setScopes(scopes) {
if (!(scopes instanceof Array)) {
throw new Error('Scopes must be array');
}
return {
type: SET_SCOPES,
payload: scopes
};
}

View File

@ -1,11 +1,12 @@
import { combineReducers } from 'redux';
import { ERROR, SET_CLIENT, SET_OAUTH } from './actions';
import { ERROR, SET_CLIENT, SET_OAUTH, SET_SCOPES } from './actions';
export default combineReducers({
error,
client,
oauth
oauth,
scopes
});
function error(
@ -59,3 +60,16 @@ function oauth(
return state;
}
}
function scopes(
state = [],
{type, payload = []}
) {
switch (type) {
case SET_SCOPES:
return payload;
default:
return state;
}
}