Permalink
Browse files

first pass at openid implementation

  • Loading branch information...
herestomwiththeweather committed Sep 5, 2008
1 parent b354544 commit cbed5958cb6cf67b05e73b32b8ed52a88b62762d
@@ -8,7 +8,55 @@ def new
end
def create
- person = Person.authenticate(params[:email], params[:password])
+ if using_open_id?
+ open_id_authentication(params[:openid_url])
+ else
+ password_authentication(params[:login],params[:password])
+ end
+ end
+
+ def open_id_authentication(openid_url)
+ authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
+ if result.successful?
+ @person = Person.find_or_initialize_by_identity_url(identity_url)
+ if @person.new_record?
+ @person.name = registration['nickname']
+ @person.email = registration['email']
+ @person.save
+ if @person.errors.empty?
+ self.current_person = @person
+ successful_login
+ else
+ @body = "login single-col"
+ err_message = "Your OpenID profile must provide"
+ err_message += " nickname," if !@person.errors[:name].nil?
+ err_message += " email," if !@person.errors[:email].nil?
+
+ failed_login err_message.chop
+ end
+ end
+ else
+ failed_login result.message
+ end
+ 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_person.remember_me
+ cookies[:auth_token] = { :value => self.current_person.remember_token , :expires => self.current_person.remember_token_expires_at }
+ end
+ redirect_back_or_default('/')
+ flash[:notice] = "Logged in successfully"
+ end
+
+ def password_authentication(login, password)
+ person = Person.authenticate(login, password)
unless person.nil?
if person.deactivated?
flash[:error] = "Your account has been deactivated"
View
@@ -35,7 +35,7 @@ class Person < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :name,
:description, :connection_notifications,
:message_notifications, :wall_comment_notifications,
- :blog_comment_notifications
+ :blog_comment_notifications, :identity_url
# Indexed fields for Sphinx
is_indexed :fields => [ 'name', 'description', 'deactivated',
'email_verified'],
@@ -391,6 +391,7 @@ def set_old_description
end
def log_activity_description_changed
+ debugger
unless @old_description == description or description.blank?
add_activities(:item => self, :person => self)
end
@@ -418,7 +419,7 @@ def connect_to_admin
## Other private method(s)
def password_required?
- crypted_password.blank? || !password.blank? || !verify_password.nil?
+ (crypted_password.blank? && identity_url.nil?) || !password.blank? || !verify_password.nil?
end
class << self
@@ -40,4 +40,4 @@
<%= submit_tag 'Sign up', :class => "button" %>
</div>
<% end %>
-<%- end -%>
+<%- end -%>
@@ -15,6 +15,15 @@
:maxlength => Person::MAX_PASSWORD %>
</div>
+ <p>
+ or use...
+ </p>
+
+ <div class="form_row">
+ <label for="openid_url">OpenID</label>
+ <%= text_field_tag "openid_url" %>
+ </div>
+
<div class="form_row">
<label for="remember_me" class="checkbox">Remember me:</label>
<%= check_box_tag 'remember_me', '1', true, :class => "checkbox" %>
@@ -29,4 +38,4 @@
<%= link_to "I forgot my password!", new_password_reminder_path %>
</p>
<% end -%>
-<%- end -%>
+<%- end -%>
@@ -16,4 +16,4 @@
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
-config.active_record.colorize_logging = true
+config.active_record.colorize_logging = true
View
@@ -5,6 +5,7 @@
map.resources :connections
map.resources :password_reminders
map.resources :photos
+ map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
map.resource :session
map.resources :messages, :collection => { :sent => :get, :trash => :get },
:member => { :reply => :get, :undestroy => :put }

0 comments on commit cbed595

Please sign in to comment.