my OS is ubuntu7.10:
1.cd to the project directory
2.
sudo gem install ruby-openid
3.
sudo ruby script/plugin install open_id_authentication
4.rake -T open_id (to see the rake command)
5.
rake open_id_authentication:db:create
6.in the open-id migrate add these lines:
add_column :users, :identity_url, :string
(in self.up)
remove_column :users, :identity_url
(in self.down)
7.run the migrate
8.add a line in routes.rb:
map.open_id_complete 'session', :controller => "session", :action => "create",:requirements => { :method => :get }
VERY VERY IMPORTENT!!!
make sure the map.open_id_complete line above the map.resource :session line;(IT waste lots of my time!!!)
9:add a :identity_url in user.rb and it will look like:
attr_accessible :login, :email, :password, :password_confirmation, :identity_url
10.add some line in session/new.rhtml:
<p>
<label for="openid_url">OpenID URL</label><br/>
<%=text_field_tag "openid_url"%>
</p>
11.:
# This controller handles the login/logout function of the site.
class SessionController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
# include AuthenticatedSystem
# render new.rhtml
layout "welcome"
def new
end
def create
if using_open_id?
open_id_authentication(params[:openid_url])
else
password_authentication(params[:login], params[:password])
end
end
def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "你已经登录了."
redirect_back_or_default('/')
end
protected
def open_id_authentication(openid_url)
authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
if result.successful?
@user = User.find_or_initialize_by_identity_url(identity_url)
if @user.new_record?
@user.login = registration['nickname']
@user.email = registration['email']
@user.save(false)
end
self.current_user = @user
successful_login
else
failed_login result.message
end
end
end
def password_authentication(login, password)
self.current_user = User.authenticate(login, password)
if logged_in?
successful_login
else
failed_login
end
end
def failed_login(message = "Authentication failed.")
flash.now[:error] = message
render :action => 'new'
end
def successful_login
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default('/tools')
flash[:notice] = "登录成功"
end
end
12.add some css:
/* embeds the openid image in the text field */
input#openid_url {
background: url(http://openid.net/login-bg.gif) no-repeat;
background-color: #fff;
background-position: 0 50%;
color: #000;
padding-left: 18px;
}
分享到:
- 2007-12-19 09:57
- 浏览 1113
- 评论(1)
- 论坛回复 / 浏览 (1 / 3541)
- 查看更多
相关推荐
ruby on rails社区网站开发源码
在过去的几年中,《Ruby on Rails Tutorial》这本书被视为介绍使用 Rails 进行 Web 开发的先驱者。 在这个全球互联的世界中,计算机编程和 Web 应用程序开发都在迅猛发展,我很期待能为中国的开发者提供 Ruby on ...
Ruby On Rails中文教材(PDF)
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
Ruby on Rails中文指南
Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 ...
ruby on rails对mongodb的操作ruby on rails对mongodb的操作ruby on rails对mongodb的操作ruby on rails对mongodb的操作
在目前的主流web开发技术中,基于ruby语言的rails框架是做网站开发速度最快的工具。它可以达到j2ee框架开发速度的5~10倍,并且代码量也非常少。另外由于代码量的大幅度减少,整个网站维护的工作量也大大降低。 ...
Ruby On Rails 官方教程,这本书讲解如何使用 Ruby on Rails 框架开发应用,以及如何把应用部署到生成环境。本书使用 Rails 默认的开发工具栈开发了一个完整的社交应用(类似 Twitter)。读完本书后你将掌握如何使用...
ruby on rails api方便查阅
最终的示例程序将在外表上和一个同样采用 Rails 开发的微博网站十分相似2。虽然我们将主要的精力集中在这个示例程序上了,但是本书的重点却在于提供一些通用的方法,这样你就会具有坚实的基本功,不论开发什么样的 ...
ruby on rails 开发环境包(ruby1.8.7,rails2.2.3)
Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...
ruby on rails 教程源码,配合原书使用
ruby on rails最新版 这是本人精心收集的重要软件
该资源包包括在Linux安装Ruby on Rails所需的包,以及安装步骤文档
基于ruby on rails开发示例源码
最新Ruby on Rails中文版介绍,欢迎大家共同学习此最新的技术!随着Ruby和Rails版本的不断升级,这些知识也在不断的更新,谢谢的支持!