Permalink
Browse files

allow openid registration to recover from validation errors from simp…

…le registration info
  • Loading branch information...
herestomwiththeweather committed Sep 10, 2008
1 parent 7d06a62 commit 1652833b0b0246832cd4da27573242f73a73ae17
@@ -43,8 +43,10 @@ def create
@person = Person.new(params[:person])
respond_to do |format|
@person.email_verified = false if global_prefs.email_verifications?
+ @person.identity_url = session[:verified_identity_url]
@person.save
if @person.errors.empty?
+ session[:verified_identity_url] = nil
if global_prefs.email_verifications?
@person.email_verifications.create
flash[:notice] = %(Thanks for signing up! Check your email
@@ -57,7 +59,12 @@ def create
end
else
@body = "register single-col"
- format.html { render :action => 'new' }
+ format.html { if @person.identity_url.blank?
+ render :action => 'new'
+ else
+ render :partial => "shared/personal_details.html.erb", :object => @person, :layout => 'application'
+ end
+ }
end
end
rescue ActiveRecord::StatementInvalid
@@ -17,29 +17,45 @@ def create
def open_id_authentication(openid_url)
authenticate_with_open_id(openid_url, :required => [:nickname, :email]) do |result, identity_url, registration|
- if result.successful?
+ if !result.successful?
+ failed_login result.message
+ else
@person = Person.find_or_initialize_by_identity_url(identity_url)
if @person.new_record?
+ @person.email_verified = false if global_prefs.email_verifications?
@person.name = registration['nickname']
@person.email = registration['email']
- # XXX for now, don't mess with email verification for openid guys
- @person.email_verified = true if global_prefs.email_verifications?
+
@person.save
if !@person.errors.empty?
err_message = "The following problems exist with your OpenID profile:<br>"
- @person.errors.each do |attr,val|
- logger.warn "XXX #{attr}:#{val}"
- err_message += "#{attr}: #{val}<br>"
+ @person.errors.each do |attr,val|
+ logger.warn "open_id_authentication() Error: #{attr}:#{val}"
+ err_message += "#{attr}: #{val}<br>"
end
-
- failed_login err_message.chop
- return
+
+ flash[:error] = err_message.chop
+ @body = "login single-col"
+ session[:verified_identity_url] = identity_url
+ render :partial => "shared/personal_details.html.erb", :object => @person, :layout => 'application'
+ elsif global_prefs.email_verifications?
+ @person.email_verifications.create
+ flash[:notice] = %(Thanks for signing up! Check your email
+ to activate your account.)
+ redirect_to(home_url)
+ else
+ successful_login("Thanks for signing up!")
end
+
+ return
+ end # if new record
+
+ if @person.deactivated?
+ flash[:error] = "Your account has been deactivated"
+ redirect_to home_url and return
end
- self.current_person = @person
+
successful_login
- else
- failed_login result.message
end
end
end
@@ -50,13 +66,14 @@ def failed_login(message = "Authentication failed.")
render :action => 'new'
end
- def successful_login
+ def successful_login(message = "Logged in successfully")
+ self.current_person = @person
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"
+ flash[:notice] = message
end
def password_authentication(login, password)
View
@@ -101,6 +101,7 @@ class Person < ActiveRecord::Base
:with => EMAIL_REGEX,
:message => "must be a valid email address"
validates_uniqueness_of :email
+ validates_uniqueness_of :identity_url, :allow_nil => true
before_create :create_blog
before_save :encrypt_password
@@ -391,7 +392,6 @@ 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
@@ -77,6 +77,6 @@
<div><%= render :partial => 'shared/debug' %></div>
<%- end -%>
</div>
- <%= global_prefs.analytics %>
+ <%= global_prefs.analytics %>
</body>
</html>
@@ -0,0 +1,28 @@
+<%- column_div :type => :primary do -%>
+ <h2>Edit Personal Info</h2>
+
+ <%= error_messages_for :personal_details %>
+
+ <% form_for personal_details do |f| -%>
+
+ <div class="form_row">
+ <label for="email">
+ Email address <span class="small">(never made
+ public<%= ", will be verified" if global_prefs.email_verifications? %>)
+ </span>
+ </label>
+ <%= f.text_field :email, :maxlength => Person::MAX_EMAIL %>
+ <%= set_focus_to_id "person_email" %>
+ </div>
+
+ <div class="form_row">
+ <label for="name">Name
+ <span class="small">(will be displayed)</span></label>
+ <%= f.text_field :name, :maxlength => Person::MAX_NAME %>
+ </div>
+
+ <div class="form_row">
+ <%= submit_tag 'Sign up', :class => "button" %>
+ </div>
+ <% end %>
+<%- end -%>

0 comments on commit 1652833

Please sign in to comment.