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 the profile object from passport has an email, use it
|
||||||
if (profile.emails && profile.emails[0]) userAttrs.email = profile.emails[0].value
|
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({
|
const pass = await Passport.findOne({
|
||||||
provider,
|
provider,
|
||||||
|
@ -128,7 +128,9 @@ function PassportHelper () {
|
||||||
|
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
if (!pass) { // new user signing up, create a new user and/or passport
|
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) {
|
if (!user) {
|
||||||
user = await User.create(userAttrs).fetch()
|
user = await User.create(userAttrs).fetch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,7 @@ module.exports = {
|
||||||
autoIncrement: true
|
autoIncrement: true
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
type: 'string',
|
type: 'string'
|
||||||
unique: true,
|
|
||||||
required: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
|
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
|
||||||
|
|
|
@ -131,7 +131,7 @@ export const editUser = (user) => async (dispatch, getState) => {
|
||||||
dispatch(setWorking(true))
|
dispatch(setWorking(true))
|
||||||
|
|
||||||
try {
|
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({
|
await Ajax.patch({
|
||||||
url: '/api/me',
|
url: '/api/me',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -70,17 +70,19 @@ module.exports.protocols = {
|
||||||
const dbUser = await User.findOne({
|
const dbUser = await User.findOne({
|
||||||
id: user.id
|
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({
|
const passport = await Passport.findOne({
|
||||||
protocol: 'local',
|
protocol: 'local',
|
||||||
user: user.id
|
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) {
|
if (passport) {
|
||||||
const res = await Passport.validatePassword(user.currentPassword, passport)
|
const res = await Passport.validatePassword(user.currentPassword, passport)
|
||||||
if (!res) throw new Error('incorrect password')
|
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 }, {
|
await User.update({ id: user.id }, {
|
||||||
email: user.email
|
email: user.email
|
||||||
})
|
})
|
||||||
|
@ -90,6 +92,8 @@ module.exports.protocols = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else { // no password yet, add one
|
} 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 }, {
|
await User.update({ id: user.id }, {
|
||||||
email: user.email
|
email: user.email
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue