I've got somewhat of a unique scenario that I can't quite figure out.
I am tying a CommunityEngine based site to another member/CRM system
for authentication & populating some of the user data.

First of all, I've read the comments about bypassing validation on the
User model (http://groups.google.com/group/communityengine/
browse_thread/thread/f96ec80c4cfff7a8/efa9ac7a6226efbc?
lnk=gst&q=validate#efa9ac7a6226efbc) and have the following User model
(with the remove() method in an Initializer):

-----

class User < ActiveRecord::Base

  after_validation :custom_validations

  def custom_validations
    self.errors.remove(:login)
    self.errors.remove(:password)
    self.errors.remove(:password_confirmation)
    self.errors.remove(:birthday)
  end

end

-----

Next, I've added my own custom SessionsController to change the actual
login logic a bit.  Basically, instead of authenticating against the
CommunityEngine DB, I want the authenticate using another web
service.  If the web service login is successful, then I check to see
if the user exists in the CommunityEngine DB yet.  If not, I need to
create a new User and populate it with the data that came back from
the web service call, then create a UserSession with the newly created
user.

As you can imagine, the validations are preventing me from saving the
new user, even though I've cleared out all the errors in the errors
hash with the code above.

Here is my SessionsController with some of the external web service
code removed for brevity:

-----

class SessionsController < BaseController
  def create

    (Some code removed here for brevity, but basically I'm calling an
external web service here for authentication)
    portal_login_result =
security_service_client.portal_login(params[:login],
params[:password])

    if portal_login_result[:success]
      # Portal log in worked. First try to see if this user exists in
      # the CommunityEngine DB already..
      attempted_record =
User.find_by_smart_case_login_field(params[:login])
      if attempted_record.blank?
        # This user is not in the CommunityEngine DB yet so we'll add
them here.
        @user = User.new
        portal_login_result[:user][:fields]
[:key_value_ofstringany_type].each { |f|
          case f[:key]
          when 'LoginID'
            @user.login = f[:value]
            #            @user.login_slug = f[:value]
          when 'FirstName'
          when 'LastName'
          when 'Email'
            @user.email = f[:value]
          when 'TimeZone'
          when 'Comments'
            @user.description = f[:value]
          when 'CreatedDate'
          when 'Guid'
          when 'Entity_Guid'
          end
        }

        @user.role  = Role[:member]

        if @user.save
          @user_session = UserSession.new(@user, :remember_me =>
params[:remember_me])
          if @user_session.save

            current_user = @user_session.record #if current_user has
been called before this, it will ne nil, so we have to make to reset
it

            flash[:notice] = :thanks_youre_now_logged_in.l
            #
redirect_back_or_default(dashboard_user_path(current_user))
            redirect_to dashboard_user_path(current_user)
          else
            flash[:notice]
= 
:uh_oh_we_couldnt_log_you_in_with_the_username_and_password_you_entered_try_again.l
            redirect_to teaser_path and return if
AppConfig.closed_beta_mode
            render :action => :new
          end
        else
          flash[:notice]
= 
:uh_oh_we_couldnt_log_you_in_with_the_username_and_password_you_entered_try_again.l
          redirect_to teaser_path and return if
AppConfig.closed_beta_mode
          render :action => :new
        end
      else

      end
    else
      # Portal log in failed.
      flash[:notice]
= 
:uh_oh_we_couldnt_log_you_in_with_the_username_and_password_you_entered_try_again.l
      redirect_to teaser_path and return if AppConfig.closed_beta_mode
      render :action => :new
    end


  end
end

-----

So basically, the code putters out when I call @user.save .... also,
if I call @user.valid? it returns false.  I just can't figure out
*what* is making it invalid since I've removed all the errors from the
errors hash.

Does anyone see something I'm missing or have any ideas?

Thanks,
Tony

-- 
You received this message because you are subscribed to the Google Groups 
"CommunityEngine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/communityengine?hl=en.

Reply via email to