Add Administrateurs role and his connexion is ok.
This commit is contained in:
parent
b00b79ce35
commit
49627fccad
11 changed files with 135 additions and 21 deletions
6
app/controllers/admin_controller.rb
Normal file
6
app/controllers/admin_controller.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class AdminController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
redirect_to(controller: '/administrateurs/sessions', action: :new) unless administrateur_signed_in?
|
||||||
|
end
|
||||||
|
end
|
15
app/controllers/administrateurs/sessions_controller.rb
Normal file
15
app/controllers/administrateurs/sessions_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class Administrateurs::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
|
def new
|
||||||
|
@administrateur = Administrateur.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_sign_in_path_for(resource)
|
||||||
|
# stored_location_for(resource) ||
|
||||||
|
admin_path
|
||||||
|
end
|
||||||
|
end
|
6
app/models/administrateur.rb
Normal file
6
app/models/administrateur.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class Administrateur < ActiveRecord::Base
|
||||||
|
# Include default devise modules. Others available are:
|
||||||
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
|
devise :database_authenticatable, :registerable,
|
||||||
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
end
|
1
app/views/admin/index.html.haml
Normal file
1
app/views/admin/index.html.haml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
%p Coucou
|
10
app/views/administrateurs/sessions/new.html.haml
Normal file
10
app/views/administrateurs/sessions/new.html.haml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
%h1 Bienvenue sur TPS - Administration
|
||||||
|
%br
|
||||||
|
#gestionnaire_login
|
||||||
|
= form_for @administrateur, url: {controller: 'administrateurs/sessions', action: :create } do |f|
|
||||||
|
.form-group-lg
|
||||||
|
.form-group
|
||||||
|
= f.text_field :email, class: 'form-control', placeholder: 'Email'
|
||||||
|
.form-group
|
||||||
|
= f.password_field :password, class: 'form-control', placeholder: 'Mot de passe'
|
||||||
|
= f.submit 'Se connecter', class: %w(btn btn-lg btn-success), data: { disable_with: 'Connexion', submit: true }
|
|
@ -1,4 +1,4 @@
|
||||||
%h1 Bienvenue sur TPS
|
%h1 Bienvenue sur TPS - Gestionnaire
|
||||||
%br
|
%br
|
||||||
#gestionnaire_login
|
#gestionnaire_login
|
||||||
= form_for @gestionnaire, url: {controller: 'gestionnaires/sessions', action: :create } do |f|
|
= form_for @gestionnaire, url: {controller: 'gestionnaires/sessions', action: :create } do |f|
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
||||||
= current_gestionnaire.email
|
= current_gestionnaire.email
|
||||||
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
|
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
|
||||||
|
-elsif administrateur_signed_in?
|
||||||
|
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
||||||
|
= current_administrateur.email
|
||||||
|
= link_to "Déconnexion", '/administrateurs/sign_out', method: :delete, :class => 'btn btn-md'
|
||||||
|
|
||||||
- elsif user_signed_in?
|
- elsif user_signed_in?
|
||||||
%div.user{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
%div.user{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
|
||||||
-if current_user.loged_in_with_france_connect
|
-if current_user.loged_in_with_france_connect
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
devise_for :administrateurs, controllers: {
|
||||||
sessions: 'users/sessions'
|
sessions: 'administrateurs/sessions'
|
||||||
}
|
}, skip: [:password, :registrations]
|
||||||
|
|
||||||
devise_for :gestionnaires, controllers: {
|
devise_for :gestionnaires, controllers: {
|
||||||
sessions: 'gestionnaires/sessions'
|
sessions: 'gestionnaires/sessions'
|
||||||
}, skip: [:password, :registrations]
|
}, skip: [:password, :registrations]
|
||||||
|
|
||||||
|
devise_for :users, controllers: {
|
||||||
|
sessions: 'users/sessions'
|
||||||
|
}
|
||||||
|
|
||||||
root 'users/dossiers#index'
|
root 'users/dossiers#index'
|
||||||
|
|
||||||
get 'france_connect' => 'france_connect#login'
|
get 'france_connect' => 'france_connect#login'
|
||||||
|
@ -35,23 +39,11 @@ Rails.application.routes.draw do
|
||||||
resource :dossiers
|
resource :dossiers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get 'admin' => 'admin#index'
|
||||||
|
|
||||||
# resources :dossiers do
|
namespace :admin do
|
||||||
|
get 'sign_in' => '/administrateurs/sessions#new'
|
||||||
|
end
|
||||||
# # get '/carte/position' => 'carte#get_position'
|
|
||||||
# # get '/carte' => 'carte#show'
|
|
||||||
# # post '/carte' => 'carte#save_ref_api_carto'
|
|
||||||
|
|
||||||
# # get '/description' => 'description#show'
|
|
||||||
# # get '/description/error' => 'description#error'
|
|
||||||
# # post 'description' => 'description#create'
|
|
||||||
|
|
||||||
|
|
||||||
# post '/commentaire' => 'commentaires#create'
|
|
||||||
|
|
||||||
# end
|
|
||||||
|
|
||||||
|
|
||||||
get 'backoffice' => 'backoffice#index'
|
get 'backoffice' => 'backoffice#index'
|
||||||
|
|
||||||
|
@ -63,6 +55,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :commentaires, only: [:create]
|
resources :commentaires, only: [:create]
|
||||||
end
|
end
|
||||||
|
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
||||||
|
|
42
db/migrate/20151023132121_devise_create_administrateurs.rb
Normal file
42
db/migrate/20151023132121_devise_create_administrateurs.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
class DeviseCreateAdministrateurs < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table(:administrateurs) do |t|
|
||||||
|
## Database authenticatable
|
||||||
|
t.string :email, null: false, default: ""
|
||||||
|
t.string :encrypted_password, null: false, default: ""
|
||||||
|
|
||||||
|
## Recoverable
|
||||||
|
t.string :reset_password_token
|
||||||
|
t.datetime :reset_password_sent_at
|
||||||
|
|
||||||
|
## Rememberable
|
||||||
|
t.datetime :remember_created_at
|
||||||
|
|
||||||
|
## Trackable
|
||||||
|
t.integer :sign_in_count, default: 0, null: false
|
||||||
|
t.datetime :current_sign_in_at
|
||||||
|
t.datetime :last_sign_in_at
|
||||||
|
t.inet :current_sign_in_ip
|
||||||
|
t.inet :last_sign_in_ip
|
||||||
|
|
||||||
|
## Confirmable
|
||||||
|
# t.string :confirmation_token
|
||||||
|
# t.datetime :confirmed_at
|
||||||
|
# t.datetime :confirmation_sent_at
|
||||||
|
# t.string :unconfirmed_email # Only if using reconfirmable
|
||||||
|
|
||||||
|
## Lockable
|
||||||
|
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
||||||
|
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
||||||
|
# t.datetime :locked_at
|
||||||
|
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :administrateurs, :email, unique: true
|
||||||
|
add_index :administrateurs, :reset_password_token, unique: true
|
||||||
|
# add_index :administrateurs, :confirmation_token, unique: true
|
||||||
|
# add_index :administrateurs, :unlock_token, unique: true
|
||||||
|
end
|
||||||
|
end
|
20
db/schema.rb
20
db/schema.rb
|
@ -11,11 +11,29 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20151008090835) do
|
ActiveRecord::Schema.define(version: 20151023132121) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "administrateurs", force: :cascade do |t|
|
||||||
|
t.string "email", default: "", null: false
|
||||||
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
t.string "reset_password_token"
|
||||||
|
t.datetime "reset_password_sent_at"
|
||||||
|
t.datetime "remember_created_at"
|
||||||
|
t.integer "sign_in_count", default: 0, null: false
|
||||||
|
t.datetime "current_sign_in_at"
|
||||||
|
t.datetime "last_sign_in_at"
|
||||||
|
t.inet "current_sign_in_ip"
|
||||||
|
t.inet "last_sign_in_ip"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree
|
||||||
|
add_index "administrateurs", ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "cerfas", force: :cascade do |t|
|
create_table "cerfas", force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
t.integer "dossier_id"
|
t.integer "dossier_id"
|
||||||
|
|
18
spec/models/administrateur_spec.rb
Normal file
18
spec/models/administrateur_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Administrateur, type: :model do
|
||||||
|
describe 'database column' do
|
||||||
|
it { is_expected.to have_db_column(:email) }
|
||||||
|
it { is_expected.to have_db_column(:encrypted_password) }
|
||||||
|
it { is_expected.to have_db_column(:reset_password_token) }
|
||||||
|
it { is_expected.to have_db_column(:reset_password_sent_at) }
|
||||||
|
it { is_expected.to have_db_column(:remember_created_at) }
|
||||||
|
it { is_expected.to have_db_column(:sign_in_count) }
|
||||||
|
it { is_expected.to have_db_column(:current_sign_in_at) }
|
||||||
|
it { is_expected.to have_db_column(:last_sign_in_at) }
|
||||||
|
it { is_expected.to have_db_column(:current_sign_in_ip) }
|
||||||
|
it { is_expected.to have_db_column(:last_sign_in_ip) }
|
||||||
|
it { is_expected.to have_db_column(:created_at) }
|
||||||
|
it { is_expected.to have_db_column(:updated_at) }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue