This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 362
User authentication and profile #460
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a9f9cde
wip
mmahalwy 3248e38
user stuff
mmahalwy bdbd795
Profile page!
mmahalwy 0880f9e
Unneeded calls
mmahalwy 10d0bc2
PR feedback
mmahalwy 2b84c2c
go stateless
mmahalwy 0ba78d7
dup route
mmahalwy 0370eed
oops decorators
mmahalwy 1b467d0
Merge branch 'master' into user-auth
mmahalwy d6abc75
Merge branch 'master' into user-auth
mmahalwy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
NODE_ENV=development | ||
PORT=8000 | ||
API_URL=http://quran.com:3000 | ||
ONE_QURAN_URL=http://localhost:3030 | ||
SEGMENTS_KEY= | ||
SENTRY_KEY_CLIENT= | ||
SENTRY_KEY_SERVER= | ||
# Quran.com - development app, no need to worry! | ||
FACEBOOK_APP_ID=1599019233731707 |
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 |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
Raven: true, | ||
mixpanel: true, | ||
"expect": true, | ||
"browser": true | ||
"browser": true, | ||
"FB": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { push } from 'react-router-redux'; | ||
import { facebook } from 'redux/actions/auth'; | ||
|
||
import config from 'config'; | ||
|
||
@connect( | ||
null, | ||
{ facebook, push } | ||
) | ||
export default class FacebookLogin extends Component { | ||
static propTypes = { | ||
callback: PropTypes.func.isRequired, | ||
appId: PropTypes.string.isRequired, | ||
xfbml: PropTypes.bool, | ||
cookie: PropTypes.bool, | ||
scope: PropTypes.string, | ||
textButton: PropTypes.string, | ||
autoLoad: PropTypes.bool, | ||
size: PropTypes.string, | ||
fields: PropTypes.string, | ||
cssClass: PropTypes.string, | ||
version: PropTypes.string, | ||
icon: PropTypes.string, | ||
push: PropTypes.func, | ||
facebook: PropTypes.func | ||
}; | ||
|
||
static defaultProps = { | ||
callback: () => {}, | ||
appId: config.facebookAppId, | ||
textButton: 'Connect with Facebook', | ||
icon: 'fa-facebook', | ||
scope: 'email,public_profile,user_location', | ||
xfbml: true, | ||
cookie: true, | ||
autoLoad: false, | ||
size: 'md', | ||
fields: 'first_name,name,picture', | ||
cssClass: 'btn btn-facebook btn-', | ||
version: '2.7' | ||
}; | ||
|
||
componentDidMount() { | ||
window.fbAsyncInit = () => { | ||
FB.init({ | ||
appId: this.props.appId, | ||
xfbml: this.props.xfbml, | ||
cookie: this.props.cookie, | ||
version: `v${this.props.version}`, | ||
}); | ||
|
||
if (this.props.autoLoad) { | ||
FB.getLoginStatus(this.checkLoginState); | ||
} | ||
}; | ||
|
||
// Load the SDK asynchronously | ||
(function(d, s, id) { // eslint-disable-line | ||
const element = d.getElementsByTagName(s)[0]; | ||
const fjs = element; | ||
let js = element; | ||
if (d.getElementById(id)) { return; } | ||
js = d.createElement(s); js.id = id; | ||
js.src = '//connect.facebook.net/en_US/sdk.js'; | ||
fjs.parentNode.insertBefore(js, fjs); | ||
}(window.document, 'script', 'facebook-jssdk')); // eslint-disable-line | ||
} | ||
|
||
responseApi = (authResponse) => { | ||
const { callback, facebook, push } = this.props; // eslint-disable-line no-shadow | ||
|
||
return FB.api('/me', { fields: this.props.fields }, (me) => { | ||
me.accessToken = authResponse.accessToken; // eslint-disable-line | ||
callback(me); | ||
|
||
return facebook(authResponse.accessToken).then(action => !action.error && push('/')); | ||
}); | ||
}; | ||
|
||
checkLoginState = (response) => { | ||
if (response.authResponse) { | ||
this.responseApi(response.authResponse); | ||
} else { | ||
if (this.props.callback) { | ||
this.props.callback({ status: response.status }); | ||
} | ||
} | ||
}; | ||
|
||
handleClick = () => { | ||
FB.login(this.checkLoginState, { scope: this.props.scope }); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button | ||
className={`${this.props.cssClass}${this.props.size}`} | ||
onClick={this.handleClick} | ||
> | ||
{this.props.icon && <i className={`margin-md-right fa ${this.props.icon}`} />} | ||
{this.props.textButton} | ||
</button> | ||
<div id="fb-root"></div> | ||
</div> | ||
); | ||
} | ||
} |
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,48 +1,25 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import Link from 'react-router/lib/Link'; | ||
import { connect } from 'react-redux'; | ||
|
||
class IndexHeaderNav extends Component { | ||
export class IndexHeaderNav extends Component { | ||
static propTypes = { | ||
navlink: PropTypes.bool | ||
user: PropTypes.object | ||
}; | ||
|
||
state = { | ||
open: false | ||
}; | ||
|
||
openNav(e) { | ||
e.preventDefault(); | ||
openNav(event) { | ||
event.preventDefault(); | ||
|
||
this.setState({open: !this.state.open}); | ||
} | ||
|
||
links() { | ||
let classNames = `links ${this.state.open ? 'open' : ''}`; | ||
|
||
if (this.props.navlink === false) { | ||
return ( | ||
<ul className={classNames}> | ||
<li> | ||
<Link to="/apps" data-metrics-event-name="IndexHeader:Link:Mobile"> | ||
Mobile | ||
</Link> | ||
</li> | ||
<li> | ||
<a href="https://quran.zendesk.com/hc/en-us/articles/210090626-Development-help" target="_blank" data-metrics-event-name="IndexHeader:Link:Developer"> | ||
Developers | ||
</a> | ||
</li> | ||
<li> | ||
<a href="http://legacy.quran.com" data-metrics-event-name="IndexHeader:Link:Legacy">Legacy Quran.com</a> | ||
</li> | ||
<li> | ||
<a href="https://quran.zendesk.com/hc/en-us" data-metrics-event-name="IndexHeader:Link:Contact"> | ||
Contact us | ||
</a> | ||
</li> | ||
</ul> | ||
); | ||
} | ||
const { user } = this.props; | ||
const classNames = `links ${this.state.open ? 'open' : ''}`; | ||
|
||
return ( | ||
<ul className={classNames}> | ||
|
@@ -69,6 +46,14 @@ class IndexHeaderNav extends Component { | |
Contact us | ||
</a> | ||
</li> | ||
{ | ||
user && | ||
<li> | ||
<Link to="/profile" data-metrics-event-name="IndexHeader:Link:Profile"> | ||
{user.firstName} | ||
</Link> | ||
</li> | ||
} | ||
</ul> | ||
); | ||
} | ||
|
@@ -82,4 +67,8 @@ class IndexHeaderNav extends Component { | |
} | ||
} | ||
|
||
export default IndexHeaderNav; | ||
export default connect( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a minor note on consistency, in some components we use the decorator style, and in others we don't. I think we should stick to one style. IMHO, I prefer to not use decorators. 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on no decorators. |
||
state => ({ | ||
user: state.auth.user | ||
}) | ||
)(IndexHeaderNav); |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { PropTypes } from 'react'; | ||
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer'; | ||
import Navbar from 'react-bootstrap/lib/Navbar'; | ||
import Nav from 'react-bootstrap/lib/Nav'; | ||
import NavDropdown from 'react-bootstrap/lib/NavDropdown'; | ||
import MenuItem from 'react-bootstrap/lib/MenuItem'; | ||
import NavItem from 'react-bootstrap/lib/NavItem'; | ||
import Image from 'react-bootstrap/lib/Image'; | ||
const Header = Navbar.Header; | ||
const Collapse = Navbar.Collapse; | ||
const Toggle = Navbar.Toggle; | ||
import { connect } from 'react-redux'; | ||
|
||
import userType from 'types/userType'; | ||
|
||
const styles = require('./style.scss'); | ||
|
||
export const QuranNav = ({ user }) => ( | ||
<Navbar inverse fluid className={styles.nav}> | ||
<Header> | ||
<Toggle /> | ||
</Header> | ||
<Collapse> | ||
<Nav /> | ||
<Nav pullRight> | ||
<LinkContainer to="/apps" data-metrics-event-name="IndexHeader:Link:Mobile"> | ||
<NavItem> | ||
Mobile | ||
</NavItem> | ||
</LinkContainer> | ||
<NavItem href="https://quran.zendesk.com/hc/en-us/articles/210090626-Development-help" target="_blank" data-metrics-event-name="IndexHeader:Link:Developer"> | ||
Developers | ||
</NavItem> | ||
<NavItem href="http://legacy.quran.com" data-metrics-event-name="IndexHeader:Link:Legacy"> | ||
Legacy Quran.com | ||
</NavItem> | ||
<LinkContainer to="/donations" data-metrics-event-name="IndexHeader:Link:Contribute"> | ||
<NavItem> | ||
Contribute | ||
</NavItem> | ||
</LinkContainer> | ||
<NavItem href="https://quran.zendesk.com/hc/en-us" data-metrics-event-name="IndexHeader:Link:Contact"> | ||
Contact us | ||
</NavItem> | ||
{ | ||
user && | ||
<NavDropdown | ||
title={ | ||
<span className={styles.name}> | ||
<Image src={user.image} className={styles.image} circle /> | ||
{user.firstName} | ||
</span> | ||
} | ||
id="user-dropdown" | ||
> | ||
<LinkContainer | ||
to="/profile" | ||
data-metrics-event-name="IndexHeader:Link:Profile" | ||
> | ||
<MenuItem eventKey={3.1}>Profile</MenuItem> | ||
</LinkContainer> | ||
<MenuItem eventKey={3.3}>Logout</MenuItem> | ||
</NavDropdown> | ||
} | ||
</Nav> | ||
</Collapse> | ||
</Navbar> | ||
); | ||
|
||
QuranNav.propTypes = { | ||
user: PropTypes.shape(userType) | ||
}; | ||
|
||
export default connect( | ||
state => ({ | ||
user: state.auth.user | ||
}) | ||
)(QuranNav); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
$navbar-height: 40px; | ||
.nav { | ||
min-height: $navbar-height; | ||
border-radius: 0px; | ||
margin-bottom: 0px; | ||
|
||
:global(.navbar-nav > li > a) { | ||
padding-top: ($navbar-height - 20) / 2; | ||
padding-bottom: ($navbar-height - 20) / 2; | ||
} | ||
|
||
&.transparent{ | ||
background: transparent; | ||
} | ||
} | ||
|
||
.name{ | ||
padding-left: 25px; | ||
} | ||
|
||
.image{ | ||
width: 30px; | ||
position: absolute; | ||
left: 5px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
import FacebookButton from 'components/FacebookButton'; | ||
|
||
export default () => ( | ||
<div> | ||
<FacebookButton /> | ||
</div> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use
PropTypes.shape({ ... })
for objects?