mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
fix bug on user name management (#799)
Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
@@ -138,8 +138,13 @@ dbapi.createBootStrap = function(env) {
|
||||
, email: group.owner.email
|
||||
, ip: '127.0.0.1'
|
||||
})
|
||||
.then(function() {
|
||||
return updateUsersForMigration(group)
|
||||
.then(function(stats) {
|
||||
if (stats) {
|
||||
return updateUsersForMigration(group)
|
||||
}
|
||||
return dbapi.deleteGroup(group.id).then(function() {
|
||||
throw new Error('Found the same user with a different name')
|
||||
})
|
||||
})
|
||||
.then(function() {
|
||||
return updateDevicesForMigration(group)
|
||||
@@ -1018,18 +1023,28 @@ dbapi.createUser = function(email, name, ip) {
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.checkUserBeforeLogin = function(user) {
|
||||
return db.run(r.table('users').get(user.email)).then(function(oldUser) {
|
||||
if (!oldUser || oldUser.name === user.name) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.saveUserAfterLogin = function(user) {
|
||||
return db.run(r.table('users').get(user.email).update({
|
||||
name: user.name
|
||||
, ip: user.ip
|
||||
return db.run(r.table('users').get(user.email)).then(function(oldUser) {
|
||||
if (!oldUser) {
|
||||
return dbapi.createUser(user.email, user.name, user.ip)
|
||||
}
|
||||
if (oldUser.name !== user.name) {
|
||||
return null
|
||||
}
|
||||
return db.run(r.table('users').get(user.email).update({
|
||||
ip: user.ip
|
||||
, lastLoggedInAt: r.now()
|
||||
}))
|
||||
.then(function(stats) {
|
||||
if (stats.skipped) {
|
||||
return dbapi.createUser(user.email, user.name, user.ip)
|
||||
}
|
||||
return stats
|
||||
})
|
||||
}, {returnChanges: true}))
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.loadUser = function(email) {
|
||||
|
||||
Reference in New Issue
Block a user