13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/lean_cms/password_setup_controller.rb', line 13
def update
@user = @magic_link.user
if params[:password].blank?
flash.now[:alert] = "Password cannot be blank."
render :show, status: :unprocessable_entity
return
end
if params[:password] != params[:password_confirmation]
flash.now[:alert] = "Passwords do not match."
render :show, status: :unprocessable_entity
return
end
if params[:password].length < 8
flash.now[:alert] = "Password must be at least 8 characters."
render :show, status: :unprocessable_entity
return
end
@user.password = params[:password]
@user.password_confirmation = params[:password_confirmation]
@user.active = true
@user.must_change_password = false
if @user.save
@magic_link.mark_as_used!(request.remote_ip)
LeanCms::Session.where(user: @user).destroy_all
redirect_to lean_cms_new_session_path, notice: "Password set successfully. Please log in."
else
flash.now[:alert] = @user.errors.full_messages.join(", ")
render :show, status: :unprocessable_entity
end
end
|