created new UserController and put delete user in it

This commit is contained in:
Henry Oswald 2014-04-09 14:50:12 +01:00
parent 37fb959b00
commit 823f4a5eb9
5 changed files with 51 additions and 25 deletions

View file

@ -0,0 +1,10 @@
UserDeleter = require("./UserDeleter")
module.exports =
deleteUser: (req, res)->
user_id = req.session.user._id
UserDeleter.deleteUser user_id, (err)->
if !err?
req.session.destroy()
res.send(200)

View file

@ -25,13 +25,6 @@ module.exports = UserController =
return next(error) if error?
res.send JSON.stringify(info)
deleteUser: (req, res)->
user_id = req.session.user._id
UserDeleter.deleteUser user_id, (err)->
if !err?
req.session.destroy()
res.send(200)
_formatPersonalInfo: (user, callback = (error, info) ->) ->
callback null, {
id: user._id.toString()

View file

@ -24,6 +24,7 @@ AuthenticationController = require('./Features/Authentication/AuthenticationCont
TagsController = require("./Features/Tags/TagsController")
CollaboratorsController = require('./Features/Collaborators/CollaboratorsController')
UserInfoController = require('./Features/User/UserInfoController')
UserController_new = require("./Features/User/UserController")
UserPagesController = require('./Features/User/UserPagesController')
DocumentController = require('./Features/Documents/DocumentController')
CompileManager = require("./Features/Compile/CompileManager")
@ -80,7 +81,7 @@ module.exports = class Router
app.get '/user/passwordreset', UserPagesController.passwordResetPage
app.post '/user/passwordReset', UserController.doRequestPasswordReset
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController.unsubscribe
app.del '/user', AuthenticationController.requireLogin(), UserInfoController.deleteUser
app.del '/user', AuthenticationController.requireLogin(), UserController_new.deleteUser
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth
app.get '/dropbox/completeRegistration', DropboxUserController.completeDropboxRegistration

View file

@ -0,0 +1,39 @@
sinon = require('sinon')
chai = require('chai')
should = chai.should()
expect = chai.expect
modulePath = "../../../../app/js/Features/User/UserController.js"
SandboxedModule = require('sandboxed-module')
events = require "events"
MockResponse = require "../helpers/MockResponse"
MockRequest = require "../helpers/MockRequest"
ObjectId = require("mongojs").ObjectId
describe "UserController", ->
beforeEach ->
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserController = SandboxedModule.require modulePath, requires:
"./UserDeleter": @UserDeleter
@req = new MockRequest()
@res = new MockResponse()
@next = sinon.stub()
describe "deleteUser", ->
it "should delete the user", (done)->
user_id = "323123"
@req.session.user =
_id = user_id
@res.send = (code)=>
@UserDeleter.deleteUser.calledWith(user_id)
code.should.equal 200
done()
@UserController.deleteUser @req, @res

View file

@ -108,20 +108,3 @@ describe "UserInfoController", ->
}
describe "deleteUser", ->
it "should delete the user", (done)->
user_id = "323123"
@req.session.user =
_id = user_id
@res.send = (code)=>
@UserDeleter.deleteUser.calledWith(user_id)
code.should.equal 200
done()
@UserInfoController.deleteUser @req, @res