Sha256: b71f25ac2177207f6a439a74e5880d1e0245dc40282924d000a6b79d5802aa1f
Contents?: true
Size: 1014 Bytes
Versions: 8
Compression:
Stored size: 1014 Bytes
Contents
class RegistrationTokenValidation def self.before(controller) new(controller.dup) end def initialize(controller) @controller = controller.dup @token = @controller.params.fetch(:registration_token, nil) @team_id = @controller.params.fetch(:team_id, nil) if @token @controller.redirect_to(@controller.new_user_session_path) unless valid? end end def valid? !expired? && !owned? && resolves? end private def team @team ||= Jobshop::Team.where(id: @team_id).first end def resolves? encrypted_token = Devise.token_generator.digest( Jobshop::Team, :registration_token, @token) # Notice how we use Devise.secure_compare to compare the token in the # database with the token given in the params, mitigating timing attacks. Devise.secure_compare(team.registration_token, encrypted_token) end def expired? @expired ||= !team.registration_token_period_valid? end def owned? @owned ||= team.owner.present? end end
Version data entries
8 entries across 8 versions & 1 rubygems