-
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
17 changed files
with
16,431 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import axiosInstance from '../config/axiosInstance'; | ||
import { | ||
socialLoginInitiated, | ||
socialLoginSuccess, | ||
} from './actionCreators'; | ||
|
||
const facebookLoginUser = (serviceProvider, userData) => (dispatch) => { | ||
dispatch(socialLoginInitiated(true)); | ||
return axiosInstance.post(serviceProvider, userData) | ||
.then((res) => { | ||
console.log('res', res); | ||
localStorage.setItem('token', res.data.user.access_token); | ||
dispatch(socialLoginSuccess(res)); | ||
}) | ||
.catch((error) => error); | ||
}; | ||
|
||
export default facebookLoginUser; |
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,2 @@ | ||
export const SOCIAL_LOGIN_INITIATED = 'SOCIAL_LOGIN_INITIATED'; | ||
export const SOCIAL_LOGIN_SUCCESS = '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { toast } from 'react-toastify'; | ||
import axiosInstance from '../config/axiosInstance'; | ||
import { | ||
socialLoginInitiated, | ||
socialLoginSuccess, | ||
} from './actionCreators'; | ||
|
||
const googleLoginUser = (serviceProvider, userData) => (dispatch) => { | ||
dispatch(socialLoginInitiated(true)); | ||
return axiosInstance.post(serviceProvider, userData) | ||
.then((res) => { | ||
console.log('res', res); | ||
localStorage.setItem('token', res.data.user.access_token); | ||
dispatch(socialLoginSuccess(res)); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
toast.error(error, { autoClose: 3500, hideProgressBar: true }, { | ||
position: toast.POSITION.TOP_CENTER, | ||
}); | ||
}); | ||
}; | ||
|
||
export default googleLoginUser; |
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,67 @@ | ||
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/facebookActions'; | ||
|
||
class Facebook extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
redirect: false, | ||
}; | ||
} | ||
|
||
signup = (userToken, serviceProvider) => { | ||
let userData; | ||
userData = { | ||
user: { | ||
access_token: userToken, | ||
}, | ||
}; | ||
if (userData) { | ||
const { facebookLoginUser } = this.props; | ||
facebookLoginUser(serviceProvider, userData) | ||
.catch(alert('error')); | ||
} | ||
} | ||
|
||
responseFacebook = (response) => { | ||
const token = response.accessToken; | ||
this.signup(token, '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 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,86 @@ | ||
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 === 'google/') { | ||
userData = { | ||
user: { | ||
access_token: userToken, | ||
}, | ||
}; | ||
} | ||
|
||
if (userData) { | ||
const { googleLoginUser } = this.props; | ||
googleLoginUser(serviceProvider, userData); | ||
} | ||
} | ||
|
||
googleResponse = (response) => { | ||
const token = response.tokenId; | ||
this.signup(token, '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import React from 'react'; | ||
import Googlelogin from './Google'; | ||
import Faceboook from './Facebook'; | ||
|
||
const Login = () => <h1>Login!</h1>; | ||
const Login = () => ( | ||
<div> | ||
<h1>Login!</h1> | ||
<div className="row"> | ||
<div className="col-md-2"> | ||
<Googlelogin /> | ||
</div> | ||
<div className="col-md-2"> | ||
<Faceboook /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default Login; |
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,24 @@ | ||
import axiosInstance from '../config/axiosInstance'; | ||
|
||
// function startSocialLogin() { | ||
// return { | ||
// type: 'Start_Social_Login', | ||
// }; | ||
|
||
// function endSocialLogin (token) { | ||
// return { | ||
// type: 'End_Social_Login', | ||
// token:token, | ||
// }; | ||
|
||
const postData = (serviceProvider, userData) => { | ||
// dispatch(startSocialLogin); | ||
return axiosInstance.post(serviceProvider, userData) | ||
.then((res) => { | ||
console.log('res', res); | ||
// dispatch(endSocialLogin(res)); | ||
}) | ||
.catch((error) => error); | ||
}; | ||
|
||
export default postData; |
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 axios from 'axios'; | ||
|
||
const apiBaseUrl = 'http://127.0.0.1:8000/api/auth/'; | ||
|
||
const axiosInstance = axios.create({ | ||
baseURL: apiBaseUrl, | ||
}); | ||
|
||
export default axiosInstance; |
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,8 +1,10 @@ | ||
import { combineReducers } from 'redux'; | ||
import userReducer from './userReducer'; | ||
|
||
|
||
const rootReducer = combineReducers({ | ||
// dummy object for reducer | ||
user: () => ({}), | ||
user: userReducer, | ||
}); | ||
|
||
export default rootReducer; |
Oops, something went wrong.