Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumoshu/97851 to your computer and use it in GitHub Desktop.
Save mumoshu/97851 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# at_authlogic_openid.rb
#
# See also:
# http://m.onkey.org/2008/12/4/rails-templates
# http://www.binarylogic.com/2009/3/30/authlogic-2-0-with-some-openid-goodness/
# http://d.hatena.ne.jp/mothprog/20090404/1238810821
# 1. Install gems.
gem "ruby-openid", :lib => "openid"
# gem "authlogic-oid", :lib => "authlogic_openid"
rake "gems:install", :sudo => true
# 2. Install plugins.
plugin "open_id_authentication", :git => "git://github.com/rails/open_id_authentication.git"
plugin "authlogic_openid", :git => "git://github.com/binarylogic/authlogic_openid.git"
# 3. Setup OpenID Authentication
rake "open_id_authentication:db:create"
# 4. Add an OpenID Identifier field to the User model.
generate :migration, "AddOpenIDIdentifierToUser", "openid_identifier:string"
rake "db:migrate"
require "open3"
inside("app/views") do
Open3.popen3("patch -p3") do |stdin, stdout, stderr|
stdin.puts <<-DIFF
diff -rU3 test/app/views/user_sessions/new.html.erb test4/app/views/user_sessions/new.html.erb
--- test/app/views/user_sessions/new.html.erb 2009-04-18 22:11:20.000000000 +0900
+++ test4/app/views/user_sessions/new.html.erb 2009-04-18 22:21:20.000000000 +0900
@@ -2,11 +2,17 @@
<% form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
- <%= f.label :login %><br />
+ <div id="login_container"<% unless @user_session.openid_identifier.blank? %> style="display: none;"<% end %>>
+ <%= f.label :login %> (or <%= link_to_function "login using OpenID", "$('login_container').toggle(); $('openid_container').toggle();" %>)<br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
+ </div>
+ <div id="openid_container"<% if @user_session.openid_identifier.blank? %> style="display: none;"<% end %>>
+ <%= f.label :openid_identifier %> (or <%= link_to_function "login using a standard username / password", "$('login_container').toggle(); $('openid_container').toggle();" %>)<br />
+ <%= f.text_field :openid_identifier %>
+ </div>
<br />
<%= f.check_box :remember_me %><%= f.label :remember_me %><br />
<br />
test4/app/views/user_sessionsだけに発見: new.html.erb~
diff -rU3 test/app/views/users/_form.erb test4/app/views/users/_form.erb
--- test/app/views/users/_form.erb 2009-04-18 22:11:20.000000000 +0900
+++ test4/app/views/users/_form.erb 2009-04-18 12:05:10.000000000 +0900
@@ -6,3 +6,6 @@
<br />
<%= form.label :password_confirmation %><br />
<%= form.password_field :password_confirmation %><br />
+<br />
+<%= form.label :openid_identifier %><br />
+<%= form.text_field :openid_identifier %><br />
diff -rU3 test/app/views/users/show.html.erb test4/app/views/users/show.html.erb
--- test/app/views/users/show.html.erb 2009-04-18 22:11:20.000000000 +0900
+++ test4/app/views/users/show.html.erb 2009-04-18 22:15:22.000000000 +0900
@@ -1,7 +1,14 @@
-<p>
- <b>Login:</b>
- <%=h @user.login %>
-</p>
+<% if @user.openid_identifier.blank? %>
+ <p>
+ <b>Login:</b>
+ <%=h @user.login %>
+ </p>
+<% else %>
+ <p>
+ <b>OpenID:</b>
+ <%=h @user.openid_identifier %>
+ </p>
+<% end %>
<p>
<b>Login count:</b>
DIFF
stdin.close
puts stdout.read, stderr.read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment