Class: People::SignupController

Inherits:
ApplicationController
  • Object
show all
Includes:
AuthCheck
Defined in:
app/controllers/people/signup_controller.rb

Overview

COPYRIGHT:

Copyright (c) 2005-2009 North Carolina State University
Developed with funding for the National eXtension Initiative.

LICENSE:

BSD(-compatible)
see LICENSE file or view at http://about.extension.org/wiki/LICENSE

Constant Summary

Constant Summary

Constants included from AuthCheck

AuthCheck::AUTH_ACCOUNT_NOTVOUCHED, AuthCheck::AUTH_ACCOUNT_RETIRED, AuthCheck::AUTH_ACCOUNT_REVIEW, AuthCheck::AUTH_EMAIL_NOTCONFIRM, AuthCheck::AUTH_INVALID_APIKEY, AuthCheck::AUTH_INVALID_EMAIL, AuthCheck::AUTH_INVALID_ID, AuthCheck::AUTH_INVALID_PASSWORD, AuthCheck::AUTH_PASSWORD_EXPIRED, AuthCheck::AUTH_SIGNUP_CONFIRM, AuthCheck::AUTH_SUCCESS, AuthCheck::AUTH_UNKNOWN

Instance Method Summary (collapse)

Methods included from AuthCheck

#authlogmsg, #authuser, #checkidstring_for_openid, #explainauthresult, #statuscheck

Instance Method Details

- (Object) confirm



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/controllers/people/signup_controller.rb', line 167

def confirm
  if(@currentuser. != User::STATUS_SIGNUP)
    return redirect_to(people_welcome_url) 
  end
  
  if(params[:token].nil?)
    return render(:template => 'people/signup/confirm')
  end
  
  if (params[:token] == 'send')
    flash[:success] = "Resent Signup Confirmation"          
    @currentuser.
    return redirect_to(:controller => 'signup', :action => 'confirmationsent')      
  end
  
  @token = UserToken.find_by_token(params[:token])
  if ((@token.nil?) or (@token.user != @currentuser) or @token.tokentype != UserToken::SIGNUP)
    flash[:failure] = "Invalid token."
    return redirect_to(:controller => 'signup', :action => 'reconfirm', :reason => 'invalidtoken')
  elsif(@token.token_expired?)
    flash[:failure] = "Token expired."          
    return redirect_to(:controller => 'signup', :action => 'reconfirm', :reason => 'expiredtoken')
  else
    @currentuser.(@token)
    if (@currentuser.vouched?)
      if(!@currentuser.additionaldata.nil? and !@currentuser.additionaldata[:signup_institution_id].nil?)
        @currentuser.change_profile_community(Community.find(@currentuser.additionaldata[:signup_institution_id]))
      end       
      Notification.create(:notifytype => Notification::WELCOME, :account => @currentuser, :send_on_create => true)
      return redirect_to(people_welcome_url)
    else
      # create a support widget question
      @currentuser.
      return redirect_to(:controller => 'signup', :action => 'review')
    end
  end    
end

- (Object) confirmationsent



206
207
# File 'app/controllers/people/signup_controller.rb', line 206

def confirmationsent
end

- (Object) create



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
102
103
104
105
106
107
108
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/controllers/people/signup_controller.rb', line 67

def create
  if(!request.post?)
    return redirect_to(:action => :new)
  end
  
  if(!params[:invite].nil?)
    @invitation = Invitation.find_by_token(params[:invite])
  end
  
  # search for an existing account.  doing this here instead
  # of validations because of historical presence of 'PublicUser'
  # accounts - this will be removed when People is separated
  if(params[:user] and params[:user][:email])
    checkemail = params[:user][:email]
    if( = Account.find_by_email(checkemail))
      # has existing user account
      failuremsg = "Your email address has already been registered with us.  If you've forgotten your password for that account, please <a href='#{url_for(:controller => 'people/account', :action => :new_password)}'>request a new password</a>"
      flash.now[:failure] = failuremsg
      @user = User.new(params[:user])          
      @locations = Location.displaylist
      if(!(@user.location.nil?))  
        @countylist = @user.location.counties
        @institutionlist = @user.location.communities.institutions.find(:all, :order => 'name')
      end
      return render(:action => "new")
    else
      @user = User.new(params[:user])
    end
  end

  # institution?
  if(!params[:primary_institution_id].nil? and params[:primary_institution_id] != 0)
    @user.additionaldata = {} if @user.additionaldata.nil?
    @user.additionaldata.merge!({:signup_institution_id => params[:primary_institution_id]})
  end
  
  # affiliation/involvement?
  if(!params[:signup_affiliation].blank?)
    @user.additionaldata = {} if @user.additionaldata.nil?
    @user.additionaldata.merge!({:signup_affiliation => Hpricot(params[:signup_affiliation].sanitize).to_html})
  else
    flash.now[:failure] = "Please let us know how you are involved with Cooperative Extension"
    @locations = Location.displaylist
    return render(:action => "new")
  end
      
  # STATUS_SIGNUP
  @user. = User::STATUS_SIGNUP
  
  # last login at == now
  @user. = Time.zone.now
  
  begin
    didsave = @user.save
  rescue ActiveRecord::StatementInvalid => e
    if(!(e.to_s =~ /duplicate/i))
      raise
    end
  end
  
  if(!didsave)        
    if(!@user.errors.on(:email).nil? and @user.errors.on(:email) == 'has already been taken')
      failuremsg = "Your email address has already been registered with us.  If you've forgotten your password for that account, please <a href='#{url_for(:controller => 'people/account', :action => :new_password)}'>request a new password</a>"
      flash.now[:failure] = failuremsg
    elsif(!@user.errors.empty?)
      failuremsg = "<h3>There were errors that prevented signup</h3>"
      failuremsg += "<ul>"
      @user.errors.each { |value,msg|
        if (value == 'login')
          failuremsg += "<li>That eXtensionID #{msg}</li>"
        else
          failuremsg += "<li>#{value} - #{msg}</li>"
        end
      }
      failuremsg += "</ul>"          
      flash.now[:failurelist] = failuremsg
    end
    @locations = Location.displaylist
    if(!(@user.location.nil?))  
      @countylist = @user.location.counties
      @institutionlist = @user.location.communities.institutions.find(:all, :order => 'name')
    end
    
    render(:action => "new")
  else        
    # automatically log them in
    @currentuser = User.find_by_id(@user.id)
    session[:userid] = @currentuser.id
    session[:account_id] = @currentuser.id
    signupdata = {}     
    if(@invitation)
      signupdata.merge!({:invitation => @invitation})
    end
    UserEvent.log_event(:etype => UserEvent::PROFILE,:user => @currentuser,:description => "initialsignup")
    @currentuser.(signupdata)
    return redirect_to(:action => :confirmationsent)
  end
end

- (Object) new



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
# File 'app/controllers/people/signup_controller.rb', line 39

def new
  if(!request.post?)
    return redirect_to(:action => 'readme', :invite => params[:invite])
  end
  
  # just in case we got here from an openid login
  session[:last_opierequest] = nil
  
  if(!params[:invite].nil?)
    @invitation = Invitation.find_by_token(params[:invite])
  end
  
  if params[:user]
    @user = User.new(params[:user])
  else
    @user = User.new
  end
  
  @locations = Location.displaylist
  if(!(@user.location.nil?))  
    @countylist = @user.location.counties
  end
  
  respond_to do |format|
    format.html # new.html.erb
  end
end

- (Object) postsignup



213
214
# File 'app/controllers/people/signup_controller.rb', line 213

def postsignup
end

- (Object) readme



13
14
15
16
17
18
19
20
# File 'app/controllers/people/signup_controller.rb', line 13

def readme
  # just in case we got here from an openid login
  session[:last_opierequest] = nil
   
  if(!params[:invite].nil?)
    @invitation = Invitation.find_by_token(params[:invite])
  end
end

- (Object) reconfirm



209
210
211
# File 'app/controllers/people/signup_controller.rb', line 209

def reconfirm
  @reason = params[:reason]
end

- (Object) review



216
217
# File 'app/controllers/people/signup_controller.rb', line 216

def review
end

- (Object) xhr_county_and_institution



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/people/signup_controller.rb', line 22

def xhr_county_and_institution
  if(!request.post?)
    return redirect_to(:action => :new)
  end
  @user = @currentuser
  if(!params[:location].nil? and params[:location] != "")
    selected_location = Location.find(:first, :conditions => ["id = ?", params[:location]])	  
    @countylist = selected_location.counties
    @institutionlist = selected_location.communities.institutions.find(:all, :order => 'name')
  end

  render(:update) do |page|
      page.replace_html  :county, :partial => 'county', :locals => {:countylist => @countylist}
      page.replace_html  :institution, :partial => 'institutionlist', :locals => {:institutionlist => @institutionlist}
  end    
end