mirror of
				https://github.com/elyby/accounts-frontend.git
				synced 2025-05-31 14:11:58 +05:30 
			
		
		
		
	Рендеринг списка скоупов на oauth/permissions
This commit is contained in:
		| @@ -18,14 +18,13 @@ class Body extends BaseAuthBody { | |||||||
|         oAuthComplete: PropTypes.func.isRequired, |         oAuthComplete: PropTypes.func.isRequired, | ||||||
|         auth: PropTypes.shape({ |         auth: PropTypes.shape({ | ||||||
|             error: PropTypes.string, |             error: PropTypes.string, | ||||||
|             login: PropTypes.shape({ |             scopes: PropTypes.array.isRequired | ||||||
|                 login: PropTypes.stirng |  | ||||||
|             }) |  | ||||||
|         }) |         }) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     render() { |     render() { | ||||||
|         const {user} = this.props; |         const {user} = this.props; | ||||||
|  |         const scopes = this.props.auth.scopes; | ||||||
|  |  | ||||||
|         return ( |         return ( | ||||||
|             <div> |             <div> | ||||||
| @@ -53,10 +52,9 @@ class Body extends BaseAuthBody { | |||||||
|                         <Message {...messages.theAppNeedsAccess2} /> |                         <Message {...messages.theAppNeedsAccess2} /> | ||||||
|                     </div> |                     </div> | ||||||
|                     <ul className={styles.permissionsList}> |                     <ul className={styles.permissionsList}> | ||||||
|                         <li>Authorization for Minecraft servers</li> |                         {scopes.map((scope) => ( | ||||||
|                         <li>Manage your skins directory and additional rows for multiline</li> |                             <li>{<Message {...messages[`scope_${scope}`]} />}</li> | ||||||
|                         <li>Change the active skin</li> |                         ))} | ||||||
|                         <li>View your E-mail address</li> |  | ||||||
|                     </ul> |                     </ul> | ||||||
|                 </div> |                 </div> | ||||||
|             </div> |             </div> | ||||||
| @@ -83,8 +81,14 @@ export default function Permissions() { | |||||||
|                 <Message {...messages.approve} /> |                 <Message {...messages.approve} /> | ||||||
|             </button> |             </button> | ||||||
|         ), |         ), | ||||||
|         Links: () => ( |         Links: (props) => ( | ||||||
|             <a href="#"> |             <a href="#" onClick={(event) => { | ||||||
|  |                 event.preventDefault(); | ||||||
|  |  | ||||||
|  |                 props.onAuthComplete({ | ||||||
|  |                     accept: false | ||||||
|  |                 }); | ||||||
|  |             }}> | ||||||
|                 <Message {...messages.decline} /> |                 <Message {...messages.decline} /> | ||||||
|             </a> |             </a> | ||||||
|         ) |         ) | ||||||
|   | |||||||
| @@ -29,5 +29,15 @@ export default defineMessages({ | |||||||
|     approve: { |     approve: { | ||||||
|         id: 'approve', |         id: 'approve', | ||||||
|         defaultMessage: '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' | ||||||
|     } |     } | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -155,6 +155,7 @@ export function oAuthValidate(oauth) { | |||||||
|         .then((resp) => { |         .then((resp) => { | ||||||
|             dispatch(setClient(resp.client)); |             dispatch(setClient(resp.client)); | ||||||
|             dispatch(setOAuthRequest(resp.oAuth)); |             dispatch(setOAuthRequest(resp.oAuth)); | ||||||
|  |             dispatch(setScopes(resp.session.scopes)); | ||||||
|         }) |         }) | ||||||
|         .catch((resp = {}) => { // TODO |         .catch((resp = {}) => { // TODO | ||||||
|             handleOauthParamsValidation(resp); |             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 | ||||||
|  |     }; | ||||||
|  | } | ||||||
|   | |||||||
| @@ -1,11 +1,12 @@ | |||||||
| import { combineReducers } from 'redux'; | 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({ | export default combineReducers({ | ||||||
|     error, |     error, | ||||||
|     client, |     client, | ||||||
|     oauth |     oauth, | ||||||
|  |     scopes | ||||||
| }); | }); | ||||||
|  |  | ||||||
| function error( | function error( | ||||||
| @@ -59,3 +60,16 @@ function oauth( | |||||||
|             return state; |             return state; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function scopes( | ||||||
|  |     state = [], | ||||||
|  |     {type, payload = []} | ||||||
|  | ) { | ||||||
|  |     switch (type) { | ||||||
|  |         case SET_SCOPES: | ||||||
|  |             return payload; | ||||||
|  |  | ||||||
|  |         default: | ||||||
|  |             return state; | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user