Class: AuthController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/auth_controller.rb

Instance Method Summary collapse

Instance Method Details

#auth_formObject



103
104
105
106
107
# File 'app/controllers/auth_controller.rb', line 103

def auth_form  
  respond_to do |format|
    format.js { render :layout => false }
  end
end

#forgotObject



135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/auth_controller.rb', line 135

def forgot
  ActionMailer::Base.default_url_options[:host] = request.host
  
  @account = Account.find_by_email_address(params[:email])
  if not @account.nil?
    @account.generate_password
  else
    flash[:error_messages] = ["There's no account matching that email address.  Please try again, or sign up for an account."]
    redirect_to :action => :forgot_form
  end
end

#indexObject



6
7
8
9
10
# File 'app/controllers/auth_controller.rb', line 6

def index
  respond_to do |format|
    format.css { render :layout => false }
  end
end

#loginObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/auth_controller.rb', line 21

def 
  if request.post?
    unless @login.password or @login.have_password
      redirect_to :controller => "account", :action => "signup", :email => @login.email
    end
  end
  if request.post? and not logged_in?
    if (@login)
      
    end
  end
end

#logoutObject



159
160
161
162
# File 'app/controllers/auth_controller.rb', line 159

def logout
  reset_session
  redirect_to url_for("/")
end

#needs_personObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/auth_controller.rb', line 34

def needs_person
  @open_id_identity = OpenIdIdentity.find_or_create_by_identity_url(session[:identity_url])
  @person = Person.new
  if not AeUsers.profile_class.nil?
    @app_profile = AeUsers.profile_class.send(:new, :person => @person)
  end
  
  if params[:registration]
    person_map = HashWithIndifferentAccess.new(Person.sreg_map)
    profile_map = if AeUsers.profile_class and AeUsers.profile_class.respond_to?("sreg_map")
      HashWithIndifferentAccess.new(AeUsers.profile_class.sreg_map)
    else
      nil
    end
      
    params[:registration].each_pair do |key, value|
      if key == 'email'
        params[:email] = value
      elsif person_map.has_key?(key.to_s)
        mapper = person_map[key]
        attrs = mapper.call(value)
        @person.attributes = attrs
      elsif (profile_map and profile_map.has_key?(key))
        mapper = profile_map[key]
        @app_profile.attributes = mapper.call(value)
      end
    end
  end
  if params[:person]
    @person.attributes = params[:person]
  end
  if params[:app_profile] and @app_profile
    @app_profile.attributes = params[:app_profile]
  end
  
  if request.post?
    error_messages = []
    error_fields = []
    
    ["firstname", "lastname", "gender"].each do |field|
      if not @person.send(field)
        error_fields.push field
        error_messages.push "You must enter a value for #{field}."
      end
    end
    
    if not params[:email]
      error_fields.push("email")
      error_messages.push "You must enter a value for email."
    end
    
    if error_messages.length > 0
      flash[:error_fields] = error_fields
      flash[:error_messages] = error_messages
    else
      @person.save
      @person.primary_email_address = params[:email]
      @open_id_identity.person = @person
      @open_id_identity.save
      if @app_profile
        @app_profile.save
      end
      
      session[:person] = @person
      redirect_to session[:return_to]
    end
  end
end

#needs_profileObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/controllers/auth_controller.rb', line 109

def needs_profile
  @person = Person.find session[:provisional_person]
  if @person.nil?
    flash[:error_messages] = ["Couldn't find a person record with that ID.  
      Something may have gone wrong internally.  Please try again, and if the problem persists, please contact
      the site administrator."]
    redirect_to :back
  end
  
  if not AeUsers.
    flash[:error_messages] = ['Your account is not valid for this site.']
    redirect_to url_for("/")
  else
    if not AeUsers.profile_class.nil?
      @app_profile = AeUsers.profile_class.send(:new, :person_id => session[:provisional_person])
      @app_profile.attributes = params[:app_profile]
      
      if request.post?
        @app_profile.save
        session[:person] = @person
        redirect_to params[:return_to]
      end
    end
  end
end

#openid_loginObject



12
13
14
15
16
17
18
19
# File 'app/controllers/auth_controller.rb', line 12

def 
  params[:openid_url] ||= cookies['openid_url']    
  if using_open_id?
    if (@login.return_to)
      
    end
  end
end

#resend_validationObject



147
148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/auth_controller.rb', line 147

def resend_validation
  ActionMailer::Base.default_url_options[:host] = request.host
  
  @email_address = Account.find params[:email]
  if not @email_address.nil?
    @email_address.generate_validation
  else
    flash[:error_messages] = ["Email address #{params[:email]} not found!"]
    redirect_to url_for("/")
  end
end