-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
537 additions
and
59 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
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,13 @@ | ||
import { | ||
SOCIAL_LOGIN_INITIATED, | ||
SOCIAL_LOGIN_SUCCESS, | ||
} from './types'; | ||
|
||
export const socialLoginInitiated = () => ({ | ||
type: SOCIAL_LOGIN_INITIATED, | ||
}); | ||
|
||
|
||
export const socialLoginSuccess = () => ({ | ||
type: SOCIAL_LOGIN_SUCCESS, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { PureComponent } from 'react'; | ||
import { Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import FacebookLogin from 'react-facebook-login'; | ||
import PropTypes from 'prop-types'; | ||
import { facebookLoginUser } from '../../actions/userActions'; | ||
|
||
class Facebook extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
redirect: false, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.isLoggedIn) { | ||
this.setState({ | ||
redirect: true, | ||
}); | ||
} | ||
} | ||
|
||
signup = (userToken, serviceProvider) => { | ||
let userData; | ||
userData = { | ||
user: { | ||
access_token: userToken, | ||
}, | ||
}; | ||
const { facebookLoginUser } = this.props; | ||
facebookLoginUser(serviceProvider, userData); | ||
} | ||
|
||
responseFacebook = (response) => { | ||
const token = response.accessToken; | ||
this.signup(token, '/api/auth/facebook/'); | ||
} | ||
|
||
render() { | ||
const value = this.state; | ||
if (value.redirect) { | ||
const to = { pathname: '/' }; | ||
return ( | ||
<Redirect to={to} /> | ||
); | ||
} | ||
return ( | ||
<FacebookLogin | ||
appId="2147542838793839" | ||
fields="name,email,picture" | ||
callback={this.responseFacebook} | ||
icon="fa fa-facebook-square icon-with-margin" | ||
cssClass="facebook" | ||
textButton="Facebook" | ||
|
||
/> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
isLoggedIn: state.user.isLoggedIn, | ||
loading: state.user.loading, | ||
}); | ||
|
||
Facebook.propTypes = { | ||
isLoggedIn: PropTypes.bool.isRequired, | ||
facebookLoginUser: PropTypes.func.isRequired, | ||
}; | ||
export { Facebook as FacebookTest }; | ||
export default connect(mapStateToProps, { facebookLoginUser })(Facebook); |
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,84 @@ | ||
import React, { PureComponent } from 'react'; | ||
import { Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import GoogleLogin from 'react-google-login'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { googleLoginUser } from '../../actions/userActions'; | ||
|
||
class Googlelogin extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
redirect: false, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.isLoggedIn) { | ||
this.setState({ | ||
redirect: true, | ||
}); | ||
} | ||
} | ||
|
||
signup = (userToken, serviceProvider) => { | ||
let userData; | ||
if (serviceProvider === '/api/auth/google/') { | ||
userData = { | ||
user: { | ||
access_token: userToken, | ||
}, | ||
}; | ||
} | ||
|
||
const { googleLoginUser } = this.props; | ||
googleLoginUser(serviceProvider, userData); | ||
} | ||
|
||
googleResponse = (response) => { | ||
const token = response.tokenId; | ||
this.signup(token, '/api/auth/google/'); | ||
} | ||
|
||
render() { | ||
const value = this.state; | ||
if (value.redirect) { | ||
const to = { pathname: '/' }; | ||
return ( | ||
<Redirect to={to} /> | ||
); | ||
} | ||
return ( | ||
<div> | ||
<GoogleLogin | ||
clientId="1040550554735-0lfo665jrpgkprjkqdvh9njlc46mu6rg.apps.googleusercontent.com" | ||
redirectUri="/" | ||
onSuccess={this.googleResponse} | ||
onFailure={this.googleResponse} | ||
className="google" | ||
> | ||
<i className="fa fa-google-plus icon-with-margin" /> | ||
<span className="raised-font"> Google</span> | ||
|
||
</GoogleLogin> | ||
| ||
|
||
</div> | ||
|
||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
isLoggedIn: state.user.isLoggedIn, | ||
loading: state.user.loading, | ||
}); | ||
|
||
Googlelogin.propTypes = { | ||
isLoggedIn: PropTypes.bool.isRequired, | ||
googleLoginUser: PropTypes.func.isRequired, | ||
}; | ||
|
||
export { Googlelogin as GoogleTest }; | ||
export default connect(mapStateToProps, { googleLoginUser })(Googlelogin); |
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
Oops, something went wrong.