-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for specifying groups for the AuthenticatedRoute, Authent…
…icated and NotAuthenticated components
- Loading branch information
1 parent
48d18f7
commit 0f747af
Showing
11 changed files
with
176 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import utils from '../utils'; | ||
|
||
export default class Authenticated extends React.Component { | ||
static contextTypes = { | ||
user: React.PropTypes.object | ||
}; | ||
|
||
render() { | ||
return this.context.user !== undefined ? | ||
this.props.children : null; | ||
var user = this.context.user; | ||
var authenticated = user !== undefined; | ||
|
||
if (authenticated && this.props.inGroup) { | ||
if (user.groups) { | ||
authenticated = utils.isInGroup(user.groups, this.props.inGroup); | ||
} else { | ||
console.log(authenticated, user, user.groups); | ||
utils.logWarning('<Authenticated> In order to use the inGroup option, you must expand the groups resource for the /me endpoint.'); | ||
} | ||
} | ||
|
||
return authenticated ? utils.enforceRootElement(this.props.children) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import React from 'react'; | ||
|
||
import utils from '../utils'; | ||
|
||
export default class NotAuthenticated extends React.Component { | ||
static contextTypes = { | ||
user: React.PropTypes.object | ||
}; | ||
|
||
render() { | ||
return this.context.user === undefined ? | ||
this.props.children : null; | ||
var user = this.context.user; | ||
var authenticated = user !== undefined; | ||
|
||
if (this.props.inGroup) { | ||
if (authenticated) { | ||
if (user.groups) { | ||
authenticated = utils.isInGroup(user.groups, this.props.inGroup); | ||
} else { | ||
utils.logWarning('<NotAuthenticated> In order to use the inGroup option, you must expand the groups resource for the /me endpoint.'); | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
return !authenticated ? utils.enforceRootElement(this.props.children) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.