when a non-banned, deleted user logs in, reactivate their account
This commit is contained in:
parent
77e2000cb3
commit
c354485916
|
@ -22,8 +22,25 @@ class LoginController < ApplicationController
|
||||||
user = User.where(:username => params[:email]).first
|
user = User.where(:username => params[:email]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
if user && user.is_active? &&
|
begin
|
||||||
user.try(:authenticate, params[:password].to_s)
|
if !user
|
||||||
|
raise "no user"
|
||||||
|
end
|
||||||
|
|
||||||
|
if !user.try(:authenticate, params[:password].to_s)
|
||||||
|
raise "authentication failed"
|
||||||
|
end
|
||||||
|
|
||||||
|
if user.is_banned?
|
||||||
|
raise "user is banned"
|
||||||
|
end
|
||||||
|
|
||||||
|
if !user.is_active?
|
||||||
|
user.undelete!
|
||||||
|
flash[:success] = "Your account has been reactivated and your " <<
|
||||||
|
"unmoderated comments have been undeleted."
|
||||||
|
end
|
||||||
|
|
||||||
session[:u] = user.session_token
|
session[:u] = user.session_token
|
||||||
|
|
||||||
if !user.password_digest.to_s.match(/^\$2a\$#{BCrypt::Engine::DEFAULT_COST}\$/)
|
if !user.password_digest.to_s.match(/^\$2a\$#{BCrypt::Engine::DEFAULT_COST}\$/)
|
||||||
|
@ -46,6 +63,7 @@ class LoginController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
return redirect_to "/"
|
return redirect_to "/"
|
||||||
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
flash.now[:error] = "Invalid e-mail address and/or password."
|
flash.now[:error] = "Invalid e-mail address and/or password."
|
||||||
|
|
|
@ -191,6 +191,24 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def undelete!
|
||||||
|
User.transaction do
|
||||||
|
self.comments.each{|c| c.undelete_for_user(self) }
|
||||||
|
|
||||||
|
self.sent_messages.each do |m|
|
||||||
|
m.deleted_by_author = false
|
||||||
|
m.save
|
||||||
|
end
|
||||||
|
self.received_messages.each do |m|
|
||||||
|
m.deleted_by_recipient = false
|
||||||
|
m.save
|
||||||
|
end
|
||||||
|
|
||||||
|
self.deleted_at = nil
|
||||||
|
self.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initiate_password_reset_for_ip(ip)
|
def initiate_password_reset_for_ip(ip)
|
||||||
self.password_reset_token = "#{Time.now.to_i}-#{Utils.random_str(30)}"
|
self.password_reset_token = "#{Time.now.to_i}-#{Utils.random_str(30)}"
|
||||||
self.save!
|
self.save!
|
||||||
|
|
Loading…
Reference in a new issue