fix passport strategy config, remove github button from signup form

This commit is contained in:
catarak 2016-08-31 15:30:37 -04:00
parent 7a8e77282d
commit a741e4aaa8
2 changed files with 23 additions and 39 deletions

View file

@ -3,15 +3,12 @@ import { bindActionCreators } from 'redux';
import * as UserActions from '../actions';
import { reduxForm } from 'redux-form';
import SignupForm from '../components/SignupForm';
import GithubButton from '../components/GithubButton';
function SignupView(props) {
return (
<div className="signup">
<h1>Sign Up</h1>
<SignupForm {...props} />
<h2 className="signup__divider">Or</h2>
<GithubButton buttonText="Sign Up with Github" />
</div>
);
}

View file

@ -40,32 +40,20 @@ passport.use(new GitHubStrategy({
callbackURL: '/auth/github/callback',
passReqToCallback: true
}, (req, accessToken, refreshToken, profile, done) => {
if (req.user) {
// the user should actually never get here.
User.findOne({ github: profile.id }, (err, existingUser) => {
if (existingUser) {
return res.json({'errors', { msg: 'There is already a GitHub account that belongs to you. Sign in with that account or delete it, then link it with your current account.' }});
} else {
User.findById(req.user.id, (err, user) => {
user.email = user.email || profile._json.email;
user.github = profile.id;
user.username = user.username || profile.username;
user.tokens.push({ kind: 'github', accessToken });
user.name = user.name || profile.displayName;
user.save((err) => {
return res.json({'info', { msg: 'GitHub account has been linked.' }});
});
});
}
});
} else {
User.findOne({ github: profile.id }, (err, existingUser) => {
if (existingUser) {
return done(null, existingUser);
}
User.findOne({ email: profile._json.email }, (err, existingEmailUser) => {
if (existingEmailUser) {
return res.json('errors', { msg: 'There is already an account using this email address. Sign in to that account and link it with GitHub manually from Account Settings.' });
existingEmailUser.email = existingEmailUser.email || profile._json.email;
existingEmailUser.github = profile.id;
existingEmailUser.username = existingEmailUser.username || profile.username;
existingEmailUser.tokens.push({ kind: 'github', accessToken });
existingEmailUser.name = existingEmailUser.name || profile.displayName;
existingEmailUser.save((err) => {
return done(null, existingEmailUser);
});
} else {
const user = new User();
user.email = profile._json.email;
@ -74,10 +62,9 @@ passport.use(new GitHubStrategy({
user.tokens.push({ kind: 'github', accessToken });
user.name = profile.displayName;
user.save((err) => {
return res.json({'info', { msg: 'Account has been created with GitHub credentials.' }});
return done(null, user);
});
}
});
});
}
}));