NAK - In the verification mail, i click on the link and i get a raise: uninitialized
constant UserController
May be an error in routes.rb file ?
--
Benjamin LAN-SUN-LUK
Le 08/11/08 14:25, « Darryl L. Pierce » <mcpierce(a)gmail.com> a écrit :
You will need to run a migration for this change.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/models/user.rb | 2 +-
app/models/user_verification.rb | 6 +++-
config/initializers/schedules.rb | 32 +++++++++++++++++++++++
config/schedules.yml.example | 3 ++
db/migrate/018_add_attempts_to_verifications.rb | 11 ++++++++
db/schema.rb | 29 +++++++++++++++++---
6 files changed, 76 insertions(+), 7 deletions(-)
create mode 100644 db/migrate/018_add_attempts_to_verifications.rb
diff --git a/app/models/user.rb b/app/models/user.rb
index e2b3989..ca0c185 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -27,7 +27,7 @@ class User < ActiveRecord::Base
:message => 'No display name was provided.'
has_one :privileges, :class_name => "UserPrivilege", :dependent =>
:destroy
- has_many :product_roles
+ has_many :product_roles, :dependent => :destroy
has_one :verification, :class_name => "UserVerification", :dependent =>
:destroy
attr_accessor :password_confirmation
diff --git a/app/models/user_verification.rb b/app/models/user_verification.rb
index 0431fe0..9d6ccd0 100644
--- a/app/models/user_verification.rb
+++ b/app/models/user_verification.rb
@@ -38,8 +38,12 @@ class UserVerification < ActiveRecord::Base
belongs_to :user
# Generates a verification token.
- #
def self.create_token
(0...TOKEN_SIZE).collect { TOKEN_CHARACTERS[Kernel.rand(TOKEN_CHARACTERS.length)]
}.join
end
+
+ # Returns whether the verification attempt has expired.
+ def expired?
+ attempts >= 3
+ end
end
diff --git a/config/initializers/schedules.rb b/config/initializers/schedules.rb
index c102cdc..9239cd9 100644
--- a/config/initializers/schedules.rb
+++ b/config/initializers/schedules.rb
@@ -81,5 +81,37 @@ threads << Thread.new do
scheduler.join
end
+threads << Thread.new do
+ scheduler = Scheduler.new
+ scheduler.start
+
+ hours = SCHEDULES_CONFIG[:user_verification_expiration][:hours]
+ minutes = SCHEDULES_CONFIG[:user_verification_expiration][:minutes]
+
+ scheduler.schedule("#{minutes} #{hours} * * *") do
+ UserVerification.find(:all).each do |verification|
+ # if the account has been validated too often, then delete it, otherwise
+ # generate a new email and send it.
+ if verification.expired?
+ UserVerification.transaction do
+ verification.user.destroy
+ end
+ else
+ begin
+ UserVerification.transaction do
+ UserMailer.deliver_email_verification(verification.user, verification.token)
+ verification.attempts = verification.attempts + 1
+ verification.sent = Date.today
+ verification.save
+ end
+ rescue Exception => error
+ puts "Unable to send verification email: #{error.message}"
+ end
+ end
+ end
+ scheduler.join
+ end
+end
+
# Run all threads
threads.each { |thread| thread.run }
diff --git a/config/schedules.yml.example b/config/schedules.yml.example
index 4be4975..75741b4 100644
--- a/config/schedules.yml.example
+++ b/config/schedules.yml.example
@@ -5,3 +5,6 @@
:sprints_products_status_time:
:hours: 5
:minutes: 0
+ :user_verification_expiration:
+ :hours: 3
+ :minutes: 0
diff --git a/db/migrate/018_add_attempts_to_verifications.rb
b/db/migrate/018_add_attempts_to_verifications.rb
new file mode 100644
index 0000000..f58552c
--- /dev/null
+++ b/db/migrate/018_add_attempts_to_verifications.rb
@@ -0,0 +1,11 @@
+# The attempts column indicates how often the system has emailed the user
+# in an attempt to verify their email address.
+class AddAttemptsToVerifications < ActiveRecord::Migration
+ def self.up
+ add_column :user_verifications, :attempts, :integer, :default => 0, :null =>
false
+ end
+
+ def self.down
+ remove_column :user_verifications, :attempts
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1d72930..6eb13ee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 17) do
+ActiveRecord::Schema.define(:version => 18) do
create_table "backlog_items", :force => true do |t|
t.integer "sprint_id",
:null => false
@@ -23,6 +23,7 @@ ActiveRecord::Schema.define(:version => 17) do
end
add_index "backlog_items", ["sprint_id",
"user_story_id"], :name =>
"index_backlog_items_on_sprint_id_and_user_story_id", :unique => true
+ add_index "backlog_items", ["user_story_id"], :name =>
"fk_backlog_items_user_story"
create_table "product_roles", :force => true do |t|
t.integer "user_id", :null => false
@@ -34,7 +35,9 @@ ActiveRecord::Schema.define(:version => 17) do
t.boolean "is_approved", :default => false
end
- add_index "product_roles", ["product_id", "user_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
+ add_index "product_roles", ["user_id", "product_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
+ add_index "product_roles", ["product_id"], :name =>
"fk_user_role_product"
+ add_index "product_roles", ["role_id"], :name =>
"fk_user_role_role"
create_table "products", :force => true do |t|
t.integer "project_id"
@@ -46,6 +49,7 @@ ActiveRecord::Schema.define(:version => 17) do
end
add_index "products", ["name"], :name =>
"index_products_on_name", :unique => true
+ add_index "products", ["project_id"], :name =>
"fk_products_project"
create_table "projects", :force => true do |t|
t.integer "owner_id", :null => false
@@ -57,6 +61,7 @@ ActiveRecord::Schema.define(:version => 17) do
end
add_index "projects", ["name"], :name =>
"index_projects_on_name", :unique => true
+ add_index "projects", ["owner_id"], :name =>
"fk_product_owner"
create_table "remaining_hours_estimates", :force => true do |t|
t.integer "backlog_item_id", :null =>
false
@@ -67,6 +72,9 @@ ActiveRecord::Schema.define(:version => 17) do
t.datetime "estimated_on", :null =>
false
end
+ add_index "remaining_hours_estimates", ["backlog_item_id"], :name
=> "fk_remaining_hours_item"
+ add_index "remaining_hours_estimates", ["user_id"], :name =>
"fk_remaining_hours_user"
+
create_table "roles", :force => true do |t|
t.string "name", :null =>
false
t.boolean "can_manage_backlog_items", :default => false, :null =>
false
@@ -98,6 +106,8 @@ ActiveRecord::Schema.define(:version => 17) do
t.integer "status", :default => 0, :null =>
false
end
+ add_index "sprints", ["product_id"], :name =>
"fk_sprint_product"
+
create_table "tasks", :force => true do |t|
t.integer "backlog_item_id",
:null => false
t.integer "primary_id",
:null => false
@@ -109,6 +119,10 @@ ActiveRecord::Schema.define(:version => 17) do
t.datetime "updated_at"
end
+ add_index "tasks", ["backlog_item_id"], :name =>
"fk_task_backlog_item"
+ add_index "tasks", ["primary_id"], :name =>
"fk_task_primary"
+ add_index "tasks", ["backup_id"], :name =>
"fk_task_backup"
+
create_table "user_privileges", :force => true do |t|
t.integer "user_id", :null => false
t.boolean "admin_projects", :default => false, :null => false
@@ -117,6 +131,8 @@ ActiveRecord::Schema.define(:version => 17) do
t.datetime "updated_at"
end
+ add_index "user_privileges", ["user_id"], :name =>
"fk_privilege_user"
+
create_table "user_stories", :force => true do |t|
t.integer "product_id"
t.integer "priority"
@@ -127,12 +143,15 @@ ActiveRecord::Schema.define(:version => 17) do
t.datetime "updated_at"
end
+ add_index "user_stories", ["product_id"], :name =>
"fk_user_story_product"
+
create_table "user_verifications", :force => true do |t|
- t.integer "user_id", :null => false
- t.string "token", :limit => 16, :null => false
- t.datetime "sent", :null => false
+ t.integer "user_id", :null => false
+ t.string "token", :limit => 16, :null => false
+ t.datetime "sent", :null => false
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "attempts", :default => 0, :null => false
end
add_index "user_verifications", ["user_id"], :name =>
"index_user_verifications_on_user_id", :unique => true
--
1.6.0.2
_______________________________________________
projxp-devel mailing list
projxp-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel