lato_core 1.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.
- checksums.yaml +7 -0
- data/Rakefile +38 -0
- data/app/controllers/lato_core/api/v1/api_controller.rb +9 -0
- data/app/controllers/lato_core/application_controller.rb +6 -0
- data/app/controllers/lato_core/back/authentication_controller.rb +114 -0
- data/app/controllers/lato_core/back/back_controller.rb +28 -0
- data/app/controllers/lato_core/back/superusers_controller.rb +172 -0
- data/app/mailers/lato_core/application_mailer.rb +10 -0
- data/app/mailers/lato_core/superusers_mailer.rb +29 -0
- data/app/models/lato_core/superuser.rb +43 -0
- data/app/views/lato_core/back/authentication/login.html.erb +42 -0
- data/app/views/lato_core/back/authentication/password_edit.html.erb +50 -0
- data/app/views/lato_core/back/authentication/password_forget.html.erb +37 -0
- data/app/views/lato_core/back/back/home.html.erb +20 -0
- data/app/views/lato_core/back/superusers/edit.html.erb +12 -0
- data/app/views/lato_core/back/superusers/index.html.erb +25 -0
- data/app/views/lato_core/back/superusers/new.html.erb +12 -0
- data/app/views/lato_core/back/superusers/shared/_form.html.erb +71 -0
- data/app/views/lato_core/back/superusers/show.html.erb +1 -0
- data/app/views/lato_core/mailers/layouts/mailer.html.erb +9 -0
- data/app/views/lato_core/mailers/layouts/mailer.text.erb +1 -0
- data/app/views/lato_core/mailers/superusers/notify.html.erb +2 -0
- data/app/views/lato_core/mailers/superusers/recover_password.html.erb +4 -0
- data/config/config.yml +8 -0
- data/config/example.yml +66 -0
- data/config/initializers/init.rb +16 -0
- data/config/initializers/ram.rb +50 -0
- data/config/routes.rb +20 -0
- data/db/migrate/20160224181217_create_lato_core_superusers.rb +15 -0
- data/lib/lato_core.rb +11 -0
- data/lib/lato_core/engine.rb +26 -0
- data/lib/lato_core/interface.rb +29 -0
- data/lib/lato_core/interface/authentication.rb +34 -0
- data/lib/lato_core/interface/cache.rb +29 -0
- data/lib/lato_core/interface/communication.rb +104 -0
- data/lib/lato_core/interface/languages.rb +60 -0
- data/lib/lato_core/interface/navigation.rb +109 -0
- data/lib/lato_core/interface/session.rb +71 -0
- data/lib/lato_core/interface/superusers.rb +143 -0
- data/lib/tasks/lato_core_tasks.rake +11 -0
- data/test/controllers/lato_core/api/v1/api_controller_test.rb +9 -0
- data/test/controllers/lato_core/application_controller_test.rb +9 -0
- data/test/controllers/lato_core/back/authentication_controller_test.rb +13 -0
- data/test/controllers/lato_core/back/back_controller_test.rb +9 -0
- data/test/controllers/lato_core/back/session_controller_test.rb +13 -0
- data/test/controllers/lato_core/back/superusers_controller_test.rb +13 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/test.log +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/lato_core/superusers.yml +11 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/lato_core_test.rb +7 -0
- data/test/mailers/lato_core/lato_core_mailer_test.rb +9 -0
- data/test/mailers/previews/lato_core/lato_core_mailer_preview.rb +6 -0
- data/test/models/lato_core/superuser_test.rb +9 -0
- data/test/test_helper.rb +21 -0
- metadata +207 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6cb92d3b3c9b544994b4a3d1b0c29867ae4c9b52
|
|
4
|
+
data.tar.gz: 8bd48730a7264e0574ae614f83bccacfde7f4b96
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 36e9ec71600ea4de301286f49a40729525c8851e90f493125177b4b584a89a6a094a94d1b27e941771bebcae74ef7418ae52e0feb3e5949c4356a0c6a1a78eed
|
|
7
|
+
data.tar.gz: 1080153b8ad42ac9ffcdcfbf975835c4c75a3bace55b0a299f2aade157cbc39cd1007aa9a237fa5174023929463aa3291495509ef1c2e5ba47df44294ac5e654
|
data/Rakefile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'doc'
|
|
11
|
+
rdoc.title = 'LatoCore'
|
|
12
|
+
rdoc.rdoc_files.include('README.md')
|
|
13
|
+
rdoc.rdoc_files.include('lib/lato_core.rb')
|
|
14
|
+
rdoc.rdoc_files.include('lib/lato_core/**/*.rb')
|
|
15
|
+
rdoc.rdoc_files.include('app/models/**/*.rb')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
19
|
+
load 'rails/tasks/engine.rake'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
load 'rails/tasks/statistics.rake'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Bundler::GemHelper.install_tasks
|
|
27
|
+
|
|
28
|
+
require 'rake/testtask'
|
|
29
|
+
|
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
|
31
|
+
t.libs << 'lib'
|
|
32
|
+
t.libs << 'test'
|
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
|
34
|
+
t.verbose = false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
task default: :test
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
module LatoCore
|
|
2
|
+
module Back
|
|
3
|
+
# Controller che gestisce il login e il logout degli utenti
|
|
4
|
+
class AuthenticationController < Back::BackController
|
|
5
|
+
|
|
6
|
+
# Disattivo il controllo dell'autenticazione utente
|
|
7
|
+
skip_before_action :core_controlUser, except: [:exec_logout]
|
|
8
|
+
|
|
9
|
+
# Richiama la view della pagina di login
|
|
10
|
+
def login
|
|
11
|
+
redirect_to lato_core.root_path if core_controlSession
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Esegue il login e, se l'utente e' autenticato lo rimanda
|
|
15
|
+
# alla homepage del backoffice
|
|
16
|
+
def exec_login
|
|
17
|
+
if core_createSession(params[:username], params[:password])
|
|
18
|
+
redirect_to lato_core.root_path
|
|
19
|
+
else
|
|
20
|
+
flash[:warning] = CORE_LANG['superusers']['login_error']
|
|
21
|
+
redirect_to lato_core.login_path
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Esegue il logout e rimanda alla pagina di login del backoffice
|
|
26
|
+
def exec_logout
|
|
27
|
+
core_destroySession
|
|
28
|
+
redirect_to lato_core.login_path
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Richiama la view per la richiesta di una nuova password nel caso di
|
|
32
|
+
# password dimenticata
|
|
33
|
+
def password_forget
|
|
34
|
+
redirect_to lato_core.root_path unless core_getRecoveryPasswordPermission
|
|
35
|
+
redirect_to lato_core.root_path if core_controlSession
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Esegue il necessario per il recupero password e invia l'email al richiedente
|
|
39
|
+
def password_recover
|
|
40
|
+
redirect_to lato_core.root_path unless core_getRecoveryPasswordPermission
|
|
41
|
+
if user = LatoCore::Superuser.find_by(email: params[:email].downcase)
|
|
42
|
+
# genero il codice da salvare come session code
|
|
43
|
+
code = "RECPSW-#{SecureRandom.urlsafe_base64}"
|
|
44
|
+
# genero il codice per formare l'url di recupero password
|
|
45
|
+
code_url = URI.encode("#{user.id}::#{Time.now}::#{code}")
|
|
46
|
+
# memorizzo il session_code sul db
|
|
47
|
+
user.update_attribute(:session_code, code)
|
|
48
|
+
# invio una mail di recupero
|
|
49
|
+
LatoCore::SuperusersMailer.recover_password(user.email, code_url).deliver_now
|
|
50
|
+
flash[:success] = CORE_LANG['recover_password']['confirm_send']
|
|
51
|
+
else
|
|
52
|
+
flash[:warning] = CORE_LANG['superusers']['not_found']
|
|
53
|
+
end
|
|
54
|
+
redirect_to lato_core.login_path
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Richiama la view con il form per l'inserimento di una nuova password
|
|
58
|
+
def password_edit
|
|
59
|
+
redirect_to lato_core.root_path unless core_getRecoveryPasswordPermission
|
|
60
|
+
redirect_to lato_core.root_path if core_controlSession
|
|
61
|
+
# splitto il token ricevuto (formato: id utente, timestamp, session_code)
|
|
62
|
+
data = URI.decode(params[:token]).split('::')
|
|
63
|
+
# controllo che il formato sia corretto
|
|
64
|
+
if data.length != 3
|
|
65
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error_token']
|
|
66
|
+
redirect_to lato_core.login_path and return false
|
|
67
|
+
end
|
|
68
|
+
# identifico i singoli dati
|
|
69
|
+
user_id = data.first
|
|
70
|
+
timestamp = data.second
|
|
71
|
+
session_code = data.last
|
|
72
|
+
# cerco l'utente e, se non esiste, stampo un errore
|
|
73
|
+
@user = LatoCore::Superuser.find(user_id)
|
|
74
|
+
if !@user
|
|
75
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error_user']
|
|
76
|
+
redirect_to lato_core.login_path and return false
|
|
77
|
+
end
|
|
78
|
+
# verifico che il token sia ancora valido e non abbia superato le 24 ore
|
|
79
|
+
if !time = timestamp.to_time || time < Time.now - 24.hours
|
|
80
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error_token_time']
|
|
81
|
+
redirect_to lato_core.login_path and return false
|
|
82
|
+
end
|
|
83
|
+
# verifico che il session_code del token sia corretto
|
|
84
|
+
if @user.session_code != session_code
|
|
85
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error_token']
|
|
86
|
+
redirect_to lato_core.login_path and return false
|
|
87
|
+
end
|
|
88
|
+
# genero un nuovo token per togliere la validita' al link di recupero password
|
|
89
|
+
# e lo memorizzo all'utente
|
|
90
|
+
new_code = SecureRandom.urlsafe_base64
|
|
91
|
+
@user.update_attribute(:session_code, new_code)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Aggiorna la password dell'utente che ha richiesto il recupero password
|
|
95
|
+
def password_update
|
|
96
|
+
redirect_to lato_core.root_path unless core_getRecoveryPasswordPermission
|
|
97
|
+
user = LatoCore::Superuser.find(params[:id])
|
|
98
|
+
if !user || user.session_code != params[:token]
|
|
99
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error']
|
|
100
|
+
redirect_to lato_core.login_path and return false
|
|
101
|
+
end
|
|
102
|
+
user.update(password: params[:password], password_confirmation: params[:password])
|
|
103
|
+
if !user.save
|
|
104
|
+
flash[:warning] = CORE_LANG['recover_password']['recover_error']
|
|
105
|
+
redirect_to lato_core.login_path and return false
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
flash[:success] = CORE_LANG['recover_password']['recover_success']
|
|
109
|
+
redirect_to lato_core.login_path
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Includo l'interfaccia di lato_core
|
|
2
|
+
include LatoCore::Interface
|
|
3
|
+
# Includo l'interfaccia di lato_view
|
|
4
|
+
include LatoView::Interface
|
|
5
|
+
|
|
6
|
+
module LatoCore
|
|
7
|
+
module Back
|
|
8
|
+
# Classe che gestisce il pannello di backoffice del modulo
|
|
9
|
+
class BackController < ApplicationController
|
|
10
|
+
|
|
11
|
+
# Imposto layout di base dal lato_view
|
|
12
|
+
layout 'lato_layout'
|
|
13
|
+
|
|
14
|
+
# Attivo il controllo delle credenziali
|
|
15
|
+
before_action :core_controlUser
|
|
16
|
+
|
|
17
|
+
# Richiama la view della home del pannello di backoffice
|
|
18
|
+
def home
|
|
19
|
+
# rimando ad una pagina custom se è stato impostato da file di configurazione
|
|
20
|
+
if login_root = core_getApplicationLoginRoot and login_root
|
|
21
|
+
redirect_to login_root
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
module LatoCore
|
|
2
|
+
module Back
|
|
3
|
+
# Controller che gestisce il CRUD degli utenti amministratori
|
|
4
|
+
class SuperusersController < Back::BackController
|
|
5
|
+
|
|
6
|
+
# Imposto la voce di menu da attivare
|
|
7
|
+
before_action :set_unique_name
|
|
8
|
+
# Controllo permessi utente
|
|
9
|
+
before_action :control_permission
|
|
10
|
+
|
|
11
|
+
# Richiama la view di creazione di un nuovo utente con permessi di
|
|
12
|
+
# accesso al pannello di backoffice
|
|
13
|
+
def new
|
|
14
|
+
@superuser = LatoCore::Superuser.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Crea un nuovo utente con permessi di accesso al pannello di backoffice
|
|
18
|
+
# e rimanda alla pagina di visualizzazione del profilo utente appena
|
|
19
|
+
# creato
|
|
20
|
+
def create
|
|
21
|
+
superuser = LatoCore::Superuser.new(superuser_params)
|
|
22
|
+
# controllo che l'utente creato non abbia permessi superiori dell'utente
|
|
23
|
+
# creatore
|
|
24
|
+
if superuser.permission > core_getCurrentUser.permission
|
|
25
|
+
flash[:warning] = CORE_LANG['superusers']['permission_create']
|
|
26
|
+
redirect_to lato_core.superusers_path and return false
|
|
27
|
+
end
|
|
28
|
+
# controllo che la creazione dell'utente non abbia avuto errori
|
|
29
|
+
unless superuser.save
|
|
30
|
+
flash[:danger] = CORE_LANG['superusers']['failed_create']
|
|
31
|
+
redirect_to lato_core.superusers_path and return false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
flash[:success] = CORE_LANG['superusers']['success_create']
|
|
35
|
+
redirect_to lato_core.superuser_path(superuser)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Richiama la view di modifica dell'utente con id uguale a quello ricevuto
|
|
39
|
+
# come parametro
|
|
40
|
+
def edit
|
|
41
|
+
@superuser = LatoCore::Superuser.find(params[:id])
|
|
42
|
+
# controllo che l'utente da modificare esista
|
|
43
|
+
unless @superuser
|
|
44
|
+
flash[:warning] = CORE_LANG['superusers']['not_found']
|
|
45
|
+
redirect_to lato_core.superusers_path and return false
|
|
46
|
+
end
|
|
47
|
+
# controllo che l'utente da modificare non abbia permessi uguali o
|
|
48
|
+
# maggiori dell'utente modificatore
|
|
49
|
+
if @superuser.permission >= core_getCurrentUser.permission &&
|
|
50
|
+
@superuser.permission != core_getCurrentUser.permission
|
|
51
|
+
flash[:warning] = CORE_LANG['superusers']['permission_update']
|
|
52
|
+
redirect_to lato_core.superusers_path and return false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Aggiorna l'utente con i dati ricevuti come parametro
|
|
57
|
+
def update
|
|
58
|
+
superuser = LatoCore::Superuser.find(params[:id])
|
|
59
|
+
# controllo che l'utente da modificare esista
|
|
60
|
+
unless superuser
|
|
61
|
+
flash[:warning] = CORE_LANG['superusers']['not_found']
|
|
62
|
+
redirect_to lato_core.superusers_path and return false
|
|
63
|
+
end
|
|
64
|
+
# controllo che l'utente da modificare non abbia permessi uguali o
|
|
65
|
+
# maggiori dell'utente modificatore
|
|
66
|
+
if superuser.permission >= core_getCurrentUser.permission &&
|
|
67
|
+
superuser != core_getCurrentUser
|
|
68
|
+
flash[:warning] = CORE_LANG['superusers']['permission_update']
|
|
69
|
+
redirect_to lato_core.superusers_path and return false
|
|
70
|
+
end
|
|
71
|
+
# controllo che l'utente non si stia auto aumentando i permessi
|
|
72
|
+
if superuser.id === core_getCurrentUser.id &&
|
|
73
|
+
superuser.permission < params[:superuser][:permission].to_i
|
|
74
|
+
flash[:warning] = CORE_LANG['superusers']['level_update']
|
|
75
|
+
redirect_to lato_core.superusers_path and return false
|
|
76
|
+
end
|
|
77
|
+
# faccio in modo che l'aggiornamento avvenga senza problemi anche se
|
|
78
|
+
# la password non e' stata inserita
|
|
79
|
+
if params[:superuser][:password].blank? &&
|
|
80
|
+
params[:superuser][:password_confirmation].blank?
|
|
81
|
+
params[:superuser].delete(:password)
|
|
82
|
+
params[:superuser].delete(:password_confirmation)
|
|
83
|
+
end
|
|
84
|
+
# controllo che non ci siano stati errori di aggiornamento
|
|
85
|
+
unless superuser.update(superuser_params)
|
|
86
|
+
flash[:danger] = CORE_LANG['superusers']['failed_update']
|
|
87
|
+
redirect_to lato_core.superuser_path(superuser) and return false
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
flash[:success] = CORE_LANG['superusers']['success_update']
|
|
91
|
+
redirect_to lato_core.superuser_path(superuser)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Elimina l'utente con id ricevuto come parametro
|
|
95
|
+
def destroy
|
|
96
|
+
superuser = LatoCore::Superuser.find(params[:id])
|
|
97
|
+
# controllo che l'utente da eliminare esista
|
|
98
|
+
unless superuser
|
|
99
|
+
flash[:warning] = CORE_LANG['superusers']['not_found']
|
|
100
|
+
redirect_to lato_core.superusers_path and return false
|
|
101
|
+
end
|
|
102
|
+
# controllo che l'utente non stia provando a eliminare se stesso
|
|
103
|
+
if superuser === core_getCurrentUser
|
|
104
|
+
flash[:warning] = CORE_LANG['superusers']['itself_destroy']
|
|
105
|
+
redirect_to lato_core.superusers_path and return false
|
|
106
|
+
end
|
|
107
|
+
# controllo che l'utente da eliminare non abbia permessi maggiori o
|
|
108
|
+
# uguali all'utente eliminatore
|
|
109
|
+
if superuser.permission >= core_getCurrentUser.permission
|
|
110
|
+
flash[:warning] = CORE_LANG['superusers']['permission_destroy']
|
|
111
|
+
redirect_to lato_core.superusers_path and return false
|
|
112
|
+
end
|
|
113
|
+
# controllo che non ci siano stati errori durante l'eliminazione
|
|
114
|
+
unless superuser.destroy
|
|
115
|
+
flash[:danger] = CORE_LANG['superusers']['failed_destroy']
|
|
116
|
+
redirect_to lato_core.superuser_path(superuser) and return false
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
flash[:success] = CORE_LANG['superusers']['success_destroy']
|
|
120
|
+
redirect_to lato_core.superusers_path
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Richiama la view per la visualizzazione di un singolo utente
|
|
124
|
+
# con lo stesso id ricevuto come parametro
|
|
125
|
+
def show
|
|
126
|
+
@superuser = LatoCore::Superuser.find(params[:id])
|
|
127
|
+
# controllo che l'utente da mostrare sia esistente
|
|
128
|
+
redirect_to lato_core.superusers_path unless @superuser
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Richiama la view per la visualizzazione di tutti gli utenti
|
|
132
|
+
# del sistema
|
|
133
|
+
def index
|
|
134
|
+
@search_superusers = LatoCore::Superuser.ransack(params[:q])
|
|
135
|
+
# controllo che non vengano mostrati gli utenti impostati nascosti
|
|
136
|
+
hide_settings = core_getHideUsersSettings
|
|
137
|
+
if hide_settings && !hide_settings.blank?
|
|
138
|
+
permissions_not_accepted = []
|
|
139
|
+
current_user_permission = core_getCurrentUser.permission
|
|
140
|
+
hide_settings.each do |setting|
|
|
141
|
+
permissions_not_accepted.push(setting.first) if setting.last.to_i === current_user_permission
|
|
142
|
+
end
|
|
143
|
+
@superusers = @search_superusers.result.where.not(permission: permissions_not_accepted)
|
|
144
|
+
else
|
|
145
|
+
@superusers = @search_superusers.result
|
|
146
|
+
end
|
|
147
|
+
@superusers = @superusers.order(
|
|
148
|
+
'username ASC'
|
|
149
|
+
).paginate(page: params[:page], per_page: 10)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Definisce i parametri accettati per le azioni di aggiornamento della
|
|
153
|
+
# tabella superusers nel database
|
|
154
|
+
private def superuser_params
|
|
155
|
+
params.require(:superuser).permit(:name, :username, :email, :permission,
|
|
156
|
+
:password, :password_digest)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Imposta la voce della navbar degli utenti come attiva
|
|
160
|
+
private def set_unique_name
|
|
161
|
+
view_setCurrentVoice('core_superusers')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Controlla che l'utente abbia i permessi per accedere alla sezione
|
|
165
|
+
private def control_permission
|
|
166
|
+
redirect_to lato_core.root_path unless core_controlPermission(6)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Includo l'interfaccia di lato_core
|
|
2
|
+
include LatoCore::Interface
|
|
3
|
+
|
|
4
|
+
module LatoCore
|
|
5
|
+
# Classe base di gestione dei mailers
|
|
6
|
+
class ApplicationMailer < ActionMailer::Base
|
|
7
|
+
default from: core_getApplicationServiceEmail
|
|
8
|
+
layout 'lato_core/mailers/layouts/mailer'
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module LatoCore
|
|
2
|
+
# Mailer utilizzato per la comunicazione con l'utente amministratore tramite email
|
|
3
|
+
class SuperusersMailer < ApplicationMailer
|
|
4
|
+
|
|
5
|
+
# Prende in input un utente, un titolo e un testo per notificare l'utente
|
|
6
|
+
# con il messaggio richiesto
|
|
7
|
+
def notify(user, title, message)
|
|
8
|
+
# imposto i dati come variabili di classe
|
|
9
|
+
@title = title
|
|
10
|
+
@message = message
|
|
11
|
+
# definisco oggetto email
|
|
12
|
+
subject = "#{CORE_LANG['mailers']['notify_subject']} #{core_getApplicationName}"
|
|
13
|
+
# invio l'email di notifica all'utente
|
|
14
|
+
mail(to: user.email, subject: subject,
|
|
15
|
+
template_path: 'lato_core/mailers/superusers')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Prende in input un utente e un codice speciale.
|
|
19
|
+
# Invia all'utente l'email per il recupero password contenente il codice speciale
|
|
20
|
+
def recover_password(email, code_url)
|
|
21
|
+
# identifico codice completo per l'utente
|
|
22
|
+
@recover_url = core_getApplicationURL + lato_core.password_edit_path(code_url)
|
|
23
|
+
# invio l'email all'utente
|
|
24
|
+
mail(to: email, subject: CORE_LANG['recover_password']['email_subject'],
|
|
25
|
+
template_path: 'lato_core/mailers/superusers')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module LatoCore
|
|
2
|
+
# Modello che si riferisce agli utenti con accesso al pannello di amministrazione
|
|
3
|
+
class Superuser < ActiveRecord::Base
|
|
4
|
+
|
|
5
|
+
# Lista validazioni
|
|
6
|
+
validates :name, presence: true, length: { maximum: 50 }
|
|
7
|
+
|
|
8
|
+
validates :username, presence: true,
|
|
9
|
+
length: { maximum: 50 },
|
|
10
|
+
uniqueness: { case_sensitive: false }
|
|
11
|
+
|
|
12
|
+
validates :email, presence: true,
|
|
13
|
+
length: { maximum: 255 },
|
|
14
|
+
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i },
|
|
15
|
+
uniqueness: { case_sensitive: false }
|
|
16
|
+
|
|
17
|
+
validates :permission, presence: true,
|
|
18
|
+
length: { minimum: 1, maximum: 10 }
|
|
19
|
+
|
|
20
|
+
validates :password, presence: true,
|
|
21
|
+
length: { minimum: 6, maximum: 50 },
|
|
22
|
+
on: :create
|
|
23
|
+
|
|
24
|
+
has_secure_password
|
|
25
|
+
|
|
26
|
+
# Azioni prima del salvataggio
|
|
27
|
+
before_save do
|
|
28
|
+
username.downcase!
|
|
29
|
+
email.downcase!
|
|
30
|
+
|
|
31
|
+
set_admin_permission
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Funzione che imposta i permessi dell'utente amministratore al
|
|
35
|
+
# massimo livello
|
|
36
|
+
private def set_admin_permission
|
|
37
|
+
first_user = LatoCore::Superuser.first
|
|
38
|
+
self.permission = 10 if first_user && id === first_user.id
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|