lesli_shield 0.1.1 → 1.0.1

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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/lesli_shield/application.js +1 -4415
  3. data/app/assets/javascripts/lesli_shield/confirmations.js +1 -47
  4. data/app/assets/javascripts/lesli_shield/passwords.js +1 -699
  5. data/app/assets/javascripts/lesli_shield/registrations.js +1 -699
  6. data/app/assets/javascripts/lesli_shield/sessions.js +1 -699
  7. data/app/assets/stylesheets/lesli_shield/application.css +0 -3
  8. data/app/assets/stylesheets/lesli_shield/confirmations.css +0 -25828
  9. data/app/assets/stylesheets/lesli_shield/devise/oauth.css +1 -0
  10. data/app/assets/stylesheets/lesli_shield/passwords.css +1 -25812
  11. data/app/assets/stylesheets/lesli_shield/registrations.css +1 -26168
  12. data/app/assets/stylesheets/lesli_shield/sessions.css +1 -26168
  13. data/app/assets/stylesheets/lesli_shield/users.css +1 -0
  14. data/app/controllers/lesli_shield/application_controller.rb +2 -2
  15. data/app/controllers/lesli_shield/dashboards_controller.rb +8 -1
  16. data/app/controllers/lesli_shield/role/actions_controller.rb +46 -0
  17. data/app/controllers/lesli_shield/roles_controller.rb +182 -0
  18. data/app/controllers/lesli_shield/sessions_controller.rb +67 -0
  19. data/app/controllers/lesli_shield/settings_controller.rb +61 -0
  20. data/app/controllers/lesli_shield/users_controller.rb +90 -0
  21. data/app/controllers/users/confirmations_controller.rb +2 -1
  22. data/app/controllers/users/passwords_controller.rb +31 -35
  23. data/app/controllers/users/registrations_controller.rb +28 -33
  24. data/app/controllers/users/sessions_controller.rb +38 -48
  25. data/app/helpers/lesli_shield/sessions_helper.rb +4 -0
  26. data/app/helpers/lesli_shield/settings_helper.rb +4 -0
  27. data/app/helpers/lesli_shield/users_helper.rb +4 -0
  28. data/app/interfaces/lesli_shield/authentication_interface.rb +64 -0
  29. data/app/interfaces/lesli_shield/authorization_interface.rb +40 -0
  30. data/{db/migrate/v1/0801050210_create_lesli_shield_dashboard_components.rb → app/models/lesli_shield/account.rb} +8 -18
  31. data/app/models/lesli_shield/application_record.rb +3 -3
  32. data/app/models/lesli_shield/setting.rb +4 -0
  33. data/app/models/lesli_shield/user.rb +5 -0
  34. data/app/services/lesli_shield/tokens.rb +39 -0
  35. data/app/views/devise/confirmations/new.html.erb +14 -0
  36. data/app/views/devise/passwords/edit.html.erb +27 -69
  37. data/app/views/devise/passwords/new.html.erb +31 -73
  38. data/app/views/devise/registrations/new.html.erb +43 -97
  39. data/app/views/devise/sessions/new.html.erb +48 -68
  40. data/app/views/devise/shared/_demo.html.erb +6 -7
  41. data/app/views/devise/shared/_error_messages.html.erb +27 -13
  42. data/app/views/devise/shared/_links.html.erb +1 -1
  43. data/app/views/lesli_shield/dashboards/index.html.erb +8 -0
  44. data/app/views/lesli_shield/dashboards/show.html.erb +1 -1
  45. data/app/views/lesli_shield/partials/_navigation.html.erb +39 -0
  46. data/app/views/lesli_shield/roles/_form-information.html.erb +21 -0
  47. data/app/views/lesli_shield/roles/_form-privileges.html.erb +104 -0
  48. data/app/views/lesli_shield/roles/_session.html.erb +2 -0
  49. data/app/views/lesli_shield/roles/edit.html.erb +12 -0
  50. data/app/views/lesli_shield/roles/index.html.erb +45 -0
  51. data/app/views/lesli_shield/roles/new.html.erb +11 -0
  52. data/app/views/lesli_shield/roles/show.html.erb +13 -0
  53. data/app/views/lesli_shield/roles/update.turbo_stream.erb +3 -0
  54. data/app/views/lesli_shield/sessions/_form.html.erb +17 -0
  55. data/app/views/lesli_shield/sessions/_session.html.erb +2 -0
  56. data/app/views/lesli_shield/sessions/edit.html.erb +12 -0
  57. data/app/views/lesli_shield/sessions/index.html.erb +37 -0
  58. data/app/views/lesli_shield/sessions/new.html.erb +11 -0
  59. data/app/views/lesli_shield/sessions/show.html.erb +6 -0
  60. data/app/views/lesli_shield/settings/_form.html.erb +17 -0
  61. data/app/views/lesli_shield/settings/_setting.html.erb +2 -0
  62. data/app/views/lesli_shield/settings/edit.html.erb +12 -0
  63. data/app/views/lesli_shield/settings/index.html.erb +16 -0
  64. data/app/views/lesli_shield/settings/new.html.erb +11 -0
  65. data/app/views/lesli_shield/settings/show.html.erb +9 -0
  66. data/app/views/lesli_shield/users/_information-card.html.erb +49 -0
  67. data/app/views/lesli_shield/users/_information-form.html.erb +12 -0
  68. data/app/views/lesli_shield/users/_management-sessions.html.erb +27 -0
  69. data/app/views/lesli_shield/users/_viewer-activities.html.erb +5 -0
  70. data/app/views/lesli_shield/users/edit.html.erb +0 -0
  71. data/app/views/lesli_shield/users/index.html.erb +45 -0
  72. data/app/views/lesli_shield/users/new.html.erb +11 -0
  73. data/app/views/lesli_shield/users/show.html.erb +27 -0
  74. data/app/views/lesli_shield/users/update.turbo_stream.erb +3 -0
  75. data/config/locales/translations.en.yml +1 -22
  76. data/config/locales/translations.es.yml +1 -22
  77. data/config/locales/translations.fr.yml +1 -22
  78. data/config/locales/translations.it.yml +1 -22
  79. data/config/locales/translations.pt.yml +1 -22
  80. data/config/routes.rb +31 -7
  81. data/db/migrate/v1/0801000110_create_lesli_shield_accounts.rb +3 -8
  82. data/db/migrate/v1/0801001710_create_lesli_shield_settings.rb +37 -0
  83. data/db/migrate/v1/{0801050110_create_lesli_shield_dashboards.rb → 0801003010_create_lesli_shield_dashboards.rb} +3 -17
  84. data/db/migrate/v1/0801120310_create_lesli_shield_user_shortcuts.rb +44 -0
  85. data/db/migrate/v1/0801120410_create_lesli_shield_user_tokens.rb +46 -0
  86. data/lib/lesli_shield/engine.rb +1 -5
  87. data/lib/lesli_shield/routing.rb +0 -3
  88. data/lib/lesli_shield/version.rb +2 -2
  89. data/lib/scss/_devise-simple.scss +90 -0
  90. data/lib/scss/_devise.scss +162 -0
  91. data/lib/scss/application.scss +6 -0
  92. data/lib/scss/confirmations.scss +24 -24
  93. data/lib/scss/devise/oauth.scss +1 -1
  94. data/lib/scss/passwords.scss +4 -2
  95. data/lib/scss/registrations.scss +2 -2
  96. data/lib/scss/sessions.scss +2 -2
  97. data/lib/scss/users.scss +58 -0
  98. data/lib/tasks/lesli_shield_tasks.rake +49 -4
  99. data/lib/vue/application.js +7 -0
  100. data/lib/vue/apps/sessions/index.vue +50 -0
  101. data/lib/vue/stores/sessions.js +43 -0
  102. data/readme.md +32 -18
  103. metadata +67 -15
  104. data/app/views/layouts/lesli_shield/application.html.erb +0 -15
@@ -1,4 +1,4 @@
1
1
  module LesliShield
2
- class ApplicationController < ActionController::Base
3
- end
2
+ class ApplicationController < ::Lesli::ApplicationLesliController
3
+ end
4
4
  end
@@ -1,4 +1,11 @@
1
1
  module LesliShield
2
- class DashboardsController < Lesli::Shared::DashboardsController
2
+ class DashboardsController < ApplicationController
3
+ before_action :set_session, only: %i[ ]
4
+
5
+ def index
6
+ end
7
+
8
+ def show
9
+ end
3
10
  end
4
11
  end
@@ -0,0 +1,46 @@
1
+ module LesliShield
2
+ class Role::ActionsController < ApplicationController
3
+ before_action :set_role_action, only: %i[update destroy ]
4
+
5
+ def update
6
+ # check saved
7
+ if @role_action.result.recover
8
+ success("Role privileges added successfully!")
9
+ respond_to do |format|
10
+ format.turbo_stream
11
+ render turbo_stream: turbo_stream.replace("application-lesli-notifications", partial: "lesli/partials/application-lesli-notifications")
12
+ #format.html { redirect_to role_path(@role_action.role_id) }
13
+ end
14
+ else
15
+ respond_with_error(@user.errors)
16
+ end
17
+ end
18
+
19
+ def destroy
20
+ # check saved
21
+ if @role_action.result.destroy
22
+ # success("Role privileges removed successfully!")
23
+ # respond_to do |format|
24
+ # format.turbo_stream
25
+ # #format.html { redirect_to role_path(@role_action.role_id) }
26
+ # end
27
+ return "hola"
28
+ else
29
+ respond_with_error(@user.errors)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # Use callbacks to share common setup or constraints between actions.
36
+ def set_role_action
37
+ @role_action = Lesli::Role::ActionService.new(current_user).find(params[:id])
38
+ end
39
+
40
+ def role_action_params
41
+ params.require(:role_action).permit(
42
+ :role_id
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,182 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2025, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module LesliShield
34
+ class RolesController < ApplicationController
35
+ before_action :set_role, only: %i[ show update destroy ]
36
+
37
+ def index
38
+ @roles = respond_as_pagination(Lesli::RoleService.new(current_user, query).index)
39
+ end
40
+
41
+ def show
42
+ @role = @role.show
43
+ @role_actions = Lesli::Role::ActionService.new(current_user, query).index(nil)
44
+ end
45
+
46
+ # @return [HTML] HTML view for creating a new role
47
+ # @description returns an HTML view with a form so users can create a new role
48
+ # @example
49
+ # # Executing this controller's action from javascript's frontend
50
+ # this.url.go('/roles/new')
51
+ def new
52
+ end
53
+
54
+ # @return [HTML] HTML view for editing the role
55
+ # @description returns an HTML view with a form so users edit an existing role
56
+ # @example
57
+ # # Executing this controller's action from javascript's frontend
58
+ # let role_id = 3;
59
+ # this.url.go(`/roles/${role_id}/edit`)
60
+ def edit
61
+ end
62
+
63
+ # @return [Json] Json that contains wheter the creation of the role was successful or not.
64
+ # If it is not successful, it returns an error message
65
+ # @description Creates a new role associated to the *current_user*'s *account*.
66
+ # @example
67
+ # # Executing this controller's action from javascript's frontend
68
+ # let data = {
69
+ # role: {
70
+ # name: "Change Request"
71
+ # }
72
+ # };
73
+ # this.http.post('127.0.0.1/house/roles', data);
74
+ def create
75
+
76
+ role = RoleService.new(current_user).create(role_params)
77
+
78
+ if role.successful?
79
+ respond_with_successful(role.result)
80
+ else
81
+ respond_with_error(role.errors_as_sentence)
82
+ end
83
+ end
84
+
85
+ # @controller_action_param :name [String] The name of the role
86
+ # @return [Json] Json that contains wheter the role was successfully updated or not.
87
+ # If it it not successful, it returns an error message
88
+ # @description Updates an existing role associated to the *current_user*'s *account*.
89
+ def update
90
+ # Respond with 404 if role was not found
91
+ return respond_with_not_found unless @role.found?
92
+
93
+ # check if current user can work with role
94
+ # unless current_user.can_work_with_role?(@role.resource)
95
+ # return respond_with_error(I18n.t("core.roles.messages_danger_updating_role_object_level_permission_too_high"))
96
+ # end
97
+
98
+ # Update role information
99
+ @role.update(role_params)
100
+
101
+ # check if the update went OK
102
+ if @role.successful?
103
+ success("Role updated successfully!")
104
+ respond_to do |format|
105
+ format.turbo_stream
106
+ format.html { redirect_to @role }
107
+ end
108
+ else
109
+ respond_with_error(@role.errors)
110
+ end
111
+ end
112
+
113
+ # @return [Json] Json that contains wheter the role was successfully deleted or not.
114
+ # If it it not successful, it returns an error message
115
+ # @description Deletes an existing *role* associated to the *current_user*'s *account*.
116
+ def destroy
117
+ return respond_with_not_found unless @role.found?
118
+
119
+ # Validation: check if the role has still associated users
120
+ if @role.has_users?
121
+ return respond_with_error(I18n.t("core.roles.messages_danger_users_assigned_validation"))
122
+ end
123
+
124
+ @role.destroy
125
+
126
+ # Check if the deletion went ok
127
+ unless @role.successful?
128
+ return respond_with_error(@role.errors)
129
+ end
130
+
131
+ respond_with_successful
132
+ end
133
+
134
+ # @return [JSON]
135
+ # @description Gets all the specific options for roles CRUD
136
+ def options
137
+ respond_with_successful(RoleService.new(current_user).options)
138
+ end
139
+
140
+ private
141
+
142
+ # @return [void]
143
+ # @description Sets the requested user based on the current_users's account
144
+ # @example
145
+ # # Executing this method from a controller action:
146
+ # set_role
147
+ # puts @role
148
+ # # This will either display nil or an instance of Role
149
+ def set_role
150
+ @role = Lesli::RoleService.new(current_user, @query).find(params[:id])
151
+ return respond_with_not_found unless @role.found?
152
+ end
153
+
154
+ # @return [Parameters] Allowed parameters for the role
155
+ # @description Sanitizes the parameters received from an HTTP call to only allow the specified ones.
156
+ # Allowed params are detail_attributes: [:name, :active, :object_level_permission]
157
+ # @example
158
+ # # suppose params contains {
159
+ # # "role": {
160
+ # # "name": "Admin",
161
+ # # "word": Hello
162
+ # # }
163
+ # #}
164
+ # filtered_params = role_params
165
+ # puts filtered_params
166
+ # # will remove all unpermitted attributes and only print {
167
+ # # "name": "Admin",
168
+ # #}
169
+ def role_params
170
+ params.require(:role).permit(
171
+ :name,
172
+ :active,
173
+ :description,
174
+ :path_default,
175
+ :path_limited,
176
+ :isolated,
177
+ :permission_level
178
+ )
179
+ end
180
+
181
+ end
182
+ end
@@ -0,0 +1,67 @@
1
+ module LesliShield
2
+ class SessionsController < ApplicationController
3
+ before_action :set_session, only: %i[ show edit update destroy ]
4
+
5
+ # GET /sessions
6
+ def index
7
+ respond_to do |format|
8
+ format.html {
9
+ @sessions = respond_as_pagination(Lesli::User::SessionService.new(current_user, query).index())
10
+ }
11
+ format.json {
12
+ respond_with_pagination(UserSessionService.new(current_user, query).index())
13
+ }
14
+ end
15
+ end
16
+
17
+ # GET /sessions/1
18
+ def show
19
+ end
20
+
21
+ # GET /sessions/new
22
+ def new
23
+ @session = Session.new
24
+ end
25
+
26
+ # GET /sessions/1/edit
27
+ def edit
28
+ end
29
+
30
+ # POST /sessions
31
+ def create
32
+ @session = Session.new(session_params)
33
+
34
+ if @session.save
35
+ redirect_to @session, notice: "Session was successfully created."
36
+ else
37
+ render :new, status: :unprocessable_entity
38
+ end
39
+ end
40
+
41
+ # PATCH/PUT /sessions/1
42
+ def update
43
+ if @session.update(session_params)
44
+ redirect_to @session, notice: "Session was successfully updated.", status: :see_other
45
+ else
46
+ render :edit, status: :unprocessable_entity
47
+ end
48
+ end
49
+
50
+ # DELETE /sessions/1
51
+ def destroy
52
+ @session.destroy!
53
+ redirect_to sessions_path, notice: "Session was successfully destroyed.", status: :see_other
54
+ end
55
+
56
+ private
57
+ # Use callbacks to share common setup or constraints between actions.
58
+ def set_session
59
+ @session = Session.find(params.expect(:id))
60
+ end
61
+
62
+ # Only allow a list of trusted parameters through.
63
+ def session_params
64
+ params.fetch(:session, {})
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,61 @@
1
+ module LesliShield
2
+ class SettingsController < ApplicationController
3
+ #before_action :set_setting, only: %i[ show edit update destroy ]
4
+
5
+ # GET /settings
6
+ def index
7
+ @settings = Setting.all
8
+ end
9
+
10
+ # GET /settings/1
11
+ def show
12
+ end
13
+
14
+ # GET /settings/new
15
+ def new
16
+ @setting = Setting.new
17
+ end
18
+
19
+ # GET /settings/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST /settings
24
+ def create
25
+ @setting = Setting.new(setting_params)
26
+
27
+ if @setting.save
28
+ redirect_to @setting, notice: "Setting was successfully created."
29
+ else
30
+ render :new, status: :unprocessable_entity
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /settings/1
35
+ def update
36
+ if @setting.update(setting_params)
37
+ redirect_to @setting, notice: "Setting was successfully updated.", status: :see_other
38
+ else
39
+ render :edit, status: :unprocessable_entity
40
+ end
41
+ end
42
+
43
+ # DELETE /settings/1
44
+ def destroy
45
+ @setting.destroy!
46
+ redirect_to settings_path, notice: "Setting was successfully destroyed.", status: :see_other
47
+ end
48
+
49
+ private
50
+
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_setting
53
+ @setting = Setting.find(params.expect(:id))
54
+ end
55
+
56
+ # Only allow a list of trusted parameters through.
57
+ def setting_params
58
+ params.fetch(:setting, {})
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,90 @@
1
+ module LesliShield
2
+ class UsersController < ApplicationController
3
+ before_action :set_user, only: %i[ show edit update destroy ]
4
+
5
+ # GET /users
6
+ def index
7
+ @users = respond_as_pagination(Lesli::UserService.new(current_user, query).index(params))
8
+ end
9
+
10
+ # GET /users/1
11
+ def show
12
+ @activities = @user.result.activities.order(id: :desc).map { |a| {
13
+ id: a[:id],
14
+ title: a[:title].titleize,
15
+ description: a[:description],
16
+ date: Date2.new(a[:created_at]).date_words
17
+ }}
18
+ @sessions = @user.result.sessions
19
+ @user = @user.show
20
+ end
21
+
22
+ # GET /users/new
23
+ def new
24
+ @user = User.new
25
+ end
26
+
27
+ # GET /users/1/edit
28
+ def edit
29
+ end
30
+
31
+ # POST /users
32
+ def create
33
+ @user = User.new(user_params)
34
+
35
+ if @user.save
36
+ redirect_to @user, notice: "User was successfully created."
37
+ else
38
+ render :new, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ # PATCH/PUT /users/1
43
+ def update
44
+
45
+ # check if the user trully exists
46
+ return respond_with_not_found unless @user.found?
47
+
48
+ # update the user information
49
+ @user.update(user_params)
50
+
51
+ # check saved
52
+ if @user.successful?
53
+ success("User updated successfully!")
54
+ respond_to do |format|
55
+ format.turbo_stream
56
+ format.html { redirect_to @user }
57
+ end
58
+ else
59
+ respond_with_error(@user.errors)
60
+ end
61
+ end
62
+
63
+ # DELETE /users/1
64
+ def destroy
65
+ @user.destroy!
66
+ redirect_to users_path, notice: "User was successfully destroyed.", status: :see_other
67
+ end
68
+
69
+ private
70
+
71
+ # Use callbacks to share common setup or constraints between actions.
72
+ def set_user
73
+ @user = Lesli::UserService.new(current_user).find(params[:id])
74
+ end
75
+
76
+ # Only allow a list of trusted parameters through.
77
+ def user_params
78
+ params.require(:user).permit(
79
+ :active,
80
+ :email,
81
+ :alias,
82
+ :title,
83
+ :roles_id,
84
+ :first_name,
85
+ :last_name,
86
+ :telephone
87
+ )
88
+ end
89
+ end
90
+ end
@@ -23,7 +23,8 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
23
23
  end
24
24
 
25
25
  # register a log with a validation atempt for the user
26
- log = user.logs.create({ description: "confirmation_atempt_successful" })
26
+ activity = user.activities.create({ title: "user_confirmation", description: "Confirmation process started" })
27
+
27
28
 
28
29
  registration_operator = Lesli::UserRegistrationOperator.new(user)
29
30
 
@@ -4,48 +4,52 @@ class Users::PasswordsController < Devise::PasswordsController
4
4
 
5
5
  # Sends an email with a token, so the user can reset their password
6
6
  def create
7
+ begin
7
8
 
8
- if params[:user].blank?
9
- #Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email")
10
- return respond_with_error(I18n.t("core.shared.messages_warning_user_not_found"))
11
- end
9
+ if params[:user].blank?
10
+ #Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email")
11
+ raise(I18n.t("core.shared.messages_warning_user_not_found"))
12
+ end
12
13
 
13
- if params[:user][:email].blank?
14
- #Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email")
15
- return respond_with_error(I18n.t("core.shared.messages_warning_user_not_found"))
16
- end
14
+ if params[:user][:email].blank?
15
+ #Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email")
16
+ raise(I18n.t("core.shared.messages_warning_user_not_found"))
17
+ end
17
18
 
18
- user = Lesli::User.find_by(:email => params[:user][:email])
19
+ user = Lesli::User.find_by(:email => params[:user][:email])
19
20
 
20
- if user.blank?
21
- # Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email", {
22
- # email: (params[:user][:email] || "")
23
- # })
24
- return respond_with_error(I18n.t("core.shared.messages_warning_user_not_found"))
25
- end
21
+ if user.blank?
22
+ # Account::Activity.log("core", "/password/create", "password_creation_failed", "no_valid_email", {
23
+ # email: (params[:user][:email] || "")
24
+ # })
25
+ raise(I18n.t("core.shared.messages_warning_user_not_found"))
26
+ end
26
27
 
27
- unless user.active
28
- # user.logs.create({title: "password_creation_failed", description: "user_not_active"})
29
- # Account::Activity.log("core", "/password/create", "password_creation_failed", "user_not_active")
30
- return respond_with_error(I18n.t("core.users/passwords.messages_danger_inactive_user"))
31
- end
28
+ unless user.active
29
+ user.activities.create({title: "password_creation_failed", description: "user_not_active"})
30
+ # Account::Activity.log("core", "/password/create", "password_creation_failed", "user_not_active")
31
+ raise(I18n.t("core.users/passwords.messages_danger_inactive_user"))
32
+ end
32
33
 
33
- token = user.generate_password_reset_token
34
+ token = user.generate_password_reset_token
34
35
 
35
- #user.logs.create({ title: "password_creation_successful" })
36
+ user.activities.create({ title: "password_create", description: "Password reset instructions sent" })
36
37
 
37
- begin
38
38
  Lesli::DeviseMailer.reset_password_instructions(user, token).deliver_now
39
- respond_with_successful
39
+ success(I18n.t("core.users/passwords.messages_success"))
40
+ redirect_to(new_user_password_path)
40
41
  rescue => exception
41
42
  #Honeybadger.notify(exception)
42
- respond_with_error(exception.message)
43
+ danger(exception.message)
44
+ redirect_to(new_user_password_path)
43
45
  end
44
46
  end
45
47
 
46
48
  def update
47
49
  super do |resource|
48
50
 
51
+ logs = resource.activities.new({ title: "password_reset", description:"atempt" })
52
+
49
53
  # check if password update was ok
50
54
  if resource.errors.empty?
51
55
 
@@ -54,18 +58,10 @@ class Users::PasswordsController < Devise::PasswordsController
54
58
  resource.update(password_expiration_at: nil)
55
59
  end
56
60
 
57
- resource.logs.create(title: "password_reset_successful")
58
-
59
- return respond_with_successful
60
-
61
+ logs.update({ description: "successful" })
61
62
  else
62
-
63
- resource.logs.create(title: "password_reset_error") if resource.id
64
-
65
- return respond_with_error(resource.errors.full_messages.to_sentence)
66
-
63
+ logs.update({ description: resource.errors.full_messages.to_sentence })
67
64
  end
68
-
69
65
  end
70
66
  end
71
67
  end
@@ -42,35 +42,34 @@ class Users::RegistrationsController < Devise::RegistrationsController
42
42
  # end
43
43
 
44
44
  def create
45
-
46
- # # Check if instance allow multi-account
47
- # if !Rails.application.config.lesli.dig(:security, :allow_registration)
48
- # respond_with_error(I18n.t("core.users/registrations.messages_error_registration_not_allowed"))
49
- # return
50
- # end
51
-
52
- # # Validate user is unique
53
- # if ::User.with_deleted.find_by(email: sign_up_params["email"])
54
- # return respond_with_error(I18n.t("core.users/registrations.messages_info_user_already_exists"))
55
- # end
56
-
57
- # build new user
58
- user = build_resource(sign_up_params)
59
-
60
- # run password complexity validations
61
- #user_validator = UsersValidator.new(user).password_complexity(sign_up_params[:password])
62
-
63
- # return if there are errors with the complexity validations
64
- # unless user_validator.valid?
65
- # return respond_with_error("password_complexity_error", password_complexity.failures)
66
- # end
67
-
68
- # persist new user
69
- if user.save
70
- respond_with_successful()
71
- else
72
- respond_with_error(user.errors.full_messages.to_sentence)
45
+ begin
46
+ # Check if instance allow multi-account
47
+ if !Lesli.config.security.dig(:allow_registration)
48
+ raise(I18n.t("core.users/registrations.messages_error_registration_not_allowed"))
49
+ end
50
+
51
+ # build new user
52
+ user = build_resource(sign_up_params)
53
+
54
+ # run password complexity validations
55
+ #user_validator = UsersValidator.new(user).password_complexity(sign_up_params[:password])
56
+
57
+ # return if there are errors with the complexity validations
58
+ # unless user_validator.valid?
59
+ # return respond_with_error("password_complexity_error", password_complexity.failures)
60
+ # end
61
+
62
+ # persist new user
63
+ if user.save
64
+ success("Account created, check your email")
65
+ else
66
+ raise(user.errors.full_messages.to_sentence)
67
+ end
68
+ rescue => exception
69
+ #Honeybadger.notify(exception)
70
+ danger(exception.message)
73
71
  end
72
+ redirect_to(new_user_registration_path)
74
73
  end
75
74
 
76
75
  # GET /resource/edit
@@ -132,10 +131,6 @@ class Users::RegistrationsController < Devise::RegistrationsController
132
131
  # end
133
132
 
134
133
  def sign_up_params
135
- params.permit(:sign_up,
136
- :email,
137
- :password,
138
- :password_confirmation
139
- )
134
+ params.fetch(:user, {}).permit(:email, :password, :password_confirmation)
140
135
  end
141
136
  end