From 744f29c674f51223c812d08ff57ad9f085df31de Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 20 Mar 2015 16:39:32 +0200 Subject: [PATCH] Refactor sessions --- .travis.yml | 2 +- app/assets/stylesheets/app.sass | 7 +++++ app/controllers/admin/sessions_controller.rb | 10 +++++++ app/controllers/application_controller.rb | 9 ++++-- .../registrar/invoices_controller.rb | 7 +++++ .../registrar/sessions_controller.rb | 7 +++++ app/controllers/registrar_controller.rb | 4 +++ app/controllers/sessions_controller.rb | 4 --- app/models/ability.rb | 1 + app/models/invoice.rb | 3 ++ app/views/admin/sessions/login.haml | 6 ++++ app/views/layouts/login_registrar.haml | 27 +++++++++++++++++ app/views/layouts/registrar.haml | 5 ++-- app/views/registrar/invoices/index.haml | 1 + app/views/registrar/sessions/login.haml | 6 ++++ config/routes.rb | 29 +++++++++++++++---- db/migrate/20150320132023_create_invoices.rb | 7 +++++ db/schema.rb | 7 ++++- 18 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 app/controllers/admin/sessions_controller.rb create mode 100644 app/controllers/registrar/invoices_controller.rb create mode 100644 app/controllers/registrar/sessions_controller.rb create mode 100644 app/controllers/registrar_controller.rb create mode 100644 app/models/invoice.rb create mode 100644 app/views/admin/sessions/login.haml create mode 100644 app/views/layouts/login_registrar.haml create mode 100644 app/views/registrar/invoices/index.haml create mode 100644 app/views/registrar/sessions/login.haml create mode 100644 db/migrate/20150320132023_create_invoices.rb diff --git a/.travis.yml b/.travis.yml index cb0a3fc07..9db737a18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: - cp config/database-travis.yml config/database.yml - RAILS_ENV=test bundle exec rake db:all:schema:load - RAILS_ENV=test bundle exec rake db:seed -script: +script: - RAILS_ENV=test bundle exec rake cache: bundler services: diff --git a/app/assets/stylesheets/app.sass b/app/assets/stylesheets/app.sass index 8722b8523..64b9857d4 100644 --- a/app/assets/stylesheets/app.sass +++ b/app/assets/stylesheets/app.sass @@ -20,3 +20,10 @@ .nowrap white-space: nowrap + +.form-signin + max-width: 330px + padding: 15px + margin: 0 auto + input + margin-bottom: 10px diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb new file mode 100644 index 000000000..866711dac --- /dev/null +++ b/app/controllers/admin/sessions_controller.rb @@ -0,0 +1,10 @@ +class Admin::SessionsController < SessionsController + layout 'login' + + def create + super + end + + def login + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8840e4989..e48b785d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,9 +17,14 @@ class ApplicationController < ActionController::Base def after_sign_in_path_for(_resource) if session[:user_return_to] && session[:user_return_to] != login_path - return session[:user_return_to].to_s + return session[:user_return_to].to_s + end + + if request.path.match('registrar') + registrar_invoices_path + elsif request.path.match('admin') + admin_dashboard_path end - admin_dashboard_path end def user_for_paper_trail diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb new file mode 100644 index 000000000..610fa4693 --- /dev/null +++ b/app/controllers/registrar/invoices_controller.rb @@ -0,0 +1,7 @@ +class Registrar::InvoicesController < RegistrarController + load_and_authorize_resource + + def index + + end +end diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb new file mode 100644 index 000000000..89d445b2f --- /dev/null +++ b/app/controllers/registrar/sessions_controller.rb @@ -0,0 +1,7 @@ +class Registrar::SessionsController < SessionsController + layout 'registrar' + + def login + + end +end diff --git a/app/controllers/registrar_controller.rb b/app/controllers/registrar_controller.rb new file mode 100644 index 000000000..6425f0f92 --- /dev/null +++ b/app/controllers/registrar_controller.rb @@ -0,0 +1,4 @@ +class RegistrarController < ApplicationController + before_action :authenticate_user! + layout 'registrar' +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ff4f74517..103283f6b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -14,8 +14,4 @@ class SessionsController < Devise::SessionsController sign_in_and_redirect @user, event: :authentication # end end - - def login - render 'layouts/login', layout: false - end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 3e7105692..fe5b574bf 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -40,6 +40,7 @@ class Ability def user can :show, :dashboard + can :manage, Invoice end def customer_service diff --git a/app/models/invoice.rb b/app/models/invoice.rb new file mode 100644 index 000000000..97a2d56d2 --- /dev/null +++ b/app/models/invoice.rb @@ -0,0 +1,3 @@ +class Invoice < ActiveRecord::Base + +end diff --git a/app/views/admin/sessions/login.haml b/app/views/admin/sessions/login.haml new file mode 100644 index 000000000..6dec84141 --- /dev/null +++ b/app/views/admin/sessions/login.haml @@ -0,0 +1,6 @@ +.form-signin + / TODO: Refactor this when ID card login is done + = button_to 'ID card (user1)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user1' + = button_to 'ID card (user2)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user2' diff --git a/app/views/layouts/login_registrar.haml b/app/views/layouts/login_registrar.haml new file mode 100644 index 000000000..f00e48f36 --- /dev/null +++ b/app/views/layouts/login_registrar.haml @@ -0,0 +1,27 @@ +!!! +%html{:lang => I18n.locale.to_s} + %head + %meta{:charset => "utf-8"}/ + %meta{:content => "IE=edge", "http-equiv" => "X-UA-Compatible"}/ + %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}/ + %meta{:content => "EIS Registrar portal", :name => "description"}/ + %meta{:content => "Gitlab Ltd", :name => "author"}/ + = csrf_meta_tags + = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true + = stylesheet_link_tag 'login', media: 'all', 'data-turbolinks-track' => true + %link{:href => "../../favicon.ico", :rel => "icon"}/ + %title EIS Registrar - Log In + %body{:style => env_style} + .container + .form-signin + - display = (flash.empty?) ? 'none' : 'block' + #flash{style: "display: #{display};"} + - type = (flash[:notice]) ? 'bg-success' : 'bg-danger' + .alert{class: type}= flash[:notice] || flash[:alert] + %h2.form-signin-heading.text-center Eesti Interneti SA + %hr + / TODO: Refactor this when ID card login is done + = button_to 'ID card (user1)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user1' + = button_to 'ID card (user2)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user2' diff --git a/app/views/layouts/registrar.haml b/app/views/layouts/registrar.haml index 9e2ab4f97..27197aa9a 100644 --- a/app/views/layouts/registrar.haml +++ b/app/views/layouts/registrar.haml @@ -25,8 +25,9 @@ - if unstable_env.present? .text-center %small{style: 'color: #0074B3;'}= unstable_env - %ul.nav.navbar-nav.navbar-right - %li= link_to t('log_out', user: current_user), '/logout' + - if current_user + %ul.nav.navbar-nav.navbar-right + %li= link_to t('log_out', user: current_user), '/logout' / /.nav-collapse .container diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml new file mode 100644 index 000000000..7ac71c3e8 --- /dev/null +++ b/app/views/registrar/invoices/index.haml @@ -0,0 +1 @@ +invoices diff --git a/app/views/registrar/sessions/login.haml b/app/views/registrar/sessions/login.haml new file mode 100644 index 000000000..6dec84141 --- /dev/null +++ b/app/views/registrar/sessions/login.haml @@ -0,0 +1,6 @@ +.form-signin + / TODO: Refactor this when ID card login is done + = button_to 'ID card (user1)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user1' + = button_to 'ID card (user2)', 'sessions', + class: 'btn btn-lg btn-primary btn-block', name: 'user2' diff --git a/config/routes.rb b/config/routes.rb index 225ecaca2..cc48a3e07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,21 +65,38 @@ Rails.application.routes.draw do resources :epp_logs resources :repp_logs + devise_scope :user do + get 'login' => 'sessions#login' + post 'sessions' => 'sessions#create' + end + + root 'domains#index' + end + + namespace(:registrar) do + resources :invoices + + devise_scope :user do + get 'login' => 'sessions#login' + post 'sessions' => 'sessions#create' + end + + # authenticated :user do + # root to: 'domains#index', as: :authenticated_root + # end + root 'domains#index' end devise_for :users devise_scope :user do - resources :sessions - get 'logout' => 'devise/sessions#destroy' - get 'login' => 'sessions#login' end - authenticated :user do - root to: 'admin/domains#index', as: :authenticated_root - end + # authenticated :user do + # root to: 'admin/domains#index', as: :authenticated_root + # end root to: redirect('login') diff --git a/db/migrate/20150320132023_create_invoices.rb b/db/migrate/20150320132023_create_invoices.rb new file mode 100644 index 000000000..9caf0082a --- /dev/null +++ b/db/migrate/20150320132023_create_invoices.rb @@ -0,0 +1,7 @@ +class CreateInvoices < ActiveRecord::Migration + def change + create_table :invoices do |t| + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fdedb6f22..4945b36fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150303151224) do +ActiveRecord::Schema.define(version: 20150320132023) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -226,6 +226,11 @@ ActiveRecord::Schema.define(version: 20150303151224) do add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, using: :btree add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree + create_table "invoices", force: :cascade do |t| + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "keyrelays", force: :cascade do |t| t.integer "domain_id" t.datetime "pa_date"