mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Removed anon name collisions and reset anon user name if name is taken in interim.
This commit is contained in:
parent
9941607bcd
commit
ffd057899e
3 changed files with 16 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
{backboneFailure, genericFailure} = require 'lib/errors'
|
||||
{backboneFailure, genericFailure, parseServerError} = require 'lib/errors'
|
||||
User = require 'models/User'
|
||||
storage = require 'lib/storage'
|
||||
BEEN_HERE_BEFORE_KEY = 'beenHereBefore'
|
||||
|
@ -16,7 +16,14 @@ init = ->
|
|||
module.exports.createUser = (userObject, failure=backboneFailure, nextURL=null) ->
|
||||
user = new User(userObject)
|
||||
user.save({}, {
|
||||
error: failure,
|
||||
error: (model,jqxhr,options) ->
|
||||
error = parseServerError(jqxhr.responseText)
|
||||
property = error.property if error.property
|
||||
if jqxhr.status is 409 and property is 'name'
|
||||
anonUserObject = _.omit(userObject, 'name')
|
||||
module.exports.createUser anonUserObject, failure, nextURL
|
||||
else
|
||||
genericFailure(jqxhr)
|
||||
success: -> if nextURL then window.location.href = nextURL else window.location.reload()
|
||||
})
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ module.exports = class SignupModalView extends View
|
|||
for key, val of me.attributes when key in ["preferredLanguage", "testGroupNumber", "dateCreated", "wizardColor1", "name", "music", "volume", "emailSubscriptions"]
|
||||
userObject[key] ?= val
|
||||
subscribe = @$el.find('#signup-subscribe').prop('checked')
|
||||
userObject.name ?= me.get('name')
|
||||
userObject.emailSubscriptions ?= []
|
||||
if subscribe
|
||||
userObject.emailSubscriptions.push 'announcement' unless 'announcement' in userObject.emailSubscriptions
|
||||
|
|
|
@ -103,13 +103,14 @@ UserHandler = class UserHandler extends Handler
|
|||
|
||||
# Name setting
|
||||
(req, user, callback) ->
|
||||
return callback(null, req, user) unless req.body.name
|
||||
nameLower = req.body.name?.toLowerCase()
|
||||
return callback(null, req, user) if nameLower is user.get('nameLower')
|
||||
User.findOne({nameLower:nameLower}).exec (err, otherUser) ->
|
||||
return callback(null, req, user) unless req.body.name or user.get('name')
|
||||
nameLower = req.body.name?.toLowerCase() or user.get('nameLower')
|
||||
# return callback(null, req, user) if nameLower is user.get('nameLower')
|
||||
User.findOne({nameLower:nameLower,anonymous:false}).exec (err, otherUser) ->
|
||||
log.error "Database error setting user name: #{err}" if err
|
||||
return callback(res:'Database error.', code:500) if err
|
||||
r = {message:'is already used by another account', property:'name'}
|
||||
console.log 'Another user exists' if otherUser
|
||||
return callback({res:r, code:409}) if otherUser
|
||||
user.set('name', req.body.name)
|
||||
callback(null, req, user)
|
||||
|
@ -150,7 +151,7 @@ UserHandler = class UserHandler extends Handler
|
|||
res.end()
|
||||
|
||||
nameToID: (req, res, name) ->
|
||||
User.findOne({nameLower:name.toLowerCase()}).exec (err, otherUser) ->
|
||||
User.findOne({nameLower:name.toLowerCase(),anonymous:false}).exec (err, otherUser) ->
|
||||
res.send(if otherUser then otherUser._id else JSON.stringify(''))
|
||||
res.end()
|
||||
|
||||
|
|
Loading…
Reference in a new issue