chaltron 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/stylesheets/chaltron/layout.scss~ +68 -0
- data/app/controllers/chaltron/omniauth_callbacks_controller.rb +1 -1
- data/app/controllers/chaltron/omniauth_callbacks_controller.rb~ +34 -0
- data/app/controllers/chaltron/users_controller.rb~ +94 -0
- data/app/models/user.rb +15 -1
- data/app/models/user.rb~ +28 -0
- data/app/views/chaltron/users/index.html.erb~ +48 -0
- data/app/views/devise/sessions/_new_ldap.html.erb +14 -3
- data/app/views/devise/sessions/_new_ldap.html.erb~ +31 -0
- data/app/views/devise/sessions/_new_local.html.erb +4 -4
- data/app/views/devise/sessions/_new_local.html.erb~ +20 -0
- data/app/views/locales/en.yml +3 -1
- data/app/views/locales/en.yml~ +91 -0
- data/app/views/locales/it.yml +3 -1
- data/app/views/locales/it.yml~ +91 -0
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/devise.rb~ +256 -0
- data/lib/chaltron/controllers/helpers.rb +8 -0
- data/lib/chaltron/controllers/helpers.rb~ +61 -0
- data/lib/chaltron/engine.rb +1 -0
- data/lib/chaltron/engine.rb~ +47 -0
- data/lib/chaltron/ldap/user.rb~ +88 -0
- data/lib/chaltron/version.rb +1 -1
- data/lib/chaltron/version.rb~ +3 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9930da7720c0e4d19aeca6675e60a013d323e421
|
4
|
+
data.tar.gz: fd940fbb766e2a37932a1ac5fc6b4a641d91e508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0bc22a40c751d9eeca5ffd89cafd22cf5aebe730b5d8063250e2ffbfcdd2dd53f203915f5e2b64d17dd1459cb4894824a39516ff25d41b2854586e8570529cc
|
7
|
+
data.tar.gz: 0bc5262f0db91a51303c6b179dd316e8d1fb4704cc0f47dc2f9c2b18f528b004c2ce427db284a0283533493f62cd0d79d9cc77f677f4b28f034c8eeb61242053
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Chaltron [![Gem Version](https://badge.fury.io/rb/chaltron.svg)](http://badge.fury.io/rb/chaltron)
|
2
2
|
|
3
3
|
[![Build Status](https://api.travis-ci.org/vicvega/chaltron.png?branch=master)](http://travis-ci.org/vicvega/chaltron)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/vicvega/chaltron/badge.
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/vicvega/chaltron/badge.svg?branch=master&service=github)](https://coveralls.io/github/vicvega/chaltron?branch=master)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/vicvega/chaltron/badges/gpa.svg)](https://codeclimate.com/github/vicvega/chaltron)
|
6
6
|
[![Dependency Status](https://gemnasium.com/vicvega/chaltron.png)](https://gemnasium.com/vicvega/chaltron)
|
7
7
|
[![PullReview stats](https://www.pullreview.com/github/vicvega/chaltron/badges/master.svg?)](https://www.pullreview.com/github/vicvega/chaltron/reviews/master)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
body {
|
2
|
+
// background-color: #E1E1E1;
|
3
|
+
}
|
4
|
+
|
5
|
+
div#content {
|
6
|
+
margin-top: 40px;
|
7
|
+
}
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Flash messages
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
.flash-container {
|
14
|
+
cursor: pointer;
|
15
|
+
margin: 0;
|
16
|
+
text-align: center;
|
17
|
+
position: fixed;
|
18
|
+
top: 40px;
|
19
|
+
width: 100%;
|
20
|
+
opacity: 0.8;
|
21
|
+
z-index: 100;
|
22
|
+
.alert {
|
23
|
+
margin: 0;
|
24
|
+
border-radius: 0;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Login
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
.login-box{
|
33
|
+
margin-top: 100px;
|
34
|
+
@include form-box(650px);
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Navbar tabs
|
39
|
+
*
|
40
|
+
*/
|
41
|
+
.nav-tabs {
|
42
|
+
margin-bottom: 15px;
|
43
|
+
}
|
44
|
+
|
45
|
+
#nprogress .spinner {
|
46
|
+
display: block;
|
47
|
+
position: fixed;
|
48
|
+
z-index: 1031;
|
49
|
+
top: 12px;
|
50
|
+
right: 5px;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Scaffold
|
55
|
+
*
|
56
|
+
*/
|
57
|
+
.side-filters fieldset {
|
58
|
+
margin-bottom: 15px;
|
59
|
+
}
|
60
|
+
|
61
|
+
.form-actions {
|
62
|
+
background-color: whitesmoke;
|
63
|
+
border-top: 1px solid #e5e5e5;
|
64
|
+
margin-bottom: 18px;
|
65
|
+
margin-top: 18px;
|
66
|
+
padding-bottom: 18px;
|
67
|
+
padding-top: 18px;
|
68
|
+
}
|
@@ -15,7 +15,7 @@ module Chaltron
|
|
15
15
|
if user.nil?
|
16
16
|
redirect_to root_url, alert: I18n.t('chaltron.not_allowed_to_sign_in')
|
17
17
|
else
|
18
|
-
user.remember_me =
|
18
|
+
user.remember_me = params[:remember_me] if user.persisted?
|
19
19
|
flash[:notice] = I18n.t('devise.sessions.signed_in')
|
20
20
|
|
21
21
|
info I18n.t('chaltron.logs.login_via', user: user.display_name, provider: 'ldap')
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'chaltron/ldap/user'
|
2
|
+
|
3
|
+
module Chaltron
|
4
|
+
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
5
|
+
|
6
|
+
default_log_category :login
|
7
|
+
|
8
|
+
def ldap
|
9
|
+
puts '##########################################'
|
10
|
+
puts oauth.inspect
|
11
|
+
puts '##########################################'
|
12
|
+
puts params.inspect
|
13
|
+
puts '##########################################'
|
14
|
+
# We only find ourselves here
|
15
|
+
# if the authentication to LDAP was successful.
|
16
|
+
user = Chaltron::LDAP::User.find_or_create(oauth, Chaltron.ldap_allow_all)
|
17
|
+
if user.nil?
|
18
|
+
redirect_to root_url, alert: I18n.t('chaltron.not_allowed_to_sign_in')
|
19
|
+
else
|
20
|
+
user.remember_me = params[:remember_me] if user.persisted?
|
21
|
+
flash[:notice] = I18n.t('devise.sessions.signed_in')
|
22
|
+
|
23
|
+
info I18n.t('chaltron.logs.login_via', user: user.display_name, provider: 'ldap')
|
24
|
+
sign_in_and_redirect(user)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def oauth
|
31
|
+
@oauth ||= request.env['omniauth.auth']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class Chaltron::UsersController < ApplicationController
|
2
|
+
before_action :authenticate_user!
|
3
|
+
load_and_authorize_resource except: [:self_show, :self_edit, :self_update]
|
4
|
+
|
5
|
+
respond_to :html
|
6
|
+
default_log_category :user_admin
|
7
|
+
|
8
|
+
def index
|
9
|
+
|
10
|
+
puts 'USER controller index START'
|
11
|
+
|
12
|
+
@filters = params[:filters] || {}
|
13
|
+
|
14
|
+
# apply provider filter
|
15
|
+
@users = @users.where(provider: nil) if @filters[:provider] == 'local'
|
16
|
+
@users = @users.where(provider: :ldap) if @filters[:provider] == 'ldap'
|
17
|
+
# apply activity filter
|
18
|
+
@users = @users.where(sign_in_count: 0) if @filters[:activity] == 'no_login'
|
19
|
+
|
20
|
+
|
21
|
+
puts 'USER controller index STOP'
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
end
|
26
|
+
|
27
|
+
def new
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
end
|
32
|
+
|
33
|
+
def self_show
|
34
|
+
end
|
35
|
+
|
36
|
+
def self_edit
|
37
|
+
end
|
38
|
+
|
39
|
+
def create
|
40
|
+
if @user.save
|
41
|
+
flash[:notice] = I18n.t('chaltron.users.created')
|
42
|
+
info I18n.t('chaltron.logs.users.created',
|
43
|
+
current: current_user.display_name, user: @user.display_name)
|
44
|
+
end
|
45
|
+
respond_with(@user)
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
flash[:notice] = I18n.t('chaltron.users.updated') if @user.update(update_params)
|
50
|
+
respond_with(@user)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self_update
|
54
|
+
user_params_with_pass = self_update_params.dup
|
55
|
+
if params[:user][:password].present?
|
56
|
+
user_params_with_pass.merge!(
|
57
|
+
password: params[:user][:password],
|
58
|
+
password_confirmation: params[:user][:password_confirmation],
|
59
|
+
)
|
60
|
+
end
|
61
|
+
if current_user.update(user_params_with_pass)
|
62
|
+
flash[:notice] = I18n.t('chaltron.users.self_updated')
|
63
|
+
render :self_show
|
64
|
+
else
|
65
|
+
render :self_edit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def destroy
|
70
|
+
if current_user == @user
|
71
|
+
redirect_to({ action: :index }, alert: I18n.t('chaltron.users.cannot_self_destroy'))
|
72
|
+
else
|
73
|
+
info I18n.t('chaltron.logs.users.destroyed',
|
74
|
+
current: current_user.display_name, user: @user.display_name)
|
75
|
+
@user.destroy
|
76
|
+
respond_with(@user)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
def create_params
|
82
|
+
params.require(:user).permit(:username, :email, :fullname,
|
83
|
+
:password, :password_confirmation, roles: [])
|
84
|
+
end
|
85
|
+
|
86
|
+
def update_params
|
87
|
+
params.require(:user).permit(roles: [])
|
88
|
+
end
|
89
|
+
|
90
|
+
def self_update_params
|
91
|
+
params.require(:user).permit(:email, :fullname)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/app/models/user.rb
CHANGED
@@ -3,13 +3,27 @@ class User < ActiveRecord::Base
|
|
3
3
|
# Include default devise modules. Others available are:
|
4
4
|
# :registerable, :confirmable, :lockable and :omniauthable
|
5
5
|
|
6
|
+
# Virtual attribute for authenticating by either username or email
|
7
|
+
attr_accessor :login
|
8
|
+
|
6
9
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,
|
7
10
|
:timeoutable, :omniauthable
|
8
11
|
|
9
|
-
validates :username, presence: true, uniqueness: { scope: :provider }
|
12
|
+
validates :username, presence: true, uniqueness: { scope: :provider, case_sensitive: false }
|
10
13
|
|
11
14
|
def display_name
|
12
15
|
fullname.presence || username
|
13
16
|
end
|
14
17
|
|
18
|
+
# Devise method overridden to allow sign in with email or username
|
19
|
+
def self.find_for_database_authentication(warden_conditions)
|
20
|
+
conditions = warden_conditions.dup
|
21
|
+
login = conditions.delete(:login)
|
22
|
+
if login
|
23
|
+
where(conditions).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
|
24
|
+
else
|
25
|
+
where(conditions).first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
15
29
|
end
|
data/app/models/user.rb~
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
include Authorizable
|
3
|
+
# Include default devise modules. Others available are:
|
4
|
+
# :registerable, :confirmable, :lockable and :omniauthable
|
5
|
+
|
6
|
+
# Virtual attribute for authenticating by either username or email
|
7
|
+
attr_accessor :login
|
8
|
+
|
9
|
+
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,
|
10
|
+
:timeoutable, :omniauthable
|
11
|
+
|
12
|
+
validates :username, presence: true, uniqueness: { scope: :provider, case_sensitive: false }
|
13
|
+
|
14
|
+
def display_name
|
15
|
+
fullname.presence || username
|
16
|
+
end
|
17
|
+
|
18
|
+
# Devise method overridden to allow sign in with email or username
|
19
|
+
def self.find_for_database_authentication(warden_conditions)
|
20
|
+
conditions = warden_conditions.dup
|
21
|
+
if login = conditions.delete(:login)
|
22
|
+
where(conditions).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
|
23
|
+
else
|
24
|
+
where(conditions).first
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<% puts 'USER INDEX VIEW DEBUG 1' %>
|
2
|
+
|
3
|
+
<div class='container-fluid'>
|
4
|
+
<h3 class='page-header'><%= t '.title' %></h3>
|
5
|
+
<div class='row'>
|
6
|
+
<div class='col-md-3 side-filters'>
|
7
|
+
<%= render partial: 'side_filters', locals: { filters: @filters } %>
|
8
|
+
<hr>
|
9
|
+
|
10
|
+
<div class='btn-group pull-right'>
|
11
|
+
<%= content_tag :button, type: 'button', class: 'btn btn-primary dropdown-toggle',
|
12
|
+
data: {toggle: 'dropdown'}, aria: {expanded: false} do %>
|
13
|
+
<%= icon :plus, t('.new_user') %> <span class="caret"></span>
|
14
|
+
<% end %>
|
15
|
+
<ul class='dropdown-menu' role='menu'>
|
16
|
+
<li><%= link_to t('.new_ldap_user'), ldap_search_url %></li>
|
17
|
+
<li><%= link_to t('.new_local_user'), new_user_url %></li>
|
18
|
+
</ul>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<div class='col-md-9'>
|
22
|
+
<div class='panel panel-default'>
|
23
|
+
<div class='panel-body'>
|
24
|
+
<%= content_tag 'table', id: 'users', class: 'table table-striped' do %>
|
25
|
+
<thead>
|
26
|
+
<tr>
|
27
|
+
<th class='username'>
|
28
|
+
<%= User.human_attribute_name(:username) %>
|
29
|
+
</th>
|
30
|
+
<th class='fullname'>
|
31
|
+
<%= User.human_attribute_name(:fullname) %>
|
32
|
+
</th>
|
33
|
+
<th class='email'>
|
34
|
+
<%= User.human_attribute_name(:email) %>
|
35
|
+
</th>
|
36
|
+
</tr>
|
37
|
+
</thead>
|
38
|
+
<tbody>
|
39
|
+
<%= render @users %>
|
40
|
+
</tbody>
|
41
|
+
<% end %>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<% puts 'USER INDEX VIEW DEBUG 2' %>
|
@@ -2,16 +2,27 @@
|
|
2
2
|
<div class='form-group'>
|
3
3
|
<%= label_tag 'username', 'Username', class: 'col-sm-3 control-label' %>
|
4
4
|
<div class='col-sm-9'>
|
5
|
-
<%= text_field_tag :username, nil, {class: 'form-control', autofocus: 'autofocus'} %>
|
5
|
+
<%= text_field_tag :username, nil, {class: 'form-control', autofocus: 'autofocus', placeholder: 'LDAP username'} %>
|
6
6
|
</div>
|
7
7
|
</div>
|
8
8
|
<div class='form-group'>
|
9
9
|
<%= label_tag 'password', 'Password', class: 'col-sm-3 control-label' %>
|
10
10
|
<div class='col-sm-9'>
|
11
|
-
<%= password_field_tag :password, nil, {class: 'form-control bottom'} %>
|
11
|
+
<%= password_field_tag :password, nil, {class: 'form-control bottom', placeholder: 'Password'} %>
|
12
12
|
</div>
|
13
13
|
</div>
|
14
|
-
|
14
|
+
<% if devise_mapping.rememberable? %>
|
15
|
+
<div class='form-group'>
|
16
|
+
<div class='col-sm-offset-3 col-sm-9'>
|
17
|
+
<div class='checkbox'>
|
18
|
+
<%= label_tag :remember_me do %>
|
19
|
+
<%= check_box_tag :remember_me, 1, false %>
|
20
|
+
<%= t('.remember_me') %>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
15
26
|
<div class='form-group'>
|
16
27
|
<div class='col-sm-offset-3 col-sm-9'>
|
17
28
|
<%= submit_tag t('.submit_text'), class: 'btn btn-primary' %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%= form_tag(user_omniauth_callback_path(:ldap), class: 'form-horizontal', role: 'form') do %>
|
2
|
+
<div class='form-group'>
|
3
|
+
<%= label_tag 'username', 'Username', class: 'col-sm-3 control-label' %>
|
4
|
+
<div class='col-sm-9'>
|
5
|
+
<%= text_field_tag :username, nil, {class: 'form-control', autofocus: 'autofocus'} %>
|
6
|
+
</div>
|
7
|
+
</div>
|
8
|
+
<div class='form-group'>
|
9
|
+
<%= label_tag 'password', 'Password', class: 'col-sm-3 control-label' %>
|
10
|
+
<div class='col-sm-9'>
|
11
|
+
<%= password_field_tag :password, nil, {class: 'form-control bottom', placeholder: 'Password'} %>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
<% if devise_mapping.rememberable? %>
|
15
|
+
<div class='form-group'>
|
16
|
+
<div class='col-sm-offset-3 col-sm-9'>
|
17
|
+
<div class='checkbox'>
|
18
|
+
<%= label_tag :remember_me do %>
|
19
|
+
<%= check_box_tag :remember_me, 1, false %>
|
20
|
+
<%= t('.remember_me') %>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
<div class='form-group'>
|
27
|
+
<div class='col-sm-offset-3 col-sm-9'>
|
28
|
+
<%= submit_tag t('.submit_text'), class: 'btn btn-primary' %>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
<% end %>
|
@@ -1,10 +1,10 @@
|
|
1
|
-
<%= bootstrap_form_for(resource, as: resource_name, url: session_path(resource_name), layout: :horizontal, label_col:
|
2
|
-
<%= f.text_field :
|
3
|
-
<%= f.password_field :password %>
|
1
|
+
<%= bootstrap_form_for(resource, as: resource_name, url: session_path(resource_name), layout: :horizontal, label_col: 'col-sm-3', control_col: 'col-sm-9') do |f| %>
|
2
|
+
<%= f.text_field :login, placeholder: t('.login_placeholder') %>
|
3
|
+
<%= f.password_field :password, placeholder: 'Password' %>
|
4
4
|
<% if devise_mapping.rememberable? %>
|
5
5
|
<div class='form-group'>
|
6
6
|
<div class='col-sm-offset-3 col-sm-9'>
|
7
|
-
<%= f.check_box :remember_me, label: t('.remember_me'), control_col:
|
7
|
+
<%= f.check_box :remember_me, label: t('.remember_me'), control_col: 'col-sm-3' %>
|
8
8
|
</div>
|
9
9
|
</div>
|
10
10
|
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= bootstrap_form_for(resource, as: resource_name, url: session_path(resource_name), layout: :horizontal, label_col: 'col-sm-3', control_col: 'col-sm-9') do |f| %>
|
2
|
+
<%= f.text_field :login, placeholder: t('.username_placeholder') %>
|
3
|
+
<%= f.password_field :password, placeholder: 'Password' %>
|
4
|
+
<% if devise_mapping.rememberable? %>
|
5
|
+
<div class='form-group'>
|
6
|
+
<div class='col-sm-offset-3 col-sm-9'>
|
7
|
+
<%= f.check_box :remember_me, label: t('.remember_me'), control_col: 'col-sm-3' %>
|
8
|
+
</div>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
<div class='form-group'>
|
12
|
+
<div class='col-sm-offset-3 col-sm-9'>
|
13
|
+
<%= f.submit t('.submit_text'), class: 'btn btn-primary' %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
<hr>
|
17
|
+
<p>
|
18
|
+
<strong><%= link_to t('.link_text'), new_password_path(resource_name) %> </strong>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
data/app/views/locales/en.yml
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
en:
|
2
|
+
devise:
|
3
|
+
passwords:
|
4
|
+
new:
|
5
|
+
title: Forgot your password?
|
6
|
+
par1: Send us your email to receive instrucions for password reset
|
7
|
+
par2_html: Already got valid credentials? <strong><a href="/users/sign_in">Login</a></strong>
|
8
|
+
submit_text: Submit
|
9
|
+
edit:
|
10
|
+
title: Change password
|
11
|
+
submit_text: Change password
|
12
|
+
par_html: Never mind! <strong><a href="/users/sign_in">Login</a></strong>
|
13
|
+
sessions:
|
14
|
+
new:
|
15
|
+
title: Login
|
16
|
+
new_local:
|
17
|
+
remember_me: Remember me
|
18
|
+
link_text: Forgot your password?
|
19
|
+
submit_text: Login
|
20
|
+
username_placeholder: Username or email
|
21
|
+
new_ldap:
|
22
|
+
remember_me: Remember me
|
23
|
+
submit_text: LDAP login
|
24
|
+
chaltron:
|
25
|
+
logs:
|
26
|
+
index:
|
27
|
+
title: Log list
|
28
|
+
show:
|
29
|
+
headers:
|
30
|
+
details: Details
|
31
|
+
users:
|
32
|
+
index:
|
33
|
+
title: User list
|
34
|
+
new_user: New user
|
35
|
+
new_local_user: New local user
|
36
|
+
new_ldap_user: New LDAP user
|
37
|
+
side_filters:
|
38
|
+
provider:
|
39
|
+
all: All
|
40
|
+
local: Local
|
41
|
+
ldap: LDAP
|
42
|
+
activity:
|
43
|
+
inactive: Inactive
|
44
|
+
no_login: Never logged
|
45
|
+
new:
|
46
|
+
title: New local user
|
47
|
+
submit_text: Create local user
|
48
|
+
edit:
|
49
|
+
title: Edit %{user}
|
50
|
+
self_edit:
|
51
|
+
title: Edit account data
|
52
|
+
form:
|
53
|
+
cancel_text: Cancel
|
54
|
+
show:
|
55
|
+
headers:
|
56
|
+
activity: Activity
|
57
|
+
details: Details
|
58
|
+
edit: Edit
|
59
|
+
destroy: Destroy
|
60
|
+
destroy_confirm: Are you sure you want to destroy %{user}?
|
61
|
+
self_show:
|
62
|
+
title: Account data
|
63
|
+
headers:
|
64
|
+
activity: Activity
|
65
|
+
details: Details
|
66
|
+
edit: Edit account data
|
67
|
+
ldap:
|
68
|
+
search:
|
69
|
+
title: Search for LDAP sers
|
70
|
+
submit_text: Search
|
71
|
+
name_label: User
|
72
|
+
name_help: Search for user-id (exact match)
|
73
|
+
fullname_label: Fullname
|
74
|
+
fullname_help: Search for first name or surname (also partial match)
|
75
|
+
department_label: Department
|
76
|
+
department_help: Search for department (also partial match)
|
77
|
+
limit_label: Limit
|
78
|
+
limit_help: Max shown results
|
79
|
+
multi_new:
|
80
|
+
title: New LDAP users
|
81
|
+
submit_text: Create LDAP users
|
82
|
+
par: Select users by clicking row table
|
83
|
+
multi_create:
|
84
|
+
title: Create LDAP users
|
85
|
+
result: Results
|
86
|
+
created:
|
87
|
+
one: A new user has been successfully created
|
88
|
+
other: "%{count} users have been successfully created"
|
89
|
+
error:
|
90
|
+
one: A user has not been crated
|
91
|
+
other: "%{count} users have not been created"
|
data/app/views/locales/it.yml
CHANGED
@@ -17,8 +17,10 @@ it:
|
|
17
17
|
remember_me: Ricordami
|
18
18
|
link_text: Hai dimenticato la password?
|
19
19
|
submit_text: Login
|
20
|
+
login_placeholder: Username o email
|
20
21
|
new_ldap:
|
21
|
-
|
22
|
+
remember_me: Ricordami
|
23
|
+
submit_text: LDAP login
|
22
24
|
chaltron:
|
23
25
|
logs:
|
24
26
|
index:
|
@@ -0,0 +1,91 @@
|
|
1
|
+
it:
|
2
|
+
devise:
|
3
|
+
passwords:
|
4
|
+
new:
|
5
|
+
title: Password dimenticata?
|
6
|
+
par1: Inserisci la tua email per ricevere instruzioni su come resettare la password
|
7
|
+
submit_text: Invia
|
8
|
+
par2_html: Hai già delle credenziali valide? <strong><a href="/users/sign_in">Login</a></strong>
|
9
|
+
edit:
|
10
|
+
title: Cambio password
|
11
|
+
submit_text: Cambia password
|
12
|
+
par_html: Come non detto! <strong><a href="/users/sign_in">Login</a></strong>
|
13
|
+
sessions:
|
14
|
+
new:
|
15
|
+
title: Login
|
16
|
+
new_local:
|
17
|
+
remember_me: Ricordami
|
18
|
+
link_text: Hai dimenticato la password?
|
19
|
+
submit_text: Login
|
20
|
+
username_placeholder: Username o email
|
21
|
+
new_ldap:
|
22
|
+
remember_me: Ricordami
|
23
|
+
submit_text: LDAP login
|
24
|
+
chaltron:
|
25
|
+
logs:
|
26
|
+
index:
|
27
|
+
title: Elenco dei log
|
28
|
+
show:
|
29
|
+
headers:
|
30
|
+
details: Dettagli
|
31
|
+
users:
|
32
|
+
index:
|
33
|
+
title: Elenco degli utenti
|
34
|
+
new_user: Nuovo utente
|
35
|
+
new_local_user: Nuovo utente locale
|
36
|
+
new_ldap_user: Nuovo utente LDAP
|
37
|
+
side_filters:
|
38
|
+
provider:
|
39
|
+
all: Tutti
|
40
|
+
local: Locali
|
41
|
+
ldap: LDAP
|
42
|
+
activity:
|
43
|
+
inactive: Inattivi
|
44
|
+
no_login: Mai loggati
|
45
|
+
new:
|
46
|
+
title: Nuovo utente locale
|
47
|
+
submit_text: Crea utente locale
|
48
|
+
edit:
|
49
|
+
title: Modifica %{user}
|
50
|
+
self_edit:
|
51
|
+
title: Modifica dati personali
|
52
|
+
form:
|
53
|
+
cancel_text: Annulla
|
54
|
+
show:
|
55
|
+
headers:
|
56
|
+
activity: Attività
|
57
|
+
details: Dettagli
|
58
|
+
edit: Modifica
|
59
|
+
destroy: Cancella
|
60
|
+
destroy_confirm: Sei sicuro di voler cancellare %{user}?
|
61
|
+
self_show:
|
62
|
+
title: Dati personali
|
63
|
+
headers:
|
64
|
+
activity: Attività
|
65
|
+
details: Dettagli
|
66
|
+
edit: Modifica dati personali
|
67
|
+
ldap:
|
68
|
+
search:
|
69
|
+
title: Ricerca utenti LDAP
|
70
|
+
submit_text: Cerca
|
71
|
+
name_label: Utente
|
72
|
+
name_help: Ricerca per user-id (match esatto)
|
73
|
+
fullname_label: Nome
|
74
|
+
fullname_help: Ricerca per nome o cognome (anche match parziale)
|
75
|
+
department_label: Funzione
|
76
|
+
department_help: Ricerca per sigla di funzione (anche match parziale)
|
77
|
+
limit_label: Limite
|
78
|
+
limit_help: Massimo numero di risultati visualizzati
|
79
|
+
multi_new:
|
80
|
+
title: Nuovi utenti LDAP
|
81
|
+
submit_text: Crea utenti LDAP
|
82
|
+
par: Selezione gli utenti facendo un click sulla riga della tabella
|
83
|
+
multi_create:
|
84
|
+
title: Creazione utenti LDAP
|
85
|
+
result: Risultati
|
86
|
+
created:
|
87
|
+
one: È stato creato un nuovo utente
|
88
|
+
other: Sono stati creati %{count} nuovi utenti
|
89
|
+
error:
|
90
|
+
one: Un utente non è stato creato
|
91
|
+
other: "%{count} utenti non sono stati creati"
|
@@ -29,7 +29,7 @@ Devise.setup do |config|
|
|
29
29
|
# session. If you need permissions, you should implement that in a before filter.
|
30
30
|
# You can also supply a hash where the value is a boolean determining whether
|
31
31
|
# or not authentication should be aborted when the value is not present.
|
32
|
-
config.authentication_keys = [:
|
32
|
+
config.authentication_keys = [:login]
|
33
33
|
|
34
34
|
# Configure parameters from the request object used for authentication. Each entry
|
35
35
|
# given should be a request method and it will automatically be passed to the
|
@@ -0,0 +1,256 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
2
|
+
# Many of these configuration options can be set straight in your model.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# The secret key used by Devise. Devise uses this key to generate
|
5
|
+
# random tokens. Changing this key will render invalid all existing
|
6
|
+
# confirmation, reset password and unlock tokens in the database.
|
7
|
+
# config.secret_key = 'b329892371e2344d4ac2ca83059d9e4edee312765f952accfd5794570204e34d83bcdaf6fdcb9aa707d70a707f04695d6a88cf00693852533e913c26b658b455'
|
8
|
+
|
9
|
+
# ==> Mailer Configuration
|
10
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
11
|
+
# note that it will be overwritten if you use your own mailer class
|
12
|
+
# with default "from" parameter.
|
13
|
+
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
|
14
|
+
|
15
|
+
# Configure the class responsible to send e-mails.
|
16
|
+
# config.mailer = 'Devise::Mailer'
|
17
|
+
|
18
|
+
# ==> ORM configuration
|
19
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
20
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
21
|
+
# available as additional gems.
|
22
|
+
require 'devise/orm/active_record'
|
23
|
+
|
24
|
+
# ==> Configuration for any authentication mechanism
|
25
|
+
# Configure which keys are used when authenticating a user. The default is
|
26
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
27
|
+
# authenticating a user, both parameters are required. Remember that those
|
28
|
+
# parameters are used only when authenticating and not when retrieving from
|
29
|
+
# session. If you need permissions, you should implement that in a before filter.
|
30
|
+
# You can also supply a hash where the value is a boolean determining whether
|
31
|
+
# or not authentication should be aborted when the value is not present.
|
32
|
+
config.authentication_keys = [:username]
|
33
|
+
|
34
|
+
# Configure parameters from the request object used for authentication. Each entry
|
35
|
+
# given should be a request method and it will automatically be passed to the
|
36
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
37
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
38
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
39
|
+
# config.request_keys = []
|
40
|
+
|
41
|
+
# Configure which authentication keys should be case-insensitive.
|
42
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
43
|
+
# to authenticate or find a user. Default is :email.
|
44
|
+
config.case_insensitive_keys = [:username, :email]
|
45
|
+
|
46
|
+
# Configure which authentication keys should have whitespace stripped.
|
47
|
+
# These keys will have whitespace before and after removed upon creating or
|
48
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
49
|
+
config.strip_whitespace_keys = [:username, :email]
|
50
|
+
|
51
|
+
# Tell if authentication through request.params is enabled. True by default.
|
52
|
+
# It can be set to an array that will enable params authentication only for the
|
53
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
54
|
+
# enable it only for database (email + password) authentication.
|
55
|
+
# config.params_authenticatable = true
|
56
|
+
|
57
|
+
# Tell if authentication through HTTP Auth is enabled. False by default.
|
58
|
+
# It can be set to an array that will enable http authentication only for the
|
59
|
+
# given strategies, for example, `config.http_authenticatable = [:database]` will
|
60
|
+
# enable it only for database authentication. The supported strategies are:
|
61
|
+
# :database = Support basic authentication with authentication key + password
|
62
|
+
# config.http_authenticatable = false
|
63
|
+
|
64
|
+
# If http headers should be returned for AJAX requests. True by default.
|
65
|
+
# config.http_authenticatable_on_xhr = true
|
66
|
+
|
67
|
+
# The realm used in Http Basic Authentication. 'Application' by default.
|
68
|
+
# config.http_authentication_realm = 'Application'
|
69
|
+
|
70
|
+
# It will change confirmation, password recovery and other workflows
|
71
|
+
# to behave the same regardless if the e-mail provided was right or wrong.
|
72
|
+
# Does not affect registerable.
|
73
|
+
# config.paranoid = true
|
74
|
+
|
75
|
+
# By default Devise will store the user in session. You can skip storage for
|
76
|
+
# particular strategies by setting this option.
|
77
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
78
|
+
# may want to disable generating routes to Devise's sessions controller by
|
79
|
+
# passing skip: :sessions to `devise_for` in your config/routes.rb
|
80
|
+
config.skip_session_storage = [:http_auth]
|
81
|
+
|
82
|
+
# By default, Devise cleans up the CSRF token on authentication to
|
83
|
+
# avoid CSRF token fixation attacks. This means that, when using AJAX
|
84
|
+
# requests for sign in and sign up, you need to get a new CSRF token
|
85
|
+
# from the server. You can disable this option at your own risk.
|
86
|
+
# config.clean_up_csrf_token_on_authentication = true
|
87
|
+
|
88
|
+
# ==> Configuration for :database_authenticatable
|
89
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
90
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
91
|
+
#
|
92
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
93
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
94
|
+
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
95
|
+
# encryptor), the cost increases exponentially with the number of stretches (e.g.
|
96
|
+
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
97
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
98
|
+
|
99
|
+
# Setup a pepper to generate the encrypted password.
|
100
|
+
# config.pepper = '2b12b15c7b15b7205f776f689afe0892252ab7273f8be6e46c0bd98b96790f1a930f0587db5a60e768ba79370513cae7c6b11e4babab1a0adabdd9f424f57291'
|
101
|
+
|
102
|
+
# ==> Configuration for :confirmable
|
103
|
+
# A period that the user is allowed to access the website even without
|
104
|
+
# confirming their account. For instance, if set to 2.days, the user will be
|
105
|
+
# able to access the website for two days without confirming their account,
|
106
|
+
# access will be blocked just in the third day. Default is 0.days, meaning
|
107
|
+
# the user cannot access the website without confirming their account.
|
108
|
+
# config.allow_unconfirmed_access_for = 2.days
|
109
|
+
|
110
|
+
# A period that the user is allowed to confirm their account before their
|
111
|
+
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
112
|
+
# their account within 3 days after the mail was sent, but on the fourth day
|
113
|
+
# their account can't be confirmed with the token any more.
|
114
|
+
# Default is nil, meaning there is no restriction on how long a user can take
|
115
|
+
# before confirming their account.
|
116
|
+
# config.confirm_within = 3.days
|
117
|
+
|
118
|
+
# If true, requires any email changes to be confirmed (exactly the same way as
|
119
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
120
|
+
# db field (see migrations). Until confirmed, new email is stored in
|
121
|
+
# unconfirmed_email column, and copied to email column on successful confirmation.
|
122
|
+
config.reconfirmable = true
|
123
|
+
|
124
|
+
# Defines which key will be used when confirming an account
|
125
|
+
# config.confirmation_keys = [ :email ]
|
126
|
+
|
127
|
+
# ==> Configuration for :rememberable
|
128
|
+
# The time the user will be remembered without asking for credentials again.
|
129
|
+
# config.remember_for = 2.weeks
|
130
|
+
|
131
|
+
# If true, extends the user's remember period when remembered via cookie.
|
132
|
+
# config.extend_remember_period = false
|
133
|
+
|
134
|
+
# Options to be passed to the created cookie. For instance, you can set
|
135
|
+
# secure: true in order to force SSL only cookies.
|
136
|
+
# config.rememberable_options = {}
|
137
|
+
|
138
|
+
# ==> Configuration for :validatable
|
139
|
+
# Range for password length.
|
140
|
+
config.password_length = 8..128
|
141
|
+
|
142
|
+
# Email regex used to validate email formats. It simply asserts that
|
143
|
+
# one (and only one) @ exists in the given string. This is mainly
|
144
|
+
# to give user feedback and not to assert the e-mail validity.
|
145
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
146
|
+
|
147
|
+
# ==> Configuration for :timeoutable
|
148
|
+
# The time you want to timeout the user session without activity. After this
|
149
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
150
|
+
# config.timeout_in = 30.minutes
|
151
|
+
|
152
|
+
# If true, expires auth token on session timeout.
|
153
|
+
# config.expire_auth_token_on_timeout = false
|
154
|
+
|
155
|
+
# ==> Configuration for :lockable
|
156
|
+
# Defines which strategy will be used to lock an account.
|
157
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
158
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
159
|
+
# config.lock_strategy = :failed_attempts
|
160
|
+
|
161
|
+
# Defines which key will be used when locking and unlocking an account
|
162
|
+
# config.unlock_keys = [ :email ]
|
163
|
+
|
164
|
+
# Defines which strategy will be used to unlock an account.
|
165
|
+
# :email = Sends an unlock link to the user email
|
166
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
167
|
+
# :both = Enables both strategies
|
168
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
169
|
+
# config.unlock_strategy = :both
|
170
|
+
|
171
|
+
# Number of authentication tries before locking an account if lock_strategy
|
172
|
+
# is failed attempts.
|
173
|
+
# config.maximum_attempts = 20
|
174
|
+
|
175
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
176
|
+
# config.unlock_in = 1.hour
|
177
|
+
|
178
|
+
# Warn on the last attempt before the account is locked.
|
179
|
+
# config.last_attempt_warning = false
|
180
|
+
|
181
|
+
# ==> Configuration for :recoverable
|
182
|
+
#
|
183
|
+
# Defines which key will be used when recovering the password for an account
|
184
|
+
# config.reset_password_keys = [ :email ]
|
185
|
+
|
186
|
+
# Time interval you can reset your password with a reset password key.
|
187
|
+
# Don't put a too small interval or your users won't have the time to
|
188
|
+
# change their passwords.
|
189
|
+
config.reset_password_within = 6.hours
|
190
|
+
|
191
|
+
# ==> Configuration for :encryptable
|
192
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
193
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
194
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
195
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
196
|
+
# REST_AUTH_SITE_KEY to pepper).
|
197
|
+
#
|
198
|
+
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
199
|
+
# config.encryptor = :sha512
|
200
|
+
|
201
|
+
# ==> Scopes configuration
|
202
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
203
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
204
|
+
# are using only default views.
|
205
|
+
# config.scoped_views = false
|
206
|
+
|
207
|
+
# Configure the default scope given to Warden. By default it's the first
|
208
|
+
# devise role declared in your routes (usually :user).
|
209
|
+
# config.default_scope = :user
|
210
|
+
|
211
|
+
# Set this configuration to false if you want /users/sign_out to sign out
|
212
|
+
# only the current scope. By default, Devise signs out all scopes.
|
213
|
+
# config.sign_out_all_scopes = true
|
214
|
+
|
215
|
+
# ==> Navigation configuration
|
216
|
+
# Lists the formats that should be treated as navigational. Formats like
|
217
|
+
# :html, should redirect to the sign in page when the user does not have
|
218
|
+
# access, but formats like :xml or :json, should return 401.
|
219
|
+
#
|
220
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
221
|
+
# should add them to the navigational formats lists.
|
222
|
+
#
|
223
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
224
|
+
# config.navigational_formats = ['*/*', :html]
|
225
|
+
|
226
|
+
# The default HTTP method used to sign out a resource. Default is :delete.
|
227
|
+
config.sign_out_via = :delete
|
228
|
+
|
229
|
+
# ==> OmniAuth
|
230
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
231
|
+
# up on your models and hooks.
|
232
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
233
|
+
|
234
|
+
# ==> Warden configuration
|
235
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
236
|
+
# change the failure app, you can configure them inside the config.warden block.
|
237
|
+
#
|
238
|
+
# config.warden do |manager|
|
239
|
+
# manager.intercept_401 = false
|
240
|
+
# manager.default_strategies(scope: :user).unshift :some_external_strategy
|
241
|
+
# end
|
242
|
+
|
243
|
+
# ==> Mountable engine configurations
|
244
|
+
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
|
245
|
+
# is mountable, there are some extra configurations to be taken into account.
|
246
|
+
# The following options are available, assuming the engine is mounted as:
|
247
|
+
#
|
248
|
+
# mount MyEngine, at: '/my_engine'
|
249
|
+
#
|
250
|
+
# The router that invoked `devise_for`, in the example above, would be:
|
251
|
+
# config.router_name = :my_engine
|
252
|
+
#
|
253
|
+
# When using omniauth, Devise cannot automatically set Omniauth path,
|
254
|
+
# so you need to do it manually. For the users scope, it would be:
|
255
|
+
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
256
|
+
end
|
@@ -45,6 +45,14 @@ module Chaltron
|
|
45
45
|
)
|
46
46
|
end
|
47
47
|
|
48
|
+
#
|
49
|
+
# To allow login with username or email
|
50
|
+
#
|
51
|
+
protected
|
52
|
+
def configure_permitted_parameters
|
53
|
+
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
|
54
|
+
end
|
55
|
+
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Chaltron
|
2
|
+
module Controllers
|
3
|
+
# Those helpers are convenience methods added to ApplicationController.
|
4
|
+
module Helpers
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
rescue_from ::CanCan::AccessDenied do |exception|
|
8
|
+
alert = current_user.nil? ? t('chaltron.access_denied_try_login') : t('chaltron.access_denied')
|
9
|
+
redirect_to root_url, alert: alert
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def log_category
|
15
|
+
defined?(@log_category) ? @log_category : self.to_s.downcase
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_log_category(cat)
|
19
|
+
@log_category = cat.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Utilities for logging
|
25
|
+
#
|
26
|
+
def info(message, category = nil)
|
27
|
+
create_log_message(message, category, :info)
|
28
|
+
end
|
29
|
+
|
30
|
+
def debug(message, category = nil)
|
31
|
+
create_log_message(message, category, :debug)
|
32
|
+
end
|
33
|
+
|
34
|
+
def error(message, category = nil)
|
35
|
+
create_log_message(message, category, :error)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def create_log_message(message, category, severity)
|
40
|
+
category ||= self.class.log_category
|
41
|
+
::Log.create(
|
42
|
+
message: message,
|
43
|
+
category: category.to_s,
|
44
|
+
severity: severity.to_s
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# To allow login with username or email
|
50
|
+
#
|
51
|
+
protected
|
52
|
+
def configure_permitted_parameters
|
53
|
+
|
54
|
+
puts '-------------------------------HERE'
|
55
|
+
|
56
|
+
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/chaltron/engine.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'devise'
|
2
|
+
require 'cancancan'
|
3
|
+
require 'omniauth'
|
4
|
+
require 'omniauth-ldap'
|
5
|
+
require 'bootstrap-sass'
|
6
|
+
require 'autoprefixer-rails'
|
7
|
+
require 'font-awesome-sass'
|
8
|
+
require 'simple-navigation'
|
9
|
+
require 'jquery-datatables-rails'
|
10
|
+
require 'ajax-datatables-rails'
|
11
|
+
require 'bootstrap_form'
|
12
|
+
require 'nprogress-rails'
|
13
|
+
require 'rails-i18n'
|
14
|
+
require 'momentjs-rails'
|
15
|
+
|
16
|
+
require 'simple_navigation_renderers'
|
17
|
+
SimpleNavigation.config_file_paths << File.expand_path('../../../config', __FILE__)
|
18
|
+
|
19
|
+
module Chaltron
|
20
|
+
class Engine < ::Rails::Engine
|
21
|
+
config.generators do |g|
|
22
|
+
g.test_framework :rspec, fixture: false
|
23
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
24
|
+
g.assets false
|
25
|
+
g.helper false
|
26
|
+
end
|
27
|
+
|
28
|
+
config.app_generators do |g|
|
29
|
+
g.templates.unshift File::expand_path('../../templates', __FILE__)
|
30
|
+
end
|
31
|
+
|
32
|
+
initializer('chaltron.locales') do |_app|
|
33
|
+
Chaltron::Engine.config.i18n.load_path += Dir[root.join('app/views', 'locales', '*.{rb,yml}')]
|
34
|
+
Chaltron::Engine.config.i18n.load_path += Dir[root.join('app/models', 'locales', '*.{rb,yml}')]
|
35
|
+
end
|
36
|
+
|
37
|
+
initializer('chaltron.helpers') do |_app|
|
38
|
+
ActiveSupport.on_load(:action_controller) do
|
39
|
+
include Chaltron::Controllers::Helpers
|
40
|
+
|
41
|
+
puts '--------------------------DEBUG'
|
42
|
+
|
43
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# LDAP extension for User ::User
|
2
|
+
#
|
3
|
+
# * Find or create user from omniauth.auth data
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'chaltron/ldap/person'
|
7
|
+
|
8
|
+
module Chaltron
|
9
|
+
module LDAP
|
10
|
+
class User
|
11
|
+
class << self
|
12
|
+
attr_reader :auth
|
13
|
+
|
14
|
+
def find_or_create(auth, create)
|
15
|
+
@auth = auth
|
16
|
+
if uid.blank? || email.blank? || username.blank?
|
17
|
+
raise_error('Account must provide a dn, uid and email address')
|
18
|
+
end
|
19
|
+
user = find_by_uid_and_provider
|
20
|
+
|
21
|
+
puts "DEBUG user = #{user}"
|
22
|
+
|
23
|
+
entry = Chaltron::LDAP::Person.find_by_uid(username)
|
24
|
+
|
25
|
+
|
26
|
+
puts "DEBUG entry = #{entry}"
|
27
|
+
|
28
|
+
|
29
|
+
if user.nil? and create
|
30
|
+
# create user
|
31
|
+
user = entry.create_user Chaltron.default_roles
|
32
|
+
end
|
33
|
+
update_ldap_attributes(user, entry) unless user.nil?
|
34
|
+
user
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def update_ldap_attributes(user, entry)
|
40
|
+
user.update_attributes!(
|
41
|
+
email: entry.email,
|
42
|
+
department: entry.department
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_by_uid_and_provider
|
47
|
+
# LDAP distinguished name is case-insensitive
|
48
|
+
user = ::User.where('provider = ? and lower(extern_uid) = ?', provider, uid.downcase).last
|
49
|
+
if user.nil?
|
50
|
+
# Look for user with same emails
|
51
|
+
#
|
52
|
+
# Possible cases:
|
53
|
+
# * When user already has account and need to link their LDAP account.
|
54
|
+
# * LDAP uid changed for user with same email and we need to update their uid
|
55
|
+
#
|
56
|
+
user = ::User.find_by(email: email)
|
57
|
+
user.update_attributes!(extern_uid: uid, provider: provider) unless user.nil?
|
58
|
+
end
|
59
|
+
user
|
60
|
+
end
|
61
|
+
|
62
|
+
def uid
|
63
|
+
auth.info.uid || auth.uid
|
64
|
+
end
|
65
|
+
|
66
|
+
def email
|
67
|
+
auth.info.email.downcase unless auth.info.email.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def name
|
71
|
+
auth.info.name.to_s.force_encoding('utf-8')
|
72
|
+
end
|
73
|
+
|
74
|
+
def username
|
75
|
+
auth.info.nickname.to_s.force_encoding('utf-8')
|
76
|
+
end
|
77
|
+
|
78
|
+
def provider
|
79
|
+
'ldap'
|
80
|
+
end
|
81
|
+
|
82
|
+
def raise_error(message)
|
83
|
+
fail OmniAuth::Error, '(LDAP) ' + message
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/chaltron/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chaltron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vicvega
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -384,12 +384,15 @@ files:
|
|
384
384
|
- app/assets/stylesheets/chaltron.scss
|
385
385
|
- app/assets/stylesheets/chaltron/datatables.scss
|
386
386
|
- app/assets/stylesheets/chaltron/layout.scss
|
387
|
+
- app/assets/stylesheets/chaltron/layout.scss~
|
387
388
|
- app/assets/stylesheets/chaltron/mixins.scss
|
388
389
|
- app/controllers/chaltron/ldap_controller.rb
|
389
390
|
- app/controllers/chaltron/logs_controller.rb
|
390
391
|
- app/controllers/chaltron/omniauth_callbacks_controller.rb
|
392
|
+
- app/controllers/chaltron/omniauth_callbacks_controller.rb~
|
391
393
|
- app/controllers/chaltron/sessions_controller.rb
|
392
394
|
- app/controllers/chaltron/users_controller.rb
|
395
|
+
- app/controllers/chaltron/users_controller.rb~
|
393
396
|
- app/datatables/log_datatable.rb
|
394
397
|
- app/helpers/chaltron/ldap_helper.rb
|
395
398
|
- app/helpers/chaltron/logs_helper.rb
|
@@ -400,6 +403,7 @@ files:
|
|
400
403
|
- app/models/locales/it.yml
|
401
404
|
- app/models/log.rb
|
402
405
|
- app/models/user.rb
|
406
|
+
- app/models/user.rb~
|
403
407
|
- app/views/chaltron/ldap/_entry.html.erb
|
404
408
|
- app/views/chaltron/ldap/multi_create.html.erb
|
405
409
|
- app/views/chaltron/ldap/multi_new.html.erb
|
@@ -412,6 +416,7 @@ files:
|
|
412
416
|
- app/views/chaltron/users/_user.html.erb
|
413
417
|
- app/views/chaltron/users/edit.html.erb
|
414
418
|
- app/views/chaltron/users/index.html.erb
|
419
|
+
- app/views/chaltron/users/index.html.erb~
|
415
420
|
- app/views/chaltron/users/new.html.erb
|
416
421
|
- app/views/chaltron/users/self_edit.html.erb
|
417
422
|
- app/views/chaltron/users/self_show.html.erb
|
@@ -421,12 +426,17 @@ files:
|
|
421
426
|
- app/views/devise/passwords/edit.html.erb
|
422
427
|
- app/views/devise/passwords/new.html.erb
|
423
428
|
- app/views/devise/sessions/_new_ldap.html.erb
|
429
|
+
- app/views/devise/sessions/_new_ldap.html.erb~
|
424
430
|
- app/views/devise/sessions/_new_local.html.erb
|
431
|
+
- app/views/devise/sessions/_new_local.html.erb~
|
425
432
|
- app/views/devise/sessions/new.html.erb
|
426
433
|
- app/views/locales/en.yml
|
434
|
+
- app/views/locales/en.yml~
|
427
435
|
- app/views/locales/it.yml
|
436
|
+
- app/views/locales/it.yml~
|
428
437
|
- config/chaltron_navigation.rb
|
429
438
|
- config/initializers/devise.rb
|
439
|
+
- config/initializers/devise.rb~
|
430
440
|
- config/locales/devise.en.yml
|
431
441
|
- config/locales/devise.it.yml
|
432
442
|
- config/locales/en.yml
|
@@ -442,11 +452,15 @@ files:
|
|
442
452
|
- lib/chaltron/banner.rb
|
443
453
|
- lib/chaltron/bootstrap_form.rb
|
444
454
|
- lib/chaltron/controllers/helpers.rb
|
455
|
+
- lib/chaltron/controllers/helpers.rb~
|
445
456
|
- lib/chaltron/engine.rb
|
457
|
+
- lib/chaltron/engine.rb~
|
446
458
|
- lib/chaltron/ldap/connection.rb
|
447
459
|
- lib/chaltron/ldap/person.rb
|
448
460
|
- lib/chaltron/ldap/user.rb
|
461
|
+
- lib/chaltron/ldap/user.rb~
|
449
462
|
- lib/chaltron/version.rb
|
463
|
+
- lib/chaltron/version.rb~
|
450
464
|
- lib/generators/chaltron/install_generator.rb
|
451
465
|
- lib/generators/chaltron/templates/app/assets/javascripts/home.js.coffee
|
452
466
|
- lib/generators/chaltron/templates/app/assets/stylesheets/home.scss
|
@@ -489,7 +503,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
489
503
|
version: '0'
|
490
504
|
requirements: []
|
491
505
|
rubyforge_project:
|
492
|
-
rubygems_version: 2.4.
|
506
|
+
rubygems_version: 2.4.8
|
493
507
|
signing_key:
|
494
508
|
specification_version: 4
|
495
509
|
summary: Move faster and break things - revisited for rails 4
|