Class: Goldberg::UsersController
Instance Method Summary
collapse
Methods included from Controller
included
#copy, #six_local_auto_login
#active_scaffold_render_secure_download, #assign_names_with_active_scaffold, #render_with_active_scaffold, #search_generic_view_paths?
Instance Method Details
#confirm_registration ⇒ Object
Invoked when a user clicks on a link in a self-registration email. Displays a form where the user can enter their username and password.
112
113
114
115
116
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 112
def confirm_registration
@user = User.find_by_confirmation_key(params[:id])
@user or flash.now[:error] = 'Sorry, but there is no such confirmation required.'
render :action => 'confirm_registration'
end
|
#confirm_registration_submit ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 118
def confirm_registration_submit
@user = User.find(params[:id])
if @user and @user.self_reg_confirmation_required and
@user.confirmation_key == params[:user][:confirmation_key] and
@user.check_password(params[:user][:clear_password])
@user.self_reg_confirmation_required = false
@user.confirmation_key = nil
if @user.save
flash.now[:notice] = 'Registration confirmed.'
AuthController.set_user(session, @user.id)
render :action => 'confirm_registration_submit'
else
flash.now[:error] = 'Could not save confirmation!'
render :action => 'confirm_registration'
end
else
flash.now[:error] = 'Self-registration confirmation invalid!'
render :action => 'confirm_registration'
end
end
|
#create ⇒ Object
Also known as:
self_create, delegate_create
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
102
103
104
105
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 65
def create
@user = User.new(params[:user])
if @self_reg
@user.role_id = Goldberg.settings.self_reg_role_id
@user.self_reg_confirmation_required =
Goldberg.settings.self_reg_confirmation_required
if Goldberg.settings.self_reg_send_confirmation_email
if not @user.email_valid?
flash.now[:error] = 'A valid email address is required!'
render :action => 'new'
return
end
end
end
if params[:user][:clear_password].length == 0 or
params[:user][:confirm_password] != params[:user][:clear_password]
flash.now[:error] = 'Password invalid!'
render :action => 'new'
else
if @user.save
flash.now[:notice] = 'User was successfully created.'
if @self_reg
if Goldberg.settings.self_reg_confirmation_required
if Goldberg.settings.self_reg_send_confirmation_email
confirm_email = UserMailer.create_confirmation_request(@user)
UserMailer.deliver(confirm_email)
end
render :action => 'create'
else
AuthController.set_user(session, @user.id)
redirect_to @user.get_start_path
end
else
redirect_to :action => 'list'
end
else
render :action => 'new'
end
end
end
|
#destroy ⇒ Object
Also known as:
delegate_destroy
195
196
197
198
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 195
def destroy
User.find(params[:id]).destroy
redirect_to :action => 'list'
end
|
#edit ⇒ Object
Also known as:
self_edit, delegate_edit
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 142
def edit
if @self_reg
@user = Goldberg.user
else
@user = User.find(params[:id])
end
if @user
if @user.role_id
@role = Role.find(@user.role_id)
end
render :action => 'edit'
else
render :nothing => true
end
end
|
#forgot_password ⇒ Object
201
202
203
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 201
def forgot_password
render :action => 'forgot_password'
end
|
#forgot_password_submit ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 205
def forgot_password_submit
@user = User.find_by_name_and_email(params[:user][:name],
params[:user][:email])
if @user
if (not @user.self_reg_confirmation_required)
@user.set_confirmation_key
if @user.save
reset_email = UserMailer.create_reset_password_request(@user)
UserMailer.deliver(reset_email)
render :action => 'forgot_password_submit'
else
render :action => 'forgot_password'
end
else
flash.now[:error] = "You can't reset your password because your account is not yet confirmed."
render :action => 'forgot_password'
end
else
flash.now[:error] = "No such user/email."
render :action => 'forgot_password'
end
end
|
#list ⇒ Object
Also known as:
delegate_list
27
28
29
30
31
32
33
34
35
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 27
def list
if @delegate_reg
conditions = ['role_id in (?)', Goldberg.credentials.role_ids]
else
conditions = nil
end
@users = User.find(:all, :conditions => conditions, :order => 'name')
render :action => 'list'
end
|
#new ⇒ Object
Also known as:
self_register, delegate_register
58
59
60
61
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 58
def new
@user = User.new
render :action => 'new'
end
|
#reset_password ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 229
def reset_password
@user = User.find_by_confirmation_key(params[:id])
if @user
render :action => 'reset_password'
else
flash.now[:error] = 'Sorry, but we received no such password reset request.'
render :action => 'forgot_password'
end
end
|
#reset_password_submit ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 241
def reset_password_submit
@user = User.find_by_confirmation_key(params[:id])
if @user
if (not @user.self_reg_confirmation_required)
password = @user.class.random_password
@user.clear_password = password
@user.password_expired = true
if @user.save
password_email = UserMailer.create_reset_password(@user, password)
UserMailer.deliver(password_email)
render :action => 'reset_password_submit'
else
render :action => 'reset_password'
end
else
flash.now[:error] = "You can't reset your password because your account is not yet confirmed."
render :action => 'forgot_password'
end
else
flash.now[:error] = "No such password reset request for user."
render :action => 'forgot_password'
end
end
|
#show ⇒ Object
Also known as:
self_show, delegate_show
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 38
def show
if @self_reg
@user = Goldberg.user
else
@user = User.find(params[:id])
end
if @user
if @user.role_id
@role = Role.find(@user.role_id)
else
@role = Role.new(:id => nil, :name => '(none)')
end
render :action => 'show'
else
render :nothing => true
end
end
|
#update ⇒ Object
Also known as:
self_update, delegate_update
160
161
162
163
164
165
166
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
|
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/controllers/goldberg/users_controller.rb', line 160
def update
if @self_reg
@user = Goldberg.user
else
@user = User.find(params[:id])
end
if @user
if params[:user]['clear_password'] == ''
params[:user].delete('clear_password')
end
if @self_reg
params[:user][:role_id] = @user.role_id
end
if params[:user][:clear_password] and
params[:user][:clear_password].length > 0 and
params[:user][:confirm_password] != params[:user][:clear_password]
flash.now[:error] = 'Password invalid!'
render :action => 'edit'
else
if @user.update_attributes(params[:user])
flash.now[:notice] = 'User was successfully updated.'
redirect_to :action => (@self_reg ? 'self_show' : 'show'),
:id => @user
else
render :action => 'edit'
end
end
end end
|