Permalink
Browse files

First commit. Tested with Google and Yahoo.

  • Loading branch information...
Javier Vazquez Rodriguez
Javier Vazquez Rodriguez committed Apr 30, 2009
1 parent b76277d commit 00585db5475bbcdc95a0a167c264331a1794b4a5
@@ -1,6 +1,6 @@
class UsersController < ApplicationController
- #before_filter :require_no_user, :only => [:new, :create]
- before_filter :require_user, :only => [:show, :edit, :update]
+ before_filter :require_no_user, :only => [:new, :create]
+ before_filter :require_user, :only => [:show, :edit, :update, :destroy]
def new
@user = User.new
@@ -38,4 +38,12 @@ def update
end
end
end
+
+ def destroy
+ @user = User.find(params[:id])
+ current_user_session.destroy
+ @user.destroy
+ flash[:notice] = "Account deleted!"
+ redirect_to new_account_url
+ end
end
View
@@ -1,3 +1,20 @@
class User < ActiveRecord::Base
- acts_as_authentic
+ acts_as_authentic do |c|
+ c.validate_login_field = false
+ # optional, but if you register by openid, i want you at least to share your email-address
+ c.validate_email_field = true
+ # 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?
+ else
+ self.email = registration['http://axschema.org/contact/email'].first unless registration['http://axschema.org/contact/email'].nil?
+ end
+ end
+
end
@@ -6,13 +6,15 @@
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
- <%= javascript_include_tag :defaults %>
+ <%= stylesheet_link_tag 'openid' %>
+ <script src="/javascripts/jquery-1.2.6.min.js" type="text/javascript"></script>
+ <script src="/javascripts/openid-jquery.js" type="text/javascript"></script>
</head>
<body>
-<span style="float: right; text-align: right;"><%= link_to "Source code", "http://github.com/binarylogic/authlogic_example" %> | <%= link_to "Setup tutorial", "http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup" %> | <%= link_to "Password reset tutorial", "http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic" %><br />
+<span style="float: right; text-align: right;"><%= link_to "Source code", "http://github.com/vazqujav/authlogic_example/tree/with-openid" %> | <%= link_to "Setup tutorial", "http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup" %> | <%= link_to "Password reset tutorial", "http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic" %><br />
<%= link_to "OpenID addon", "http://github.com/binarylogic/authlogic_openid" %> | <%= link_to "Authlogic Repo", "http://github.com/binarylogic/authlogic" %> | <%= link_to "Authlogic Doc", "http://authlogic.rubyforge.org/" %></span>
-<h1>Authlogic Example App</h1>
+<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 />
@@ -23,12 +25,17 @@
<%= link_to "Log In", new_user_session_path %>
<% else %>
<%= link_to "My Account", account_path %> |
+ <%= link_to 'Delete Account', user_path(@user), :method => :delete %> |
<%= link_to "Logout", user_session_path, :method => :delete, :confirm => "Are you sure you want to logout?" %>
<% end %>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
+<h3>Current Known Issues:</h3>
+<ul>
+ <li>Yahoo isn't working because currently it doesn't provide the email address neither by sreg nor by ax.</li>
+</ul>
</body>
</html>
@@ -1,5 +0,0 @@
-A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request just click the link below:
-
-<%= @edit_password_reset_url %>
-
-If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us.
@@ -1,20 +1,21 @@
-<h1>Login</h1>
+<script type="text/javascript">
+ $(document).ready(function() {
+ openid.init('user_session[openid_identifier]');
+ });
+</script>
-<% form_for @user_session, :url => user_session_path do |f| %>
+<% form_for :user_session, @user_session, :url => user_session_path, :html => { :method => :post, :class => "new_user_session", :id => "openid_form" } do |f| %>
<%= f.error_messages %>
- <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, "OpenID" %> (or <%= link_to_function "login using a standard username / password", "$('login_container').toggle(); $('openid_container').toggle();" %>)<br /><br />
- <%= f.text_field :openid_identifier %><br />
- </div>
- <br />
- <%= f.check_box :remember_me %><%= f.label :remember_me %><br />
- <br />
- <%= f.submit "Login" %>
+ <input type="hidden" name="action" value="verify" />
+ <% field_set_tag 'Log In' do %>
+ <div id="openid_choice">
+ <p>Please click your account provider:</p>
+ <div id="openid_btns"></div>
+ </div>
+
+ <div id="openid_input_area">
+ <%= text_field_tag 'openid_identifier', :id => 'openid_identifier', :value => 'http://'%>
+ <%= submit_tag "Sign-In" %>
+ </div>
+ <% end %>
<% end %>
View
@@ -1,14 +1,16 @@
-<%= form.label :login %><br />
-<%= form.text_field :login %><br />
-<br />
-<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
-<%= form.password_field :password %><br />
-<br />
-<%= form.label :password_confirmation %><br />
-<%= form.password_field :password_confirmation %><br />
-<br />
-<%= form.label :openid_identifier, "Or use OpenID instead of a standard login / password" %><br />
-<%= form.text_field :openid_identifier %><br />
-<br />
-<%= form.label :email %><br />
-<%= form.text_field :email %><br />
+<script type="text/javascript">
+ $(document).ready(function() {
+ openid.init('user[openid_identifier]');
+ });
+</script>
+<% hidden_field_tag :action, "verify" %>
+<% field_set_tag 'Register' do %>
+ <div id="openid_choice">
+ <p>Please click your account provider:</p>
+ <div id="openid_btns"></div>
+ </div>
+ <div id="openid_input_area">
+ <%= form.text_field :openid_identifier %>
+ <%= form.submit "Create" %>
+ </div>
+<% end %>
@@ -0,0 +1,14 @@
+<%= form.label :login %><br />
+<%= form.text_field :login %><br />
+<br />
+<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
+<%= form.password_field :password %><br />
+<br />
+<%= form.label :password_confirmation %><br />
+<%= form.password_field :password_confirmation %><br />
+<br />
+<%= form.label :openid_identifier, "Or use OpenID instead of a standard login / password" %><br />
+<%= form.text_field :openid_identifier %><br />
+<br />
+<%= form.label :email %><br />
+<%= form.text_field :email %><br />
@@ -1,7 +1,4 @@
-<h1>Register</h1>
-
-<% form_for @user, :url => account_path do |f| %>
+<% form_for :user, @user, :url => account_path, :html => { :class => "new_user", :id => "openid_form" } do |f| %>
<%= f.error_messages %>
- <%= render :partial => "form", :object => f %>
- <%= f.submit "Register" %>
+ <%= render :partial => "form", :object => f %>
<% end %>
@@ -1,9 +1,7 @@
-<h1>Edit My Account</h1>
+<h1>Register</h1>
<% form_for @user, :url => account_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
- <%= f.submit "Update" %>
-<% end %>
-
-<br /><%= link_to "My Profile", account_path %>
+ <%= f.submit "Register" %>
+<% end %>
@@ -10,6 +10,11 @@
</p>
<% end %>
+<p>
+ <b>Email:</b>
+ <%=h @user.email %>
+</p>
+
<p>
<b>Login count:</b>
<%=h @user.login_count %>
@@ -38,7 +43,4 @@
<p>
<b>Current login ip:</b>
<%=h @user.current_login_ip %>
-</p>
-
-
-<%= link_to 'Edit', edit_account_path %>
+</p>
View
@@ -25,7 +25,7 @@
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "aws-s3", :lib => "aws/s3"
- config.gem "authlogic"
+ config.gem "authlogic", :version => '2.0.11'
config.gem "authlogic-oid", :lib => "authlogic_openid"
# Only load the plugins named here, in the order given. By default, all plugins
@@ -6,7 +6,7 @@ def self.up
t.string :crypted_password
t.string :password_salt
t.string :email, :null => false
- t.string :openid_identifier
+ t.string :openid_identifier, :null => false
t.string :persistence_token, :null => false
t.integer :login_count, :default => 0, :null => false
t.datetime :last_request_at
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 00585db

Please sign in to comment.