allow github accounts with no email visible to sign up
parent
b01c46dbc7
commit
40d8200eac
|
@ -117,7 +117,7 @@ function PassportHelper () {
|
|||
|
||||
// if the profile object from passport has an email, use it
|
||||
if (profile.emails && profile.emails[0]) userAttrs.email = profile.emails[0].value
|
||||
if (!userAttrs.email) return next(new Error('No email available'))
|
||||
// if (!userAttrs.email) return next(new Error('No email available'))
|
||||
|
||||
const pass = await Passport.findOne({
|
||||
provider,
|
||||
|
@ -128,7 +128,9 @@ function PassportHelper () {
|
|||
|
||||
if (!req.user) {
|
||||
if (!pass) { // new user signing up, create a new user and/or passport
|
||||
user = await User.findOne({ email: userAttrs.email })
|
||||
if (userAttrs.email) {
|
||||
user = await User.findOne({ email: userAttrs.email })
|
||||
}
|
||||
if (!user) {
|
||||
user = await User.create(userAttrs).fetch()
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ module.exports = {
|
|||
autoIncrement: true
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
unique: true,
|
||||
required: true
|
||||
type: 'string'
|
||||
}
|
||||
|
||||
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
|
||||
|
|
|
@ -131,7 +131,7 @@ export const editUser = (user) => async (dispatch, getState) => {
|
|||
dispatch(setWorking(true))
|
||||
|
||||
try {
|
||||
if (!user.currentPassword) throw new Error('Please enter your current password.')
|
||||
// if (!user.currentPassword) throw new Error('Please enter your current password.')
|
||||
await Ajax.patch({
|
||||
url: '/api/me',
|
||||
data: {
|
||||
|
|
|
@ -70,17 +70,19 @@ module.exports.protocols = {
|
|||
const dbUser = await User.findOne({
|
||||
id: user.id
|
||||
})
|
||||
if (!dbUser) throw new Error('an account with that id was not found')
|
||||
if (!dbUser) throw new Error('An account with that id was not found.')
|
||||
|
||||
const passport = await Passport.findOne({
|
||||
protocol: 'local',
|
||||
user: user.id
|
||||
})
|
||||
if (!user.currentPassword && passport) throw new Error('Missing current password')
|
||||
if (!user.currentPassword && passport) throw new Error('Please enter your current password.')
|
||||
if (passport) {
|
||||
const res = await Passport.validatePassword(user.currentPassword, passport)
|
||||
if (!res) throw new Error('incorrect password')
|
||||
|
||||
const otherUser = await User.findOne({ email: user.email })
|
||||
if (otherUser && otherUser.id !== dbUser.id) throw new Error('There is already an account with that email.')
|
||||
await User.update({ id: user.id }, {
|
||||
email: user.email
|
||||
})
|
||||
|
@ -90,6 +92,8 @@ module.exports.protocols = {
|
|||
})
|
||||
}
|
||||
} else { // no password yet, add one
|
||||
const otherUser = await User.findOne({ email: user.email })
|
||||
if (otherUser && otherUser.id !== dbUser.id) throw new Error('There is already an account with that email.')
|
||||
await User.update({ id: user.id }, {
|
||||
email: user.email
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue