Permalink
Browse files

Added in hacky proof of concept JsAuth code.

Disabled auto_register as it prevents email being obtained
  • Loading branch information...
1 parent 6209d2a commit 649a0f1603d1dc3982007cd932e8372bd54aab08 @dctanner committed Dec 22, 2009
@@ -1,7 +1,12 @@
class UserSessionsController < ApplicationController
- before_filter :require_no_user, :only => [:new, :create]
+ # before_filter :require_no_user, :only => [:new, :create]
+ before_filter :require_no_user_so_destroy_if_exists, :only => [:new, :create]
before_filter :require_user, :only => :destroy
+ def require_no_user_so_destroy_if_exists
+ current_user_session.destroy if current_user
+ end
+
def new
@user_session = UserSession.new
end
@@ -19,13 +24,18 @@ def create
@user_session.save do |result|
if result
flash[:notice] = "Login successful!"
+ # @user = @user_session.record
+ # render :action => :jsauth_success, :layout => 'jsauth'
redirect_back_or_default account_url
else
render :action => :new
end
end
end
+ def jsauth_success
+ end
+
def destroy
current_user_session.destroy
flash[:notice] = "Logout successful!"
@@ -4,6 +4,11 @@ class UsersController < ApplicationController
def new
@user = User.new
+
+ respond_to do |format|
+ format.html { render }
+ format.js { render :layout => false }
+ end
end
def create
View
@@ -22,7 +22,6 @@ def before_connect(facebook_session)
private
def map_openid_registration(registration)
-
if registration.empty?
# no email returned
self.email_autoset = false
@@ -1,5 +1,6 @@
class UserSession < Authlogic::Session::Base
- auto_register
+ # TODO: auto_register does NOT fetch email etc.. http://stackoverflow.com/questions/1748629/authlogic-autoregister-feature-using-my-options
+ # auto_register
logout_on_timeout true
end
@@ -5,14 +5,11 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
- <%= stylesheet_link_tag 'application', 'scaffold' %>
- <%= stylesheet_link_tag 'openid' %>
- <%= javascript_include_tag :defaults %>
+ <link href="/stylesheets/openid.css" media="screen" rel="stylesheet" type="text/css" />
+
<script src="/javascripts/jquery-1.2.6.min.js" type="text/javascript"></script>
- <script>
- jQuery.noConflict();
- </script>
+
<script src="/javascripts/openid-jquery.js" type="text/javascript"></script>
@@ -39,8 +36,8 @@
<p style="color: green"><%= flash[:notice] %></p>
-<%= fb_connect_javascript_tag %>
-<%= init_fb_connect "XFBML" %>
+<%# fb_connect_javascript_tag %>
+<%# init_fb_connect "XFBML" %>
<%= yield %>
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title><%= controller.controller_name %>: <%= controller.action_name %></title>
+ <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>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,4 @@
+<% form_for :user_session, @user_session, :url => user_session_url, :html => { :method => :post, :class => "new_user_session", :id => "openid_form" } do |f| %>
+ <%= f.text_field 'openid_identifier', :value => 'http://yahoo.com/' %>
+ <%= submit_tag "Sign-In" %>
+<% end %>
@@ -0,0 +1,21 @@
+<form action="http://localhost:9393/auth" method="post" id="jsauth_success_form">
+ <input type="hidden" name="id" value="<%= @user.id %>" />
+ <input type="hidden" name="email" value="<%= @user.email %>" />
+ <input type="hidden" name="signature" value="USEHMACSIGN" />
+ <input type="submit" value="Complete login to actual app" />
+</form>
+
+
+
+<script type="text/javascript" charset="utf-8">
+ // $('#jsauth_success_form').submit();
+</script>
+
+<p>
+ <b>Email:</b>
+ <% 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>
@@ -20,4 +20,4 @@
<% end %>
<% end %>
-<%= authlogic_facebook_login_button %>
+<%# authlogic_facebook_login_button %>
@@ -0,0 +1,2 @@
+var scr = document.getElementById('jsauth');
+scr.innerHTML = "<%= escape_javascript(render(:partial => 'form')) %>";
View
@@ -1,6 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resource :account, :controller => "users"
map.resources :users
- map.resource :user_session
+ map.resource :user_session, :collection => {:jsauth_success => :get}
map.root :controller => "user_sessions", :action => "new"
end

0 comments on commit 649a0f1

Please sign in to comment.