ruby script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk/
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
=========================================
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.
=========================================
ruby script/generate authenticated user sessions --include-activation --stateful
ruby script/generate controller home index
=========================================
map.root :controller => "home"
map.home '/', :controller => 'home', :action => 'index'
map.resources :users
map.resource :session
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate', :activation_code => nil
=========================================
<!-- home/index.rhtml -->
<h1>Welcome</h1>
<% if logged_in? %>
<p><strong>You are logged in as <%=h current_user.login %></strong></p>
<p><%= link_to 'Logout', logout_path %></p>
<% else %>
<p><strong>You are currently not logged in.</strong></p>
<p>
<%= link_to 'Login', login_path %> or
<%= link_to 'Sign Up', signup_path %>
</p>
<% end %>
更详细的文章
http://www.360doc.com/content/09/0407/22/4131_3053944.shtml
分享到:
相关推荐
rails登陆注册
Ajax、Prototype和Scriptaculous等JavaScript代码库和RJS,Session管理、用户登录和认证系统,XML和ActiveResource,后台处理和ActionMaile,测试和specs(包括RSpec on Rails和Selenium),安装、管理、编写插件,...
rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...
[Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...
解压后是一个exe文件,至于怎么将系统的替换为这个,相信难不到大家的哈 博文链接:https://msdn.iteye.com/blog/164888
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...
一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码
OmniAuth 是一个利用 Rack 中间件实现的灵活的认证系统。 示例代码: Rails.application.config.middleware.use OmniAuth::Builder do provider :developer unless Rails.env.production? provider :twitter, ...
本资源是参照rails敏捷开发第四版书中的例子,rails的版本是rails3.2.6
Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...
adminlte-rails, AdminLTE Rails gem 将AdminLTE主题与 Rails 资产管道集成 AdminLTE Rails gem AdminLTE 是后端的高级 Bootstrap 主题。英镑 AdminLTE Rails gem 与 Rails 资产管道集成了英镑AdminLTE主题。安装将...
Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...
中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍
使用Aptana+Rails开发Rails Web应用 有Aptana的安装配置等等,中文
Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...