Permalink
Browse files

switched to optional email and changed the view accordingly.

  • Loading branch information...
1 parent 1b8612f commit 792a32817168845145b586d8bf7f453b3d776b91 Javier Vazquez Rodriguez committed May 1, 2009
View
@@ -14,16 +14,16 @@ Live Example can be found here: http://openid-example.joontos.ch
== What does this example app contain?
1. OpenID User registration using Javascript OpenID-Selector.
-2. Automatically log users in upon successful OpenID registration, saving his OpenID identifier and email address.
+2. Automatically log users in upon successful OpenID registration, saving his OpenID identifier and (if possible) his email address.
3. A my account area where the user can view / delete his account.
4. Login/Logout functionality.
5. Automatically store information on the users and their session in the databases. Such as login count, IP address, when they logged in last, and when their last activity occurred.
6. Count how many users are logged in / out in your system.
-== Current Issues
+== Status
-* Needs to be tested using other OpenID accounts besides Google, Yahoo, Flickr and Technorati
-* The following OpenID authentication providers don't seem to support the exchange of the email address using SReg or AX: Yahoo, Technorati...
+* Tested OpenID providers with working authentication that return the users's email address: Google
+* Tested OpenID providers with working authentication: Google: Yahoo, MyOpenID, Technorati
* The following OpenID authentication providers don't seem to work at all: Flickr (replaced by Yahoo?)
== TODO
View
@@ -2,19 +2,34 @@ class User < ActiveRecord::Base
acts_as_authentic do |c|
c.validate_login_field = false
# optional, but if a user registers by openid, he should at least share his email-address with the app
- c.validate_email_field = true
+ c.validate_email_field = false
# fetch the email either by sreg or ax
c.required_fields = [:email,"http://axschema.org/contact/email"]
end
private
def map_openid_registration(registration)
- unless registration[:email].nil?
- self.email ||= registration[:email] if respond_to?(:email) && !registration[:email].blank?
+ if registration.empty?
+ # No email returned
+ self.email_autoset = false
else
- self.email = registration['http://axschema.org/contact/email'].first unless registration['http://axschema.org/contact/email'].nil?
+ # Email set by SREG?
+ unless registration[:email].nil? && registration[:email].blank?
+ self.email = registration[:email]
+ self.email_autoset = true
+ else
+ # Email set by AX
+ unless registration['http://axschema.org/contact/email'].nil? && registration['http://axschema.org/contact/email'].first.blank?
+ self.email = registration['http://axschema.org/contact/email'].first
+ self.email_autoset = true
+ else
+ # registration-hash seems to contain information other than sreg- or ax-email
+ self.email_autoset = false
+ end
+ end
end
+
end
end
@@ -12,14 +12,15 @@
</head>
<body>
-<span style="float: right; text-align: right;"><%= link_to "Source code", "http://github.com/vazqujav/authlogic_openid_selector_example" %></span>
+<span style="float: right; text-align: right;"><%= link_to "Source Code", "http://github.com/vazqujav/authlogic_openid_selector_example" %></span>
<h1>Authlogic OpenID-Selector Example App</h1>
<%= pluralize User.logged_in.count, "user" %> currently logged in<br /> <!-- This based on last_request_at, if they were active < 10 minutes they are logged in -->
<br />
<br />
<% if !current_user %>
+ <b>Make a choice:</b> <br />
<%= link_to "Register", new_account_path %> |
<%= link_to "Log In", new_user_session_path %>
<% else %>
@@ -32,5 +33,8 @@
<%= yield %>
+<p>
+This is an example of how to use <a href="http://github.com/binarylogic/authlogic">Authlogic</a> in combination with the <br /><a href="http://code.google.com/p/openid-selector/">Javascript OpenID-Selector</a> in a <a href="http://rubyonrails.org/">Ruby on Rails</a> application. <%= link_to "More...", "http://github.com/vazqujav/authlogic_openid_selector_example" %>
+</p>
</body>
</html>
@@ -5,14 +5,18 @@
</p>
<% else %>
<p>
- <b>OpenID:</b>
+ <b>OpenID Identifier:</b>
<%=h @user.openid_identifier %>
</p>
<% end %>
<p>
<b>Email:</b>
- <%=h @user.email %>
+ <% if @user.email_autoset %>
+ <%=h @user.email %>
+ <% else %>
+ OpenID Provider didn't return your email address or <br />I might haven't found out yet how to fetch it. :-)
+ <% end %>
</p>
<p>
@@ -5,7 +5,7 @@ def self.up
t.string :login
t.string :crypted_password
t.string :password_salt
- t.string :email, :null => false
+ t.string :email
t.string :openid_identifier, :null => false
t.string :persistence_token, :null => false
t.integer :login_count, :default => 0, :null => false
@@ -14,6 +14,7 @@ def self.up
t.datetime :current_login_at
t.string :last_login_ip
t.string :current_login_ip
+ t.boolean :email_autoset, :default => false, :null => false
end
add_index :users, :login

0 comments on commit 792a328

Please sign in to comment.