mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Return proper error from registration handler
This commit is contained in:
parent
cb948fede2
commit
93a088618a
4 changed files with 6 additions and 6 deletions
|
@ -84,7 +84,7 @@ module.exports =
|
||||||
logger.log email: req.body.email, "attempted register"
|
logger.log email: req.body.email, "attempted register"
|
||||||
redir = Url.parse(req.body.redir or "/project").path
|
redir = Url.parse(req.body.redir or "/project").path
|
||||||
UserRegistrationHandler.registerNewUser req.body, (err, user)->
|
UserRegistrationHandler.registerNewUser req.body, (err, user)->
|
||||||
if err == "EmailAlreadyRegisterd"
|
if err? and err?.message == "EmailAlreadyRegistered"
|
||||||
return AuthenticationController.login req, res
|
return AuthenticationController.login req, res
|
||||||
else if err?
|
else if err?
|
||||||
next(err)
|
next(err)
|
||||||
|
|
|
@ -39,13 +39,13 @@ module.exports =
|
||||||
self = @
|
self = @
|
||||||
requestIsValid = @_registrationRequestIsValid userDetails
|
requestIsValid = @_registrationRequestIsValid userDetails
|
||||||
if !requestIsValid
|
if !requestIsValid
|
||||||
return callback("request is not valid")
|
return callback(new Error("request is not valid"))
|
||||||
userDetails.email = userDetails.email?.trim()?.toLowerCase()
|
userDetails.email = userDetails.email?.trim()?.toLowerCase()
|
||||||
User.findOne email:userDetails.email, (err, user)->
|
User.findOne email:userDetails.email, (err, user)->
|
||||||
if err?
|
if err?
|
||||||
return callback err
|
return callback err
|
||||||
if user?.holdingAccount == false
|
if user?.holdingAccount == false
|
||||||
return callback("EmailAlreadyRegisterd")
|
return callback(new Error("EmailAlreadyRegistered"))
|
||||||
self._createNewUserIfRequired user, userDetails, (err, user)->
|
self._createNewUserIfRequired user, userDetails, (err, user)->
|
||||||
if err?
|
if err?
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
|
|
@ -173,9 +173,9 @@ describe "UserController", ->
|
||||||
done()
|
done()
|
||||||
@UserController.register @req, @res
|
@UserController.register @req, @res
|
||||||
|
|
||||||
it "should try and log the user in if there is an EmailAlreadyRegisterd error", (done)->
|
it "should try and log the user in if there is an EmailAlreadyRegistered error", (done)->
|
||||||
|
|
||||||
@UserRegistrationHandler.registerNewUser.callsArgWith(1, "EmailAlreadyRegisterd")
|
@UserRegistrationHandler.registerNewUser.callsArgWith(1, new Error("EmailAlreadyRegistered"))
|
||||||
@AuthenticationController.login = (req, res)=>
|
@AuthenticationController.login = (req, res)=>
|
||||||
assert.deepEqual req, @req
|
assert.deepEqual req, @req
|
||||||
assert.deepEqual res, @res
|
assert.deepEqual res, @res
|
||||||
|
|
|
@ -87,7 +87,7 @@ describe "UserRegistrationHandler", ->
|
||||||
it "should return email registered in the error if there is a non holdingAccount there", (done)->
|
it "should return email registered in the error if there is a non holdingAccount there", (done)->
|
||||||
@User.findOne.callsArgWith(1, null, {holdingAccount:false})
|
@User.findOne.callsArgWith(1, null, {holdingAccount:false})
|
||||||
@handler.registerNewUser @passingRequest, (err)=>
|
@handler.registerNewUser @passingRequest, (err)=>
|
||||||
err.should.equal "EmailAlreadyRegisterd"
|
err.should.deep.equal new Error("EmailAlreadyRegistered")
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "validRequest", ->
|
describe "validRequest", ->
|
||||||
|
|
Loading…
Reference in a new issue