mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Add monban for admin authentication
This commit is contained in:
parent
ef0d0bce0f
commit
2995460e97
4
app/assets/stylesheets/administrate/overrides.css.scss
Normal file
4
app/assets/stylesheets/administrate/overrides.css.scss
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.sign_out {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 1.5em;
|
||||||
|
}
|
||||||
@ -5,11 +5,9 @@
|
|||||||
# If you want to add pagination or other controller-level concerns,
|
# If you want to add pagination or other controller-level concerns,
|
||||||
# you're free to overwrite the RESTful controller actions.
|
# you're free to overwrite the RESTful controller actions.
|
||||||
class Admin::ApplicationController < Administrate::ApplicationController
|
class Admin::ApplicationController < Administrate::ApplicationController
|
||||||
before_filter :authenticate_admin
|
include Monban::ControllerHelpers
|
||||||
|
|
||||||
def authenticate_admin
|
before_filter :require_login
|
||||||
# TODO Add authentication logic here.
|
|
||||||
end
|
|
||||||
|
|
||||||
# Override this value to specify the number of elements to display at a time
|
# Override this value to specify the number of elements to display at a time
|
||||||
# on index pages. Defaults to 20.
|
# on index pages. Defaults to 20.
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
include Monban::ControllerHelpers
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
||||||
|
|||||||
29
app/controllers/sessions_controller.rb
Normal file
29
app/controllers/sessions_controller.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
class SessionsController < ApplicationController
|
||||||
|
layout 'administrate/login'
|
||||||
|
|
||||||
|
skip_before_action :require_login, only: [:new, :create]
|
||||||
|
|
||||||
|
def new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
user = authenticate_session(session_params)
|
||||||
|
|
||||||
|
if sign_in(user)
|
||||||
|
redirect_to admin_root_path
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
sign_out
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def session_params
|
||||||
|
params.require(:session).permit(:email, :password)
|
||||||
|
end
|
||||||
|
end
|
||||||
25
app/controllers/users_controller.rb
Normal file
25
app/controllers/users_controller.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
class UsersController < ApplicationController
|
||||||
|
skip_before_action :require_login, only: [:new, :create]
|
||||||
|
|
||||||
|
def new
|
||||||
|
@user = User.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@user = sign_up(user_params)
|
||||||
|
|
||||||
|
if @user.valid?
|
||||||
|
sign_in(@user)
|
||||||
|
redirect_to root_path
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def user_params
|
||||||
|
params.require(:user).permit(:email, :password)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@ -1,2 +1,4 @@
|
|||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
|
validates :email, presence: true, uniqueness: true
|
||||||
|
validates :password_digest, presence: true
|
||||||
end
|
end
|
||||||
|
|||||||
34
app/views/layouts/administrate/application.html.erb
Normal file
34
app/views/layouts/administrate/application.html.erb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="ROBOTS" content="NOODP" />
|
||||||
|
<meta name="viewport" content="initial-scale=1" />
|
||||||
|
<title><%= content_for(:title) %> | <%= Rails.application.class.parent_name.titlecase %></title>
|
||||||
|
<%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400,900", media: "all" %>
|
||||||
|
<%= stylesheet_link_tag "administrate/application", media: "all" %>
|
||||||
|
<%= stylesheet_link_tag "administrate/overrides", media: "all" %>
|
||||||
|
<%= csrf_meta_tags %>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="administrate">
|
||||||
|
<main class="main">
|
||||||
|
<div class="sidebar">
|
||||||
|
<%= render "sidebar" -%>
|
||||||
|
<%= content_tag :div, class: :sign_out do %>
|
||||||
|
<%= link_to "Sign out", session_path, method: :delete %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<%= content_for(:search) %>
|
||||||
|
<div class="content">
|
||||||
|
<%= render "flashes" -%>
|
||||||
|
<%= yield %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<%= render "javascript" %>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
app/views/layouts/administrate/login.html.erb
Normal file
24
app/views/layouts/administrate/login.html.erb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="ROBOTS" content="NOODP" />
|
||||||
|
<meta name="viewport" content="initial-scale=1" />
|
||||||
|
<title><%= content_for(:title) %> | <%= Rails.application.class.parent_name.titlecase %></title>
|
||||||
|
<%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400,900", media: "all" %>
|
||||||
|
<%= stylesheet_link_tag "administrate/application", media: "all" %>
|
||||||
|
<%= stylesheet_link_tag "login", media: "all" %>
|
||||||
|
<%= csrf_meta_tags %>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="administrate">
|
||||||
|
<main class="main">
|
||||||
|
<div class="container">
|
||||||
|
<div class="content">
|
||||||
|
<%= render "administrate/application/flashes" -%>
|
||||||
|
<%= yield %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
app/views/sessions/new.html.erb
Normal file
13
app/views/sessions/new.html.erb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<%= form_for :session, url: session_path do |form| %>
|
||||||
|
<div>
|
||||||
|
<%= form.label :email %>
|
||||||
|
<%= form.email_field :email %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :password %>
|
||||||
|
<%= form.password_field :password %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.submit "Sign in" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
23
app/views/users/new.html.erb
Normal file
23
app/views/users/new.html.erb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<%= form_for @user do |form| %>
|
||||||
|
|
||||||
|
<% if @user.errors.any? %>
|
||||||
|
<%= pluralize(@user.errors.count, "error") %> prevented your account from being created:
|
||||||
|
<ul>
|
||||||
|
<% @user.errors.full_messages.each do |error_message| %>
|
||||||
|
<li><%= error_message %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :email %>
|
||||||
|
<%= form.email_field :email %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.label :password %>
|
||||||
|
<%= form.password_field :password %>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<%= form.submit "Sign up" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@ -1,6 +1,6 @@
|
|||||||
# Be sure to restart your server when you modify this file.
|
# Be sure to restart your server when you modify this file.
|
||||||
|
|
||||||
DanBarberPhoto::Application.config.session_store :cookie_store, key: '_danbarberphoto_session', secure: true
|
DanBarberPhoto::Application.config.session_store :cookie_store, key: '_danbarberphoto_session'
|
||||||
|
|
||||||
# Use the database for sessions instead of the cookie-based default,
|
# Use the database for sessions instead of the cookie-based default,
|
||||||
# which shouldn't be used to store highly confidential information
|
# which shouldn't be used to store highly confidential information
|
||||||
|
|||||||
5
config/locales/monban.en.yml
Normal file
5
config/locales/monban.en.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
en:
|
||||||
|
activerecord:
|
||||||
|
attributes:
|
||||||
|
user:
|
||||||
|
password_digest: "Password"
|
||||||
@ -1,4 +1,12 @@
|
|||||||
|
require 'monban/constraints/signed_in'
|
||||||
|
require 'monban/constraints/signed_out'
|
||||||
|
|
||||||
DanBarberPhoto::Application.routes.draw do
|
DanBarberPhoto::Application.routes.draw do
|
||||||
|
resource :session, only: [:new, :create, :destroy]
|
||||||
|
resources :users, only: [:new, :create]
|
||||||
|
resource :session, only: [:new, :create, :destroy]
|
||||||
|
resources :users, only: [:new, :create]
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
DashboardManifest::DASHBOARDS.each do |dashboard_resource|
|
DashboardManifest::DASHBOARDS.each do |dashboard_resource|
|
||||||
resources dashboard_resource
|
resources dashboard_resource
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
class CreateUsers < ActiveRecord::Migration
|
class CreateUsers < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :users do |t|
|
create_table :users do |t|
|
||||||
t.string :email
|
t.string :email, null: false
|
||||||
t.string :password_digest, limit: 60
|
t.string :password_digest, null: false, limit: 60
|
||||||
|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
end
|
end
|
||||||
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# 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: 20151023163642) do
|
ActiveRecord::Schema.define(version: 20151023165644) 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"
|
||||||
@ -68,8 +68,8 @@ ActiveRecord::Schema.define(version: 20151023163642) do
|
|||||||
add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
|
add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email"
|
t.string "email", null: false
|
||||||
t.string "password_digest", limit: 60
|
t.string "password_digest", limit: 60, null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,5 +3,4 @@ FactoryGirl.define do
|
|||||||
email "test@example.com"
|
email "test@example.com"
|
||||||
password_digest ""
|
password_digest ""
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user