Disable an user

330 views
Skip to first unread message

Suec

unread,
Jun 1, 2009, 9:37:30 PM6/1/09
to Authlogic
What is the best way to disable an user(or disable his/her login)?

Thanks,

scott

unread,
Jun 1, 2009, 11:42:23 PM6/1/09
to Authlogic
Authlogic::Session::MagicStates - Automatically validates based on the
records states: active?, approved?, and confirmed?. If those methods
exist for the record.
just create a active? method in your user model.

one easy way is to create a boolean column in your user table named
something like active and put this in your user model

def active?
self.active
end

if active? returns true, they can login, if it returns false, they
will be blocked from logging in.

Ben Johnson

unread,
Jun 1, 2009, 11:46:36 PM6/1/09
to auth...@googlegroups.com
Yep, scott has it right. Also, I am pretty sure if you create a
boolean column you get the ? method for free.

Lastly, you can stop the login writing your own validation hook, just
like you would for an AR model. So fi you don't want to use active?
you can define your own method and do whatever you want:

validate :login_disabled



Ben Johnson
Binary Logic

W: www.binarylogic.com
E: bjoh...@binarylogic.com

1430 Broadway
7th Floor - NECO
New York, NY 10018

Suec

unread,
Jun 2, 2009, 3:09:28 AM6/2/09
to Authlogic
Thanks a lot, works really well.

Sue

On Jun 1, 8:46 pm, Ben Johnson <bjohn...@binarylogic.com> wrote:
> Yep, scott has it right. Also, I am pretty sure if you create a  
> boolean column you get the ? method for free.
>
> Lastly, you can stop the login writing your own validation hook, just  
> like you would for an AR model. So fi you don't want to use active?  
> you can define your own method and do whatever you want:
>
> validate :login_disabled
>
> Ben Johnson
> Binary Logic
>
> W:www.binarylogic.com
> E: bjohn...@binarylogic.com

pixelhandler

unread,
Jun 26, 2009, 1:58:04 AM6/26/09
to Authlogic
I create an action based on my login id....

in the user controller...

# GET /users/ban/1
def ban
@user = User.find(params[:id])
if superuser == true
@user.update_attribute(:confirmed,0)
flash[:notice] = "{@user.login} was banned"
else
flash[:notice] = "huh?"
end
respond_to do |format|
format.html { redirect_to(users_path) }
format.xml { head :ok }
end
end

You will also need to define the superuser ; I did this as a private
function ...

def superuser
unless @current_user.id == 1
return false
end
return true
end

Note 1 is the first record in the users table
Reply all
Reply to author
Forward
0 new messages