From 9c3c57f2a84724dbd726edc4e8fa733a5c09a878 Mon Sep 17 00:00:00 2001
From: Henry Oswald <henry.oswald@sharelatex.com>
Date: Fri, 16 May 2014 10:43:55 +0100
Subject: [PATCH] renamed TokenGenerator to PasswordResetTokenHandler and added
 Expire to function name

---
 .../PasswordReset/PasswordResetHandler.coffee      |  6 +++---
 ...tor.coffee => PasswordResetTokenHandler.coffee} |  2 +-
 .../PasswordReset/PasswordResetHandlerTests.coffee | 14 +++++++-------
 ...offee => PasswordResetTokenHandlerTests.coffee} | 14 +++++++-------
 4 files changed, 18 insertions(+), 18 deletions(-)
 rename services/web/app/coffee/Features/PasswordReset/{TokenGenerator.coffee => PasswordResetTokenHandler.coffee} (94%)
 rename services/web/test/UnitTests/coffee/PasswordReset/{TokenGeneratorTests.coffee => PasswordResetTokenHandlerTests.coffee} (77%)

diff --git a/services/web/app/coffee/Features/PasswordReset/PasswordResetHandler.coffee b/services/web/app/coffee/Features/PasswordReset/PasswordResetHandler.coffee
index 6c062989f1..d53a95be16 100644
--- a/services/web/app/coffee/Features/PasswordReset/PasswordResetHandler.coffee
+++ b/services/web/app/coffee/Features/PasswordReset/PasswordResetHandler.coffee
@@ -1,7 +1,7 @@
 settings = require("settings-sharelatex")
 async = require("async")
 UserGetter = require("../User/UserGetter")
-TokenGenerator = require("./TokenGenerator")
+PasswordResetTokenHandler = require("./PasswordResetTokenHandler")
 EmailHandler = require("../Email/EmailHandler")
 AuthenticationManager = require("../Authentication/AuthenticationManager")
 logger = require("logger-sharelatex")
@@ -14,7 +14,7 @@ module.exports =
 			if !user?
 				logger.err email:email, "user could not be found for password reset"
 				return callback("no user found")
-			TokenGenerator.getNewToken user._id, (err, token)->
+			PasswordResetTokenHandler.getNewToken user._id, (err, token)->
 				if err then return callback(err)
 				emailOptions =
 					to : email
@@ -22,7 +22,7 @@ module.exports =
 				EmailHandler.sendEmail "passwordResetRequested", emailOptions, callback		
 
 	setNewUserPassword: (token, password, callback)->
-		TokenGenerator.getUserIdFromToken token, (err, user_id)->
+		PasswordResetTokenHandler.getUserIdFromTokenAndExpire token, (err, user_id)->
 			if err then return callback(err)
 			if !user_id?
 				logger.err user_id:user_id, "token for password reset did not find user_id"
diff --git a/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee b/services/web/app/coffee/Features/PasswordReset/PasswordResetTokenHandler.coffee
similarity index 94%
rename from services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee
rename to services/web/app/coffee/Features/PasswordReset/PasswordResetTokenHandler.coffee
index a9caa343bd..0a58a0cd52 100644
--- a/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee
+++ b/services/web/app/coffee/Features/PasswordReset/PasswordResetTokenHandler.coffee
@@ -20,7 +20,7 @@ module.exports =
 		multi.exec (err)->
 			callback(err, token)
 
-	getUserIdFromToken: (token, callback)->
+	getUserIdFromTokenAndExpire: (token, callback)->
 		logger.log token:token, "getting user id from password token"
 		multi = rclient.multi()
 		multi.get buildKey(token)
diff --git a/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetHandlerTests.coffee b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetHandlerTests.coffee
index 5797dc86e1..d51eff543a 100644
--- a/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetHandlerTests.coffee
+++ b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetHandlerTests.coffee
@@ -12,9 +12,9 @@ describe "PasswordResetHandler", ->
 
 		@settings = 
 			siteUrl: "www.sharelatex.com"
-		@TokenGenerator =
+		@PasswordResetTokenHandler =
 			getNewToken:sinon.stub()
-			getUserIdFromToken:sinon.stub()
+			getUserIdFromTokenAndExpire:sinon.stub()
 		@UserGetter =
 			getUser:sinon.stub()
 		@EmailHandler = 
@@ -23,7 +23,7 @@ describe "PasswordResetHandler", ->
 			setUserPassword:sinon.stub()
 		@PasswordResetHandler = SandboxedModule.require modulePath, requires:
 			"../User/UserGetter": @UserGetter
-			"./TokenGenerator": @TokenGenerator
+			"./PasswordResetTokenHandler": @PasswordResetTokenHandler
 			"../Email/EmailHandler":@EmailHandler
 			"../Authentication/AuthenticationManager":@AuthenticationManager
 			"settings-sharelatex": @settings
@@ -41,7 +41,7 @@ describe "PasswordResetHandler", ->
 
 		it "should check the user exists", (done)->
 			@UserGetter.getUser.callsArgWith(1)
-			@TokenGenerator.getNewToken.callsArgWith(1)
+			@PasswordResetTokenHandler.getNewToken.callsArgWith(1)
 			@PasswordResetHandler.generateAndEmailResetToken @user.email, (err)=>
 				err.should.exists
 				done()
@@ -50,7 +50,7 @@ describe "PasswordResetHandler", ->
 		it "should send the email with the token", (done)->
 
 			@UserGetter.getUser.callsArgWith(1, null, @user)
-			@TokenGenerator.getNewToken.callsArgWith(1, null, @token)
+			@PasswordResetTokenHandler.getNewToken.callsArgWith(1, null, @token)
 			@EmailHandler.sendEmail.callsArgWith(2)
 			@PasswordResetHandler.generateAndEmailResetToken @user.email, (err)=>
 				@EmailHandler.sendEmail.called.should.equal true
@@ -63,14 +63,14 @@ describe "PasswordResetHandler", ->
 	describe "setNewUserPassword", ->
 
 		it "should return err if no user id can be found", (done)->
-			@TokenGenerator.getUserIdFromToken.callsArgWith(1)
+			@PasswordResetTokenHandler.getUserIdFromTokenAndExpire.callsArgWith(1)
 			@PasswordResetHandler.setNewUserPassword @token, @password, (err)=>
 				err.should.exists
 				@AuthenticationManager.setUserPassword.called.should.equal false
 				done()		
 
 		it "should set the user password", (done)->
-			@TokenGenerator.getUserIdFromToken.callsArgWith(1, null, @user_id)
+			@PasswordResetTokenHandler.getUserIdFromTokenAndExpire.callsArgWith(1, null, @user_id)
 			@AuthenticationManager.setUserPassword.callsArgWith(2)
 			@PasswordResetHandler.setNewUserPassword @token, @password, (err)=>
 				@AuthenticationManager.setUserPassword.calledWith(@user_id, @password).should.equal true
diff --git a/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetTokenHandlerTests.coffee
similarity index 77%
rename from services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee
rename to services/web/test/UnitTests/coffee/PasswordReset/PasswordResetTokenHandlerTests.coffee
index ae3228c239..49d94c1a0f 100644
--- a/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee
+++ b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetTokenHandlerTests.coffee
@@ -3,10 +3,10 @@ SandboxedModule = require('sandboxed-module')
 assert = require('assert')
 path = require('path')
 sinon = require('sinon')
-modulePath = path.join __dirname, "../../../../app/js/Features/PasswordReset/TokenGenerator"
+modulePath = path.join __dirname, "../../../../app/js/Features/PasswordReset/PasswordResetTokenHandler"
 expect = require("chai").expect
 
-describe "TokenGenerator", ->
+describe "PasswordResetTokenHandler", ->
 
 	beforeEach ->
 		@user_id = "user id here"
@@ -23,7 +23,7 @@ describe "TokenGenerator", ->
 			exec:sinon.stub()
 		@uuid = v4 : -> return @stubbedToken
 		self = @
-		@TokenGenerator = SandboxedModule.require modulePath, requires:
+		@PasswordResetTokenHandler = SandboxedModule.require modulePath, requires:
 			"redis" :
 				createClient: =>
 					auth:->
@@ -38,23 +38,23 @@ describe "TokenGenerator", ->
 
 		it "should set a new token into redis with a ttl", (done)->
 			@redisMulti.exec.callsArgWith(0) 
-			@TokenGenerator.getNewToken @user_id, (err, token)=>
+			@PasswordResetTokenHandler.getNewToken @user_id, (err, token)=>
 				@redisMulti.set "password_token:#{@stubbedToken}", @user_id
 				@redisMulti.expire "password_token:#{@stubbedToken}", 60 * 60
 				done()
 
 		it "should return if there was an error", (done)->
 			@redisMulti.exec.callsArgWith(0, "error")
-			@TokenGenerator.getNewToken @user_id, (err, token)=>
+			@PasswordResetTokenHandler.getNewToken @user_id, (err, token)=>
 				err.should.exist
 				done()
 
 
-	describe "getUserIdFromToken", ->
+	describe "getUserIdFromTokenAndExpire", ->
 
 		it "should get and delete the token", (done)->
 			@redisMulti.exec.callsArgWith(0, null, [@user_id]) 
-			@TokenGenerator.getUserIdFromToken @stubbedToken, (err, user_id)=>
+			@PasswordResetTokenHandler.getUserIdFromTokenAndExpire @stubbedToken, (err, user_id)=>
 				user_id.should.equal @user_id
 				@redisMulti.get.calledWith("password_token:#{@stubbedToken}").should.equal true
 				@redisMulti.del.calledWith("password_token:#{@stubbedToken}").should.equal true