lato 0.1.25 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/config/lato_manifest.js +2 -2
- data/app/controllers/lato/account_controller.rb +3 -3
- data/app/controllers/lato/application_controller.rb +22 -1
- data/app/controllers/lato/authentication_controller.rb +67 -10
- data/app/helpers/lato/application_helper.rb +7 -0
- data/app/helpers/lato/components_helper.rb +8 -2
- data/app/jobs/lato/application_job.rb +3 -1
- data/app/mailers/lato/invitation_mailer.rb +21 -0
- data/app/mailers/lato/user_mailer.rb +12 -0
- data/app/models/lato/invitation.rb +82 -0
- data/app/models/lato/log/user_signin.rb +8 -0
- data/app/models/lato/log.rb +14 -0
- data/app/models/lato/operation.rb +7 -1
- data/app/models/lato/user.rb +53 -20
- data/app/views/lato/account/_alert-accepted-privacy-policy-version.html.erb +5 -3
- data/app/views/lato/account/_alert-accepted-terms-and-conditions-version.html.erb +5 -3
- data/app/views/lato/account/_form-destroy.html.erb +2 -2
- data/app/views/lato/account/_form-password.html.erb +3 -3
- data/app/views/lato/account/_form-user.html.erb +3 -3
- data/app/views/lato/account/index.html.erb +7 -8
- data/app/views/lato/authentication/_fields-registration.html.erb +37 -0
- data/app/views/lato/authentication/_form-accept-invitation.html.erb +18 -0
- data/app/views/lato/authentication/_form-recover-password.html.erb +1 -1
- data/app/views/lato/authentication/_form-signin.html.erb +2 -2
- data/app/views/lato/authentication/_form-signup.html.erb +2 -32
- data/app/views/lato/authentication/_form-update-password.html.erb +4 -4
- data/app/views/lato/authentication/accept_invitation.html.erb +10 -0
- data/app/views/lato/authentication/recover_password.html.erb +2 -2
- data/app/views/lato/authentication/signin.html.erb +2 -2
- data/app/views/lato/authentication/signout.html.erb +3 -3
- data/app/views/lato/authentication/signup.html.erb +2 -2
- data/app/views/lato/authentication/update_password.html.erb +2 -2
- data/app/views/lato/components/_index.html.erb +50 -23
- data/app/views/lato/components/_navbar_nav_locales_item.html.erb +8 -0
- data/app/views/lato/mailer/invitation/invite_mail.html.erb +17 -0
- data/app/views/lato/mailer/user/email_verification_mail.html.erb +17 -1
- data/app/views/lato/mailer/user/password_update_mail.html.erb +17 -1
- data/app/views/layouts/lato/_feedbacks.html.erb +16 -1
- data/app/views/layouts/lato/_footer.html.erb +2 -2
- data/app/views/layouts/lato/_mailer-head_content.html.erb +7 -2
- data/app/views/layouts/lato/_navbar-nav_content.html.erb +6 -4
- data/app/views/layouts/lato/application.html.erb +3 -0
- data/config/importmap.rb +2 -5
- data/config/locales/en.yml +47 -1
- data/config/locales/it.yml +50 -1
- data/config/routes.rb +4 -0
- data/db/migrate/20221229233844_add_locale_to_lato_user.rb +5 -0
- data/db/migrate/20230109054412_create_lato_log_user_signins.rb +10 -0
- data/db/migrate/20230109061533_create_lato_invitations.rb +11 -0
- data/lib/lato/btstrap.rb +1 -1
- data/lib/lato/config.rb +2 -2
- data/lib/lato/version.rb +1 -1
- data/lib/tasks/lato_tasks.rake +3 -1
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d39edbfb4463841b8aae209b67bde25c3c7a49dd98020185c9ac2e75b2571bc6
|
4
|
+
data.tar.gz: 594d67d40286bfe453c05b2625f891fa3f8fff78ad44f26b6520a89ad9f1d7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cdeaedaf49f9e0efb6d53035fbbdcb4eeed8d0256e34ce54fc36073478f92592dd486e63144b8a4dab534f74953124e53698b01af2a1df93fd35ccfa206e1ce
|
7
|
+
data.tar.gz: 61e8ed6e0ec07edac2b9b8f115bb579dab182fff4c32ddacb48c24f0bbae78056f4d32fbc997c547850e301755e60688438e029226b05c4fcfd2436858e55527
|
data/README.md
CHANGED
@@ -59,12 +59,12 @@ import "lato/application";
|
|
59
59
|
// ....
|
60
60
|
```
|
61
61
|
|
62
|
-
Setup
|
62
|
+
Setup I18n on the **config/application.rb** file:
|
63
63
|
|
64
64
|
```ruby
|
65
65
|
module MyApplication
|
66
66
|
class Application < Rails::Application
|
67
|
-
config.i18n.available_locales = [:it]
|
67
|
+
config.i18n.available_locales = [:it, :en]
|
68
68
|
config.i18n.default_locale = :it
|
69
69
|
|
70
70
|
# ...
|
@@ -8,7 +8,7 @@ module Lato
|
|
8
8
|
def update_user_action
|
9
9
|
respond_to do |format|
|
10
10
|
if @session.user.update(params.require(:user).permit(:first_name, :last_name, :email))
|
11
|
-
format.html { redirect_to lato.account_path, notice: '
|
11
|
+
format.html { redirect_to lato.account_path, notice: I18n.t('lato.account_controller.update_user_action_notice') }
|
12
12
|
format.json { render json: @session.user }
|
13
13
|
else
|
14
14
|
format.html { render :index, status: :unprocessable_entity }
|
@@ -20,7 +20,7 @@ module Lato
|
|
20
20
|
def request_verify_email_action
|
21
21
|
respond_to do |format|
|
22
22
|
if @session.user.request_verify_email
|
23
|
-
format.html { redirect_to lato.account_path, notice: '
|
23
|
+
format.html { redirect_to lato.account_path, notice: I18n.t('lato.account_controller.request_verify_email_action_notice') }
|
24
24
|
format.json { render json: @session.user }
|
25
25
|
else
|
26
26
|
format.html { render :index, status: :unprocessable_entity }
|
@@ -32,7 +32,7 @@ module Lato
|
|
32
32
|
def update_password_action
|
33
33
|
respond_to do |format|
|
34
34
|
if @session.user.update(params.require(:user).permit(:password, :password_confirmation))
|
35
|
-
format.html { redirect_to lato.account_path, notice: '
|
35
|
+
format.html { redirect_to lato.account_path, notice: I18n.t('lato.account_controller.update_password_action_notice') }
|
36
36
|
format.json { render json: @session.user }
|
37
37
|
else
|
38
38
|
format.html { render :index, status: :unprocessable_entity }
|
@@ -4,18 +4,39 @@ module Lato
|
|
4
4
|
include Lato::Layoutable
|
5
5
|
include Lato::Componentable
|
6
6
|
|
7
|
+
before_action :set_default_locale
|
8
|
+
|
7
9
|
def index
|
8
10
|
session_root_path = Lato.config.session_root_path ? main_app.send(Lato.config.session_root_path) : lato.account_path
|
9
11
|
redirect_to @session.valid? ? session_root_path : lato.authentication_signin_path
|
10
12
|
end
|
11
13
|
|
14
|
+
def switch_locale
|
15
|
+
I18n.locale = params[:locale]
|
16
|
+
@session.user.update(locale: params[:locale]) if @session.valid?
|
17
|
+
respond_to_redirect_same_page
|
18
|
+
end
|
19
|
+
|
12
20
|
protected
|
13
21
|
|
14
|
-
def
|
22
|
+
def set_default_locale
|
23
|
+
return unless @session.valid?
|
24
|
+
|
25
|
+
I18n.locale = @session.user.locale || I18n.default_locale
|
26
|
+
end
|
27
|
+
|
28
|
+
def respond_to_with_not_found
|
15
29
|
respond_to do |format|
|
16
30
|
format.html { render plain: '', status: :not_found }
|
17
31
|
format.json { render json: {}, status: :not_found }
|
18
32
|
end
|
19
33
|
end
|
34
|
+
|
35
|
+
def respond_to_redirect_same_page(notice = nil)
|
36
|
+
respond_to do |format|
|
37
|
+
format.html { redirect_to request.referer, notice: notice }
|
38
|
+
format.json { render json: {} }
|
39
|
+
end
|
40
|
+
end
|
20
41
|
end
|
21
42
|
end
|
@@ -1,12 +1,19 @@
|
|
1
1
|
module Lato
|
2
2
|
class AuthenticationController < ApplicationController
|
3
|
-
before_action :not_authenticate_session, only: %i[signin signin_action signup signup_action]
|
3
|
+
before_action :not_authenticate_session, only: %i[signin signin_action signup signup_action accept_invitation accept_invitation_action]
|
4
4
|
before_action :authenticate_session, only: %i[signout signout_action]
|
5
|
+
|
5
6
|
before_action :find_user, only: %i[verify_email verify_email_action update_password update_password_action]
|
6
|
-
before_action :
|
7
|
+
before_action :find_invitation, only: %i[accept_invitation accept_invitation_action]
|
8
|
+
|
7
9
|
before_action :lock_signup_if_disabled, only: %i[signup signup_action]
|
8
10
|
before_action :lock_recover_password_if_disabled, only: %i[recover_password recover_password_action update_password update_password_action]
|
9
11
|
|
12
|
+
before_action :hide_sidebar
|
13
|
+
|
14
|
+
# Signin
|
15
|
+
##
|
16
|
+
|
10
17
|
def signin
|
11
18
|
@user = Lato::User.new
|
12
19
|
end
|
@@ -15,7 +22,10 @@ module Lato
|
|
15
22
|
@user = Lato::User.new
|
16
23
|
|
17
24
|
respond_to do |format|
|
18
|
-
if @user.signin(params.require(:user).permit(:email, :password)
|
25
|
+
if @user.signin(params.require(:user).permit(:email, :password).merge(
|
26
|
+
ip_address: request.remote_ip,
|
27
|
+
user_agent: request.user_agent
|
28
|
+
))
|
19
29
|
session_create(@user.id)
|
20
30
|
|
21
31
|
format.html { redirect_to lato.root_path }
|
@@ -27,12 +37,15 @@ module Lato
|
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
40
|
+
# Signup
|
41
|
+
##
|
42
|
+
|
30
43
|
def signup
|
31
44
|
@user = Lato::User.new
|
32
45
|
end
|
33
46
|
|
34
47
|
def signup_action
|
35
|
-
@user = Lato::User.new(
|
48
|
+
@user = Lato::User.new(registration_params)
|
36
49
|
|
37
50
|
respond_to do |format|
|
38
51
|
if @user.save
|
@@ -47,6 +60,9 @@ module Lato
|
|
47
60
|
end
|
48
61
|
end
|
49
62
|
|
63
|
+
# Signout
|
64
|
+
##
|
65
|
+
|
50
66
|
def signout; end
|
51
67
|
|
52
68
|
def signout_action
|
@@ -54,10 +70,13 @@ module Lato
|
|
54
70
|
|
55
71
|
respond_to do |format|
|
56
72
|
format.html { redirect_to lato.root_path }
|
57
|
-
format.json { render
|
73
|
+
format.json { render json: {} }
|
58
74
|
end
|
59
75
|
end
|
60
76
|
|
77
|
+
# Verify email
|
78
|
+
##
|
79
|
+
|
61
80
|
def verify_email
|
62
81
|
@code = params[:code]
|
63
82
|
end
|
@@ -65,7 +84,7 @@ module Lato
|
|
65
84
|
def verify_email_action
|
66
85
|
respond_to do |format|
|
67
86
|
if @user.verify_email(params.require(:user).permit(:code))
|
68
|
-
format.html { redirect_to lato.root_path, notice: '
|
87
|
+
format.html { redirect_to lato.root_path, notice: I18n.t('lato.authentication_controller.verify_email_action_notice') }
|
69
88
|
format.json { render json: @user }
|
70
89
|
else
|
71
90
|
format.html { render :verify_email, status: :unprocessable_entity }
|
@@ -74,6 +93,9 @@ module Lato
|
|
74
93
|
end
|
75
94
|
end
|
76
95
|
|
96
|
+
# Recover password
|
97
|
+
##
|
98
|
+
|
77
99
|
def recover_password
|
78
100
|
@user = Lato::User.new
|
79
101
|
end
|
@@ -92,12 +114,15 @@ module Lato
|
|
92
114
|
end
|
93
115
|
end
|
94
116
|
|
117
|
+
# Update password
|
118
|
+
##
|
119
|
+
|
95
120
|
def update_password; end
|
96
121
|
|
97
122
|
def update_password_action
|
98
123
|
respond_to do |format|
|
99
124
|
if @user.update_password(params.require(:user).permit(:code, :password, :password_confirmation))
|
100
|
-
format.html { redirect_to lato.authentication_signin_path, notice: '
|
125
|
+
format.html { redirect_to lato.authentication_signin_path, notice: I18n.t('lato.authentication_controller.update_password_action_notice') }
|
101
126
|
format.json { render json: @user }
|
102
127
|
else
|
103
128
|
format.html { render :update_password, status: :unprocessable_entity }
|
@@ -106,23 +131,55 @@ module Lato
|
|
106
131
|
end
|
107
132
|
end
|
108
133
|
|
134
|
+
# Accept invitation
|
135
|
+
##
|
136
|
+
|
137
|
+
def accept_invitation
|
138
|
+
@user = Lato::User.new(email: @invitation.email)
|
139
|
+
end
|
140
|
+
|
141
|
+
def accept_invitation_action
|
142
|
+
@user = Lato::User.new(registration_params)
|
143
|
+
|
144
|
+
respond_to do |format|
|
145
|
+
if @user.accept_invitation(params.permit(:id, :accepted_code))
|
146
|
+
session_create(@user.id)
|
147
|
+
|
148
|
+
format.html { redirect_to lato.root_path }
|
149
|
+
format.json { render json: @user }
|
150
|
+
else
|
151
|
+
format.html { render :accept_invitation, status: :unprocessable_entity }
|
152
|
+
format.json { render json: @user.errors, status: :unprocessable_entity }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
109
157
|
private
|
110
158
|
|
159
|
+
def registration_params
|
160
|
+
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :accepted_privacy_policy_version, :accepted_terms_and_conditions_version)
|
161
|
+
end
|
162
|
+
|
111
163
|
def find_user
|
112
164
|
@user = User.find_by(id: params[:id])
|
113
|
-
|
165
|
+
respond_to_with_not_found unless @user
|
166
|
+
end
|
167
|
+
|
168
|
+
def find_invitation
|
169
|
+
@invitation = Lato::Invitation.find_by(id: params[:id], accepted_code: params[:accepted_code])
|
170
|
+
respond_to_with_not_found unless @invitation
|
114
171
|
end
|
115
172
|
|
116
173
|
def lock_signup_if_disabled
|
117
174
|
return unless Lato.config.auth_disable_signup
|
118
175
|
|
119
|
-
|
176
|
+
respond_to_with_not_found
|
120
177
|
end
|
121
178
|
|
122
179
|
def lock_recover_password_if_disabled
|
123
180
|
return unless Lato.config.auth_disable_recover_password
|
124
181
|
|
125
|
-
|
182
|
+
respond_to_with_not_found
|
126
183
|
end
|
127
184
|
end
|
128
185
|
end
|
@@ -12,6 +12,12 @@ module Lato
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def lato_navbar_nav_locales_item(options = {})
|
16
|
+
flag = options[:flag] || false
|
17
|
+
|
18
|
+
render 'lato/components/navbar_nav_locales_item', flag: flag
|
19
|
+
end
|
20
|
+
|
15
21
|
# Sidebar
|
16
22
|
##
|
17
23
|
|
@@ -44,7 +50,7 @@ module Lato
|
|
44
50
|
columns = options[:columns] || @_lato_index[key][:columns] || collection.column_names || []
|
45
51
|
sortable_columns = @_lato_index[key][:sortable_columns] || []
|
46
52
|
searchable_columns = @_lato_index[key][:searchable_columns] || []
|
47
|
-
model_name_underscore = options[:model_name] || collection.model.name.gsub('/', '_')
|
53
|
+
model_name_underscore = options[:model_name] || collection.model.name.underscore.gsub('/', '_')
|
48
54
|
|
49
55
|
render(
|
50
56
|
'lato/components/index',
|
@@ -111,7 +117,7 @@ module Lato
|
|
111
117
|
end
|
112
118
|
|
113
119
|
content_tag :div, options do
|
114
|
-
concat content_tag(:span, "#{I18n.t('
|
120
|
+
concat content_tag(:span, "#{I18n.t('lato.there_are_some_errors')}:")
|
115
121
|
concat errors_list
|
116
122
|
concat button_tag('', type: 'button', class: 'btn-close', data: { bs_dismiss: 'alert' }) unless options[:fixed]
|
117
123
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lato
|
2
|
+
class InvitationMailer < ApplicationMailer
|
3
|
+
def invite_mail(invitation_id)
|
4
|
+
@invitation = Lato::Invitation.find(invitation_id)
|
5
|
+
|
6
|
+
set_invitation_locale
|
7
|
+
|
8
|
+
mail(
|
9
|
+
to: @invitation.email,
|
10
|
+
subject: 'Hai ricevuto un invito',
|
11
|
+
template_path: 'lato/mailer/invitation'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def set_invitation_locale
|
18
|
+
I18n.locale = @invitation.lato_user&.locale || I18n.default_locale
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,6 +3,9 @@ module Lato
|
|
3
3
|
def email_verification_mail(user_id, code)
|
4
4
|
@user = Lato::User.find(user_id)
|
5
5
|
@code = code
|
6
|
+
|
7
|
+
set_user_locale
|
8
|
+
|
6
9
|
mail(
|
7
10
|
to: @user.email,
|
8
11
|
subject: 'Conferma il tuo indirizzo email',
|
@@ -13,11 +16,20 @@ module Lato
|
|
13
16
|
def password_update_mail(user_id, code)
|
14
17
|
@user = Lato::User.find(user_id)
|
15
18
|
@code = code
|
19
|
+
|
20
|
+
set_user_locale
|
21
|
+
|
16
22
|
mail(
|
17
23
|
to: @user.email,
|
18
24
|
subject: 'Imposta una nuova password',
|
19
25
|
template_path: 'lato/mailer/user'
|
20
26
|
)
|
21
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def set_user_locale
|
32
|
+
I18n.locale = @user.locale || I18n.default_locale
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Lato
|
2
|
+
class Invitation < ApplicationRecord
|
3
|
+
attr_accessor :actions
|
4
|
+
|
5
|
+
# Kredis
|
6
|
+
##
|
7
|
+
|
8
|
+
kredis_boolean :email_invite_semaphore, expires_in: 2.minutes
|
9
|
+
|
10
|
+
# Validations
|
11
|
+
##
|
12
|
+
|
13
|
+
validates :email, presence: true, uniqueness: true
|
14
|
+
|
15
|
+
# Relations
|
16
|
+
##
|
17
|
+
|
18
|
+
belongs_to :lato_user, class_name: 'Lato::User', foreign_key: :lato_user_id, optional: true
|
19
|
+
|
20
|
+
# Hooks
|
21
|
+
##
|
22
|
+
|
23
|
+
before_validation do
|
24
|
+
self.email = email&.downcase&.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
# be sure that email is not already used by another user
|
28
|
+
before_create do
|
29
|
+
if Lato::User.find_by(email: email)
|
30
|
+
errors.add(:email, 'is already used by another user')
|
31
|
+
throw :abort
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# generate a random code for the invitation
|
36
|
+
before_create do
|
37
|
+
self.accepted_code = SecureRandom.hex(16)
|
38
|
+
end
|
39
|
+
|
40
|
+
# send an email to the invited user
|
41
|
+
after_create do
|
42
|
+
send_invite
|
43
|
+
end
|
44
|
+
|
45
|
+
# be sure accepted invitations can not be deleted
|
46
|
+
before_destroy do
|
47
|
+
throw :abort if accepted?
|
48
|
+
end
|
49
|
+
|
50
|
+
# Helpers
|
51
|
+
##
|
52
|
+
|
53
|
+
def accepted?
|
54
|
+
!!accepted_at
|
55
|
+
end
|
56
|
+
|
57
|
+
# Operations
|
58
|
+
##
|
59
|
+
|
60
|
+
def send_invite
|
61
|
+
if accepted?
|
62
|
+
errors.add(:base, :already_accepted)
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
|
66
|
+
if email_invite_semaphore.value
|
67
|
+
errors.add(:base, :email_sending_limit)
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
delivery = Lato::InvitationMailer.invite_mail(id).deliver_now
|
72
|
+
unless delivery
|
73
|
+
errors.add(:base, :email_sending_error)
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
|
77
|
+
email_invite_semaphore.value = true
|
78
|
+
|
79
|
+
true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lato
|
2
|
+
module Log
|
3
|
+
# This module is used to add log to the application.
|
4
|
+
# Log are used to track user actions without sensitive data.
|
5
|
+
# Log should not be destroyed.
|
6
|
+
before_destroy do
|
7
|
+
throw :abort
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.table_name_prefix
|
11
|
+
'lato_log_'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -10,6 +10,11 @@ module Lato
|
|
10
10
|
has_one_attached :input_file
|
11
11
|
has_one_attached :output_file
|
12
12
|
|
13
|
+
# Relations
|
14
|
+
##
|
15
|
+
|
16
|
+
belongs_to :lato_user, class_name: 'Lato::User', foreign_key: :lato_user_id, optional: true
|
17
|
+
|
13
18
|
# Hooks
|
14
19
|
##
|
15
20
|
|
@@ -50,6 +55,7 @@ module Lato
|
|
50
55
|
end
|
51
56
|
|
52
57
|
# Operations
|
58
|
+
##
|
53
59
|
|
54
60
|
def start
|
55
61
|
begin
|
@@ -93,7 +99,7 @@ module Lato
|
|
93
99
|
}
|
94
100
|
operation_params[:input_file] = file unless file.nil?
|
95
101
|
|
96
|
-
Operation.create(operation_params)
|
102
|
+
Lato::Operation.create(operation_params)
|
97
103
|
end
|
98
104
|
end
|
99
105
|
end
|
data/app/models/lato/user.rb
CHANGED
@@ -24,6 +24,9 @@ module Lato
|
|
24
24
|
##
|
25
25
|
|
26
26
|
has_many :lato_operations, class_name: 'Lato::Operation', foreign_key: :lato_user_id, dependent: :nullify
|
27
|
+
has_many :lato_invitations, class_name: 'Lato::Invitation', foreign_key: :lato_user_id, dependent: :nullify
|
28
|
+
|
29
|
+
has_many :lato_log_user_signins, class_name: 'Lato::Log::UserSignin', foreign_key: :lato_user_id, dependent: :nullify
|
27
30
|
|
28
31
|
# Hooks
|
29
32
|
##
|
@@ -32,6 +35,10 @@ module Lato
|
|
32
35
|
self.email = email&.downcase&.strip
|
33
36
|
end
|
34
37
|
|
38
|
+
before_create do
|
39
|
+
self.locale ||= I18n.default_locale
|
40
|
+
end
|
41
|
+
|
35
42
|
before_save do
|
36
43
|
self.email_verified_at = nil if email_changed?
|
37
44
|
self.accepted_privacy_policy_version = Lato.config.legal_privacy_policy_version if accepted_privacy_policy_version_changed?
|
@@ -64,31 +71,40 @@ module Lato
|
|
64
71
|
|
65
72
|
user = Lato::User.find_by(email: params[:email])
|
66
73
|
unless user
|
67
|
-
errors.add(:email,
|
74
|
+
errors.add(:email, :not_correct)
|
68
75
|
return
|
69
76
|
end
|
70
77
|
|
71
78
|
unless user.authenticate(params[:password])
|
72
|
-
errors.add(:password,
|
79
|
+
errors.add(:password, :not_correct)
|
73
80
|
return
|
74
81
|
end
|
75
82
|
|
76
83
|
self.id = user.id
|
77
84
|
reload
|
78
85
|
|
86
|
+
begin
|
87
|
+
lato_log_user_signins.create(
|
88
|
+
ip_address: params[:ip_address],
|
89
|
+
user_agent: params[:user_agent]
|
90
|
+
)
|
91
|
+
rescue StandardError => e
|
92
|
+
Rails.logger.error(e)
|
93
|
+
end
|
94
|
+
|
79
95
|
true
|
80
96
|
end
|
81
97
|
|
82
98
|
def request_verify_email
|
83
99
|
if email_verification_semaphore.value
|
84
|
-
errors.add(:base,
|
100
|
+
errors.add(:base, :email_verification_limit)
|
85
101
|
return
|
86
102
|
end
|
87
103
|
|
88
104
|
code = SecureRandom.hex.upcase
|
89
105
|
delivery = Lato::UserMailer.email_verification_mail(id, code).deliver_now
|
90
106
|
unless delivery
|
91
|
-
errors.add(:base,
|
107
|
+
errors.add(:base, :email_sending_error)
|
92
108
|
return
|
93
109
|
end
|
94
110
|
|
@@ -100,12 +116,12 @@ module Lato
|
|
100
116
|
|
101
117
|
def verify_email(params)
|
102
118
|
unless email_verification_code.value
|
103
|
-
errors.add(:base,
|
119
|
+
errors.add(:base, :email_verification_code_expired)
|
104
120
|
return
|
105
121
|
end
|
106
122
|
|
107
123
|
unless email_verification_code.value == params[:code]
|
108
|
-
errors.add(:base,
|
124
|
+
errors.add(:base, :email_verification_code_invalid)
|
109
125
|
return
|
110
126
|
end
|
111
127
|
|
@@ -116,15 +132,6 @@ module Lato
|
|
116
132
|
true
|
117
133
|
end
|
118
134
|
|
119
|
-
def destroy_with_confirmation(params)
|
120
|
-
unless params[:email_confirmation] == email
|
121
|
-
errors.add(:email, :not_correct)
|
122
|
-
return
|
123
|
-
end
|
124
|
-
|
125
|
-
destroy
|
126
|
-
end
|
127
|
-
|
128
135
|
def request_recover_password(params)
|
129
136
|
user = Lato::User.find_by(email: params[:email])
|
130
137
|
unless user
|
@@ -135,7 +142,7 @@ module Lato
|
|
135
142
|
code = SecureRandom.hex.upcase
|
136
143
|
delivery = Lato::UserMailer.password_update_mail(user.id, code).deliver_now
|
137
144
|
unless delivery
|
138
|
-
errors.add(:base,
|
145
|
+
errors.add(:base, :email_sending_error)
|
139
146
|
return
|
140
147
|
end
|
141
148
|
|
@@ -149,12 +156,12 @@ module Lato
|
|
149
156
|
|
150
157
|
def update_password(params)
|
151
158
|
unless password_update_code.value
|
152
|
-
errors.add(:base,
|
159
|
+
errors.add(:base, :password_update_code_expired)
|
153
160
|
return
|
154
161
|
end
|
155
162
|
|
156
163
|
unless password_update_code.value == params[:code]
|
157
|
-
errors.add(:base,
|
164
|
+
errors.add(:base, :password_update_code_invalid)
|
158
165
|
return
|
159
166
|
end
|
160
167
|
|
@@ -165,7 +172,7 @@ module Lato
|
|
165
172
|
|
166
173
|
def update_accepted_privacy_policy_version(params)
|
167
174
|
unless params[:confirm]
|
168
|
-
errors.add(:base,
|
175
|
+
errors.add(:base, :privacy_policy_invalid)
|
169
176
|
return
|
170
177
|
end
|
171
178
|
|
@@ -174,11 +181,37 @@ module Lato
|
|
174
181
|
|
175
182
|
def update_accepted_terms_and_conditions_version(params)
|
176
183
|
unless params[:confirm]
|
177
|
-
errors.add(:base,
|
184
|
+
errors.add(:base, :terms_and_conditions_invalid)
|
178
185
|
return
|
179
186
|
end
|
180
187
|
|
181
188
|
update(accepted_terms_and_conditions_version: Lato.config.legal_terms_and_conditions_version)
|
182
189
|
end
|
190
|
+
|
191
|
+
def destroy_with_confirmation(params)
|
192
|
+
unless params[:email_confirmation] == email
|
193
|
+
errors.add(:email, :not_correct)
|
194
|
+
return
|
195
|
+
end
|
196
|
+
|
197
|
+
destroy
|
198
|
+
end
|
199
|
+
|
200
|
+
def accept_invitation(params)
|
201
|
+
invitation = Lato::Invitation.find_by(id: params[:id], accepted_code: params[:accepted_code])
|
202
|
+
if !invitation || invitation.accepted? || invitation.email != email
|
203
|
+
errors.add(:base, :invitation_invalid)
|
204
|
+
return
|
205
|
+
end
|
206
|
+
|
207
|
+
ActiveRecord::Base.transaction do
|
208
|
+
raise ActiveRecord::Rollback unless save && invitation.update(
|
209
|
+
accepted_at: Time.now,
|
210
|
+
lato_user_id: id
|
211
|
+
)
|
212
|
+
|
213
|
+
true
|
214
|
+
end
|
215
|
+
end
|
183
216
|
end
|
184
217
|
end
|