restful_authentication使用

这是一个基本的Restful认证生成器,适用于Rails框架,来源于acts_as_authenticated。当前需要Rails 1.2.6或更高版本。使用该生成器可以创建用户模型、会话控制器,并支持激活邮件发送及状态机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Restful Authentication Generator
====

This is a basic restful authentication generator for rails, taken
from acts as authenticated.  Currently it requires Rails 1.2.6 or above.

To use:

  ./script/generate authenticated user sessions \
  --include-activation \
  --stateful

The first parameter specifies the model that gets created in signup
(typically a user or account model).  A model with migration is
created, as well as a basic controller with the create method.

The second parameter specifies the sessions controller name.  This is
the controller that handles the actual login/logout function on the
site.

The third parameter (--include-activation) generates the code for a
ActionMailer and its respective Activation Code through email.

The fourth (--stateful) builds in support for acts_as_state_machine
and generates activation code.  This was taken from:

http://www.vaporbase.com/postings/stateful_authentication

You can pass --skip-migration to skip the user migration.

If you're using acts_as_state_machine, define your users resource like this:

 map.resources :users, :member => { :suspend   => :put,
                                     :unsuspend => :put,
                                     :purge     => :delete }

Also, add an observer to config/environment.rb if you chose the
--include-activation option

  config.active_record.observers = :user_observer # or whatever you
                         # named your model

Security Alert
====

I introduced a change to the model controller that's been tripping
folks up on Rails 2.0.  The change was added as a suggestion to help
combat session fixation attacks.  However, this resets the Form
Authentication token used by Request Forgery Protection.  I've left
it out now, since Rails 1.2.6 and Rails 2.0 will both stop session
fixation attacks anyway.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值