Delete previous tokens when creating a new one.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2778 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
62e58f26b0
commit
6da0542af4
2 files changed
+22
-4
No files matched your search
+11
-2
@@ -1,5 +1,5 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -19,6 +19,8 @@ class Token < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :value
|
||||
|
||||
before_create :delete_previous_tokens
|
||||
|
||||
@@validity_time = 1.day
|
||||
|
||||
def before_create
|
||||
@@ -39,4 +41,11 @@ private
|
||||
def self.generate_token_value
|
||||
ActiveSupport::SecureRandom.hex(20)
|
||||
end
|
||||
|
||||
# Removes obsolete tokens (same user and action)
|
||||
def delete_previous_tokens
|
||||
if user
|
||||
Token.delete_all(['user_id = ? AND action = ?', user.id, action])
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user