Commit c9f0d22a authored by Jean-Noël Rouchon's avatar Jean-Noël Rouchon

Fonctions d'ajout et de modification d'utilisateurs

parent a182d6c3
......@@ -228,3 +228,26 @@ get '/users' do
@users = Technician.order(:name)
haml :users
end
post '/users' do
authentification?
user = nil
if params["userId"].to_i>0
user = Technician.find(params["userId"])
else
user = Technician.new
end
user.name = params["userName"]
user.login = params["userLogin"]
user.email = params["userEmail"]
user.admin = params["userAdmin"]
user.actif = params["userActif"]
unless params["userPassword"].empty?
salt = BCrypt::Engine.generate_salt
passwordhash = BCrypt::Engine.hash_secret(params["userPassword"], salt)
user.salt = salt
user.passwordhash = passwordhash
end
user.save
redirect "/users"
end
-# encoding: UTF-8
%h2
Site
Utilisateurs
.col-md-12
.table-responsive
%table.table.table-hover
......@@ -11,8 +11,9 @@
%th email
%th admin?
%th actif?
%th
- @users.each do |user|
%tr{onclick: "window.document.location='/users/#{user.id}';"}
%tr
%td
= user.name
%td
......@@ -23,8 +24,71 @@
= (user.admin ? "oui" : "non")
%td
= (user.actif ? "oui" : "non")
//%a.btn.btn-primary{href: "/users/0"}
// Nouvel utilisateur
//ou
%td
%button.btn.btn-success.btn-xs{type: "button", "data-id"=>"#{user.id}", "data-toggle"=>"modal", "data-target"=>"#myModal", "data-name" => "#{user.name}", "data-login" => "#{user.login}", "data-title" => "Utilisateur n°#{user.id}", "data-email" => "#{user.email}", "data-admin" => "#{user.admin}", "data-actif" => "#{user.actif}"}
Modifier
%button.btn.btn-primary{type: "button", "data-id"=>"0", "data-toggle"=>"modal", "data-target"=>"#myModal", "data-admin" => "false", "data-actif" => "true"}
Nouvel utilisateur
ou
%a{href: "/configuration"}
Retour
.modal.fade{id: "myModal", tabindex: "-1", role: "dialog", "aria-labelledby" => "myModalLabel", "aria-hidden" => true}
.modal-dialog.modal-lg
.modal-content
.modal-header
%button.close{"data-dismiss" => "modal", "aria-label" => "Close"}
%span{"aria-hidden"=>true}
×
%h4.modal-title{id: "myModalLabel"}
Ajouter un utilisateur
.modal-body
%form.form-horizontal{id: "formAction", action: '/users', method: 'post'}
.form-group
%input{type: "text", id: 'userId', name: 'userId', hidden: true}
%label.col-sm-2{for:"userName" , "control-label" => true}
Nom
.col-sm-10
%input{id: "userName", name: "userName", type: "text", required: true}
%label.col-sm-2{for:"userLogin" , "control-label" => true}
Login
.col-sm-10
%input{id: "userLogin", name: "userLogin", type: "text", required: true}
%label.col-sm-2{for:"userEmail" , "control-label" => true}
Email
.col-sm-10
%input{id: "userEmail", name: "userEmail", type: "text"}
%label.col-sm-2{for:"userAdmin" , "control-label" => true}
Admin ?
.col-sm-10
%input{id: "userAdmin", name: "userAdmin", type: "checkbox"}
%label.col-sm-2{for:"userActif" , "control-label" => true}
Actif ?
.col-sm-10
%input{id: "userActif", name: "userActif", type: "checkbox"}
%label.col-sm-2{for:"userPassword" , "control-label" => true}
Mot de passe
.col-sm-10
%input{id: "userPassword", name: "userPassword", type: "password"}
.modal-footer
%button.btn.btn-primary{type: "submit", form: "formAction"}
Enregistrer
ou
%a{"data-dismiss"=>"modal"}
Annuler
:javascript
jQuery(document).ready(function() {
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var modal = $(this);
modal.find('.modal-title').text(button.data('title'));
$('#userId').val(button.data('id'));
$('#userName').val(button.data('name'));
$('#userLogin').val(button.data('login'));
$('#userEmail').val(button.data('email'));
$('#userAdmin').prop('checked',button.data('admin'));
$('#userActif').prop('checked',button.data('actif'));
$('#userPassword').val("");
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment