Class: UsersController
Instance Method Summary
collapse
#get_login_link, #set_locale_with_config
Instance Method Details
#activate ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/users_controller.rb', line 58
def activate
unless params[:activation_code].blank?
user = User.find_by_perishable_token(params[:activation_code])
if user
if user.active?
flash[:warning] = I18n.t('already_active', :scope => [:user, :activate])
return redirect_to(:root)
end
user.activate
user.reset_perishable_token!
PersonSession.create(user, true)
flash[:notice] = I18n.t('success', :scope => [:user, :activate])
return redirect_to(:action => :show)
end
end
flash[:error] = I18n.t('error', :scope => [:user, :activate])
redirect_to(:root)
end
|
#create ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/users_controller.rb', line 28
def create
cookies.delete :auth_token
@user = User.new(params[:user])
password = params[:user][:password]
if (not Forgeos::CONFIG[:account]['checkout_quick_create'] or not password) and Forgeos::CONFIG[:account]['password_generated']
password = generate_password(10)
@user.email_confirmation = @user.email if @user.respond_to?('email_confirmation=')
@user.password = password
@user.password_confirmation = password
end
if @user.save
if @generated_password
Notifier.deliver_validation_user_account(@user, password)
else
@user.activate
PersonSession.create(@user,true)
end
flash[:notice] = I18n.t('success', :scope => [:user, :create])
redirect_to_stored_location(login_path)
else
Rails.logger.info("\033[01;33m#{@user.errors.inspect}\033[0m")
if @user.errors.on(:civility)
flash[:error] = 'Veuillez préciser votre civilité'
else
flash[:error] = I18n.t('error', :scope => [:user, :create])
end
render :action => 'new'
end
end
|
#forgotten_password ⇒ Object
86
87
|
# File 'app/controllers/users_controller.rb', line 86
def forgotten_password
end
|
#new ⇒ Object
24
25
26
|
# File 'app/controllers/users_controller.rb', line 24
def new
@user = User.new(params[:user])
end
|
#new_password ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/users_controller.rb', line 104
def new_password
@user = User.find_by_perishable_token(params[:user_token])
unless @user
flash[:error] = I18n.t('error', :scope => [:user, :new_password])
redirect_to(:root)
end
@user.activate
@user.reset_perishable_token!
end
|
#reset_password ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/users_controller.rb', line 89
def reset_password
user = User.find_by_email(params[:email])
unless user
flash[:warning] = I18n.t('unknown_user', :scope => [:user, :reset_password], :email => params[:email])
return redirect_to(:action => :forgotten_password)
end
begin
Notifier.deliver_reset_password(user)
flash[:notice] = I18n.t('success', :scope => [:user, :reset_password])
rescue StandardError
flash[:error] = I18n.t('error', :scope => [:user, :reset_password])
end
redirect_to(:root)
end
|
#show ⇒ Object
21
22
|
# File 'app/controllers/users_controller.rb', line 21
def show
end
|
#update ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'app/controllers/users_controller.rb', line 77
def update
if @user.update_attributes(params[:user])
flash[:notice] = I18n.t('success', :scope => [:user, :update])
else
flash[:error] = I18n.t('error', :scope => [:user, :update])
end
render(:action => :show)
end
|
#update_password ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'app/controllers/users_controller.rb', line 114
def update_password
@user = User.find_by_perishable_token(params[:user_token])
unless @user
flash[:error] = I18n.t('error', :scope => [:user, :new_password])
redirect_to(:root)
end
@user.reset_perishable_token!
if @user.update_attributes(params[:user].reject{|k, v| !k.to_s.match(/^password/)})
flash[:notice] = I18n.t('success', :scope => [:user, :update])
redirect_to(login_path)
else
flash[:error] = I18n.t('error', :scope => [:user, :update])
render(:action => :new_password)
end
end
|