Просмотр исходного кода

Just generate a new token on resending confirmation email

James Allen 8 лет назад
Родитель
Сommit
476f4e55c3

+ 0 - 10
services/web/app/coffee/Features/Security/OneTimeTokenHandler.coffee

@@ -27,16 +27,6 @@ module.exports =
 			return callback(error) if error?
 			return callback(error) if error?
 			callback null, token
 			callback null, token
 
 
-	findValidTokenFromData: (use, data, callback = (error, token) ->) ->
-		db.tokens.findOne {
-			use: use,
-			data: data,
-			expiresAt: { $gt: new Date() },
-			usedAt: { $exists: false }
-		}, (error, token) ->
-			return callback(error) if error?
-			return callback null, token?.token
-
 	getValueFromTokenAndExpire: (use, token, callback = (error, data) ->)->
 	getValueFromTokenAndExpire: (use, token, callback = (error, data) ->)->
 		logger.log token_start: token.slice(0,8), "getting data from #{use} token"
 		logger.log token_start: token.slice(0,8), "getting data from #{use} token"
 		now = new Date()
 		now = new Date()

+ 0 - 11
services/web/app/coffee/Features/User/UserEmailsConfirmationHandler.coffee

@@ -23,17 +23,6 @@ module.exports = UserEmailsConfirmationHandler =
 				confirmEmailUrl: "#{settings.siteUrl}/user/emails/confirm?token=#{token}"
 				confirmEmailUrl: "#{settings.siteUrl}/user/emails/confirm?token=#{token}"
 			EmailHandler.sendEmail emailTemplate, emailOptions, callback
 			EmailHandler.sendEmail emailTemplate, emailOptions, callback
 
 
-	resendConfirmationEmail: (user_id, email, callback = (error) ->) ->
-		OneTimeTokenHandler.findValidTokenFromData 'email_confirmation', { user_id, email }, (error, token) ->
-			return callback(error) if error?
-			if !token?
-				UserEmailsConfirmationHandler.sendConfirmationEmail user_id, email, callback
-			else
-				emailOptions =
-					to: email
-					confirmEmailUrl: "#{settings.siteUrl}/user/emails/confirm?token=#{token}"
-				EmailHandler.sendEmail 'confirmEmail', emailOptions, callback
-
 	confirmEmailFromToken: (token, callback = (error) ->) ->
 	confirmEmailFromToken: (token, callback = (error) ->) ->
 		logger.log {token_start: token.slice(0,8)}, 'confirming email from token'
 		logger.log {token_start: token.slice(0,8)}, 'confirming email from token'
 		OneTimeTokenHandler.getValueFromTokenAndExpire 'email_confirmation', token, (error, data) ->
 		OneTimeTokenHandler.getValueFromTokenAndExpire 'email_confirmation', token, (error, data) ->

+ 1 - 1
services/web/app/coffee/Features/User/UserEmailsController.coffee

@@ -71,7 +71,7 @@ module.exports = UserEmailsController =
 				logger.log {userId, email, foundUserId: user?._id}, "email doesn't match logged in user"
 				logger.log {userId, email, foundUserId: user?._id}, "email doesn't match logged in user"
 				return res.sendStatus 422
 				return res.sendStatus 422
 			logger.log {userId, email}, 'resending email confirmation token'
 			logger.log {userId, email}, 'resending email confirmation token'
-			UserEmailsConfirmationHandler.resendConfirmationEmail userId, email, (error) ->
+			UserEmailsConfirmationHandler.sendConfirmationEmail userId, email, (error) ->
 				return next(error) if error?
 				return next(error) if error?
 				res.sendStatus 200
 				res.sendStatus 200
 
 

+ 5 - 9
services/web/test/acceptance/coffee/UserEmailsTests.coffee

@@ -200,8 +200,7 @@ describe "UserEmails", ->
 			], done
 			], done
 
 
 	describe 'resending the confirmation', ->
 	describe 'resending the confirmation', ->
-		it 'should resend the existing token', (done) ->
-			token = null
+		it 'should generate a new token', (done) ->
 			async.series [
 			async.series [
 				(cb) =>
 				(cb) =>
 					@user.request {
 					@user.request {
@@ -223,7 +222,6 @@ describe "UserEmails", ->
 						expect(tokens.length).to.equal 1
 						expect(tokens.length).to.equal 1
 						expect(tokens[0].data.email).to.equal 'reconfirmation-email@example.com'
 						expect(tokens[0].data.email).to.equal 'reconfirmation-email@example.com'
 						expect(tokens[0].data.user_id).to.equal @user._id
 						expect(tokens[0].data.user_id).to.equal @user._id
-						token = tokens[0].token
 						cb()
 						cb()
 				(cb) =>
 				(cb) =>
 					@user.request {
 					@user.request {
@@ -241,18 +239,18 @@ describe "UserEmails", ->
 						'data.user_id': @user._id,
 						'data.user_id': @user._id,
 						usedAt: { $exists: false }
 						usedAt: { $exists: false }
 					}, (error, tokens) =>
 					}, (error, tokens) =>
-						# There should still only be one confirmation token
-						expect(tokens.length).to.equal 1
+						# There should be two tokens now
+						expect(tokens.length).to.equal 2
 						expect(tokens[0].data.email).to.equal 'reconfirmation-email@example.com'
 						expect(tokens[0].data.email).to.equal 'reconfirmation-email@example.com'
 						expect(tokens[0].data.user_id).to.equal @user._id
 						expect(tokens[0].data.user_id).to.equal @user._id
-						token = tokens[0].token
+						expect(tokens[1].data.email).to.equal 'reconfirmation-email@example.com'
+						expect(tokens[1].data.user_id).to.equal @user._id
 						cb()
 						cb()
 			], done
 			], done
 
 
 		it 'should create a new token if none exists', (done) ->
 		it 'should create a new token if none exists', (done) ->
 			# This should only be for users that have sign up with their main
 			# This should only be for users that have sign up with their main
 			# emails before the confirmation system existed
 			# emails before the confirmation system existed
-			token = null
 			async.series [
 			async.series [
 				(cb) =>
 				(cb) =>
 					db.tokens.remove {
 					db.tokens.remove {
@@ -280,12 +278,10 @@ describe "UserEmails", ->
 						expect(tokens.length).to.equal 1
 						expect(tokens.length).to.equal 1
 						expect(tokens[0].data.email).to.equal @user.email
 						expect(tokens[0].data.email).to.equal @user.email
 						expect(tokens[0].data.user_id).to.equal @user._id
 						expect(tokens[0].data.user_id).to.equal @user._id
-						token = tokens[0].token
 						cb()
 						cb()
 			], done
 			], done
 
 
 		it "should not allow reconfirmation if the email doesn't match the user", (done) ->
 		it "should not allow reconfirmation if the email doesn't match the user", (done) ->
-			token = null
 			async.series [
 			async.series [
 				(cb) =>
 				(cb) =>
 					@user.request {
 					@user.request {