added user maintenance functional test
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
class UserMaintenanceController < ApplicationController
|
||||
def delete_account
|
||||
end
|
||||
|
||||
def login_reminder
|
||||
if request.post?
|
||||
@user = User.with_email(params[:user][:email]).first
|
||||
if @user
|
||||
UserMaintenanceMailer.login_reminder(@user).deliver
|
||||
flash[:notice] = "Email sent"
|
||||
else
|
||||
flash[:notice] = "No matching user record found"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reset_password
|
||||
if request.post?
|
||||
@user = User.find_for_password_reset(params[:user][:name], params[:user][:email]).first
|
||||
if @user
|
||||
@user.reset_password_and_deliver_notice
|
||||
flash[:notice] = "Email sent"
|
||||
else
|
||||
flash[:notice] = "No matching user record found"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,6 +26,8 @@ class User < ActiveRecord::Base
|
||||
belongs_to :inviter, :class_name => "User"
|
||||
scope :named, lambda {|name| where(["lower(name) = ?", name])}
|
||||
scope :admins, where("is_admin = TRUE")
|
||||
scope :with_email, lambda {|email| email.blank? ? where("FALSE") : where(["email = ?", email])}
|
||||
scope :find_for_password_reset, lambda {|name, email| email.blank? ? where("FALSE") : where(["name = ? AND email = ?", name, email])}
|
||||
|
||||
module BanMethods
|
||||
def validate_ip_addr_is_not_banned
|
||||
@@ -94,6 +96,11 @@ class User < ActiveRecord::Base
|
||||
execute_sql("UPDATE users SET password_hash = ? WHERE id = ?", self.class.sha1(pass), id)
|
||||
pass
|
||||
end
|
||||
|
||||
def reset_password_and_deliver_notice
|
||||
new_password = reset_password()
|
||||
UserMaintenanceMailer.reset_password(self, new_password).deliver
|
||||
end
|
||||
end
|
||||
|
||||
module AuthenticationMethods
|
||||
|
||||
14
app/models/user_maintenance_mailer.rb
Normal file
14
app/models/user_maintenance_mailer.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class UserMaintenanceMailer < ActionMailer::Base
|
||||
default :from => Danbooru.config.contact_email
|
||||
|
||||
def login_reminder(user)
|
||||
@user = user
|
||||
mail(:to => user.email, :subject => "#{Danbooru.config.app_name} login reminder")
|
||||
end
|
||||
|
||||
def reset_password(user, new_password)
|
||||
@user = user
|
||||
@new_password = new_password
|
||||
mail(:to => user.email, :subject => "#{Danbooru.config.app_name} password reset")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user