Commit 17d0cd8f authored by kolosfed's avatar kolosfed

Users, authorization and flash messages

parent 7b22c82f
$(document).on("click", ".close_notifications", function (e) {
e.preventDefault();
$(this).closest("li.nav-item").find("a.nav-link").click();
});
......@@ -3,26 +3,6 @@
.sidebar,
.topbar {
.nav-item {
// Customize Dropdown Arrows for Navbar
&.dropdown {
.dropdown-toggle {
&::after {
width: 1rem;
text-align: center;
float: right;
vertical-align: 0;
border: 0;
font-weight: 900;
content: '\f105';
font-family: 'Font Awesome 5 Free';
}
}
&.show {
.dropdown-toggle::after {
content: '\f107';
}
}
}
// Counter for nav links and nav link image sizing
.nav-link {
position: relative;
......
......@@ -4,6 +4,28 @@
min-height: 100vh;
.nav-item {
position: relative;
// Customize Dropdown Arrows for Navbar
&.dropdown {
.dropdown-toggle {
&::after {
width: 1rem;
text-align: center;
float: right;
vertical-align: 0;
border: 0;
font-weight: 900;
content: '\f105';
font-family: 'Font Awesome 5 Free';
}
}
&.show {
.dropdown-toggle::after {
content: '\f107';
}
}
}
&:last-child {
margin-bottom: 1rem;
}
......
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
# GET /users.json
def index
@users = User.all
end
# GET /users/1
# GET /users/1.json
def show
end
# GET /users/new
def new
@user = User.new
end
# GET /users/1/edit
def edit
end
# POST /users
# POST /users.json
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Only allow a list of trusted parameters through.
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end
module ApplicationHelper
def flash_bg_class(flash_type)
case flash_type
when 'success'
'bg-success'
when 'error'
'bg-danger'
when 'alert'
'bg-warning'
when 'notice'
'bg-info'
else
flash_type.to_s
end
end
end
class User < ApplicationRecord
devise :database_authenticatable, :rememberable, :validatable
end
%li.nav-item.dropdown.no-arrow{class: ("show" if flash.any?)}
%a.nav-link.dropdown-toggle{"aria-expanded" => flash.any?.to_s, "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%i.fas.fa-bell.fa-fw
.dropdown-list.dropdown-menu.dropdown-menu-right.shadow.animated--grow-in{class: ("show" if flash.any?), "aria-labelledby" => "alertsDropdown"}
%h6.dropdown-header.text-center
= flash.any? ? "Сповіщення" : "Немає сповіщень"
- flash.each do |type, msg|
%a.dropdown-item.d-flex.align-items-center{class: flash_bg_class(type)}
%div
%span= msg
%a.close_notifications.dropdown-item.text-center.small.text-gray-500{href: "#"} Закрити
\ No newline at end of file
......@@ -7,11 +7,17 @@
Chicken Farm
%hr.sidebar-divider.my-0
/ # TODO @kolosfed setup active page picking
%li.nav-item.active
= link_to root_path, class: 'nav-link' do
= icon('fas', 'tachometer-alt', class: 'fa-fw') + "\n" + tag.span("Головна")
%li.nav-item
= link_to users_path, class: 'nav-link' do
= icon('fas', 'users', class: 'fa-fw') + "\n" + tag.span("Користувачі")
%hr.sidebar-divider.d-none.d-md-block
/ Sidebar Toggler (Sidebar)
......
......@@ -2,116 +2,28 @@
/ Sidebar Toggle (Topbar)
%button#sidebarToggleTop.btn.btn-link.d-md-none.rounded-circle.mr-3
%i.fa.fa-bars
/ Topbar Search
%form.d-none.d-sm-inline-block.form-inline.mr-auto.ml-md-3.my-2.my-md-0.mw-100.navbar-search
.input-group
%input.form-control.bg-light.border-0.small{"aria-describedby" => "basic-addon2", "aria-label" => "Search", placeholder: "Search for...", type: "text"}/
.input-group-append
%button.btn.btn-primary{type: "button"}
%i.fas.fa-search.fa-sm
/ Topbar Navbar
%ul.navbar-nav.ml-auto
/ Nav Item - Search Dropdown (Visible Only XS)
%li.nav-item.dropdown.no-arrow.d-sm-none
%a#searchDropdown.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%i.fas.fa-search.fa-fw
/ Dropdown - Messages
.dropdown-menu.dropdown-menu-right.p-3.shadow.animated--grow-in{"aria-labelledby" => "searchDropdown"}
%form.form-inline.mr-auto.w-100.navbar-search
.input-group
%input.form-control.bg-light.border-0.small{"aria-describedby" => "basic-addon2", "aria-label" => "Search", placeholder: "Search for...", type: "text"}/
.input-group-append
%button.btn.btn-primary{type: "button"}
%i.fas.fa-search.fa-sm
/ Nav Item - Alerts
%li.nav-item.dropdown.no-arrow.mx-1
%a#alertsDropdown.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%i.fas.fa-bell.fa-fw
/ Counter - Alerts
%span.badge.badge-danger.badge-counter 3+
/ Dropdown - Alerts
.dropdown-list.dropdown-menu.dropdown-menu-right.shadow.animated--grow-in{"aria-labelledby" => "alertsDropdown"}
%h6.dropdown-header
Alerts Center
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.mr-3
.icon-circle.bg-primary
%i.fas.fa-file-alt.text-white
%div
.small.text-gray-500 December 12, 2019
%span.font-weight-bold A new monthly report is ready to download!
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.mr-3
.icon-circle.bg-success
%i.fas.fa-donate.text-white
%div
.small.text-gray-500 December 7, 2019
$290.29 has been deposited into your account!
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.mr-3
.icon-circle.bg-warning
%i.fas.fa-exclamation-triangle.text-white
%div
.small.text-gray-500 December 2, 2019
Spending Alert: We've noticed unusually high spending for your account.
%a.dropdown-item.text-center.small.text-gray-500{href: "#"} Show All Alerts
/ Nav Item - Messages
%li.nav-item.dropdown.no-arrow.mx-1
%a#messagesDropdown.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%i.fas.fa-envelope.fa-fw
/ Counter - Messages
%span.badge.badge-danger.badge-counter 7
/ Dropdown - Messages
.dropdown-list.dropdown-menu.dropdown-menu-right.shadow.animated--grow-in{"aria-labelledby" => "messagesDropdown"}
%h6.dropdown-header
Message Center
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.dropdown-list-image.mr-3
%img.rounded-circle{alt: "", src: "https://source.unsplash.com/fn_BT9fwg_E/60x60"}/
.status-indicator.bg-success
.font-weight-bold
.text-truncate Hi there! I am wondering if you can help me with a problem I've been having.
.small.text-gray-500 Emily Fowler · 58m
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.dropdown-list-image.mr-3
%img.rounded-circle{alt: "", src: "https://source.unsplash.com/AU4VPcFN4LE/60x60"}/
.status-indicator
%div
.text-truncate I have the photos that you ordered last month, how would you like them sent to you?
.small.text-gray-500 Jae Chun · 1d
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.dropdown-list-image.mr-3
%img.rounded-circle{alt: "", src: "https://source.unsplash.com/CS2uCrpNzJY/60x60"}/
.status-indicator.bg-warning
%div
.text-truncate Last month's report looks great, I am very happy with the progress so far, keep up the good work!
.small.text-gray-500 Morgan Alvarez · 2d
%a.dropdown-item.d-flex.align-items-center{href: "#"}
.dropdown-list-image.mr-3
%img.rounded-circle{alt: "", src: "https://source.unsplash.com/Mv9hjnEUHR4/60x60"}/
.status-indicator.bg-success
%div
.text-truncate Am I a good boy? The reason I ask is because someone told me that people say this to all dogs, even if they aren't good...
.small.text-gray-500 Chicken the Dog · 2w
%a.dropdown-item.text-center.small.text-gray-500{href: "#"} Read More Messages
.topbar-divider.d-none.d-sm-block
/ Nav Item - User Information
%li.nav-item.dropdown.no-arrow
%a#userDropdown.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%span.mr-2.d-none.d-lg-inline.text-gray-600.small Valerie Luna
%img.img-profile.rounded-circle{src: "https://source.unsplash.com/QAB-WJcbgJk/60x60"}/
/ Dropdown - User Information
.dropdown-menu.dropdown-menu-right.shadow.animated--grow-in{"aria-labelledby" => "userDropdown"}
%a.dropdown-item{href: "#"}
%i.fas.fa-user.fa-sm.fa-fw.mr-2.text-gray-400
Profile
%a.dropdown-item{href: "#"}
%i.fas.fa-cogs.fa-sm.fa-fw.mr-2.text-gray-400
Settings
%a.dropdown-item{href: "#"}
%i.fas.fa-list.fa-sm.fa-fw.mr-2.text-gray-400
Activity Log
.dropdown-divider
%a.dropdown-item{"data-target" => "#logoutModal", "data-toggle" => "modal", href: "#"}
%i.fas.fa-sign-out-alt.fa-sm.fa-fw.mr-2.text-gray-400
Logout
\ No newline at end of file
= render "layouts/application/flash_notices"
- if user_signed_in?
.topbar-divider
%li.nav-item.dropdown
%a.my-auto.nav-link.text-gray-600.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#", role: "button"}
%span= current_user.name
.dropdown-menu.dropdown-menu-right.shadow.animated--grow-in
= link_to user_path(current_user), class: "dropdown-item" do
= icon("fas", "user", class: "fa-sm fa-fw mr-2 text-gray-400")
Ваш профіль
= link_to destroy_user_session_path, method: :delete, class: "dropdown-item" do
= icon("fas", "sign-out-alt", class: "fa-sm fa-fw mr-2 text-gray-400")
Вийти
-#.topbar-divider.d-none.d-sm-block
-#%li.nav-item.my-auto
-# %span= icon("fas", "user")
-#.topbar-divider.d-none.d-sm-block
-#%li.nav-item.my-auto
-# %span= icon("fas", "sign-out-alt")
\ No newline at end of file
= form_for @user do |f|
- if @user.errors.any?
#error_explanation
%h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:"
%ul
- @user.errors.full_messages.each do |message|
%li= message
.field
= f.label :name
= f.text_field :name
.field
= f.label :email
= f.text_field :email
.field
= f.label :password
= f.text_field :password
.actions
= f.submit 'Save'
%h1 Editing user
= render 'form'
= link_to 'Show', @user
\|
= link_to 'Back', users_path
%h1 Listing users
%table
%thead
%tr
%th Name
%th Email
%th Password
%th
%th
%th
%tbody
- @users.each do |user|
%tr
%td= user.name
%td= user.email
%td= user.password
%td= link_to 'Show', user
%td= link_to 'Edit', edit_user_path(user)
%td= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' }
%br
= link_to 'New User', new_user_path
%h1 New user
= render 'form'
= link_to 'Back', users_path
%p#notice= notice
%p
%b Name:
= @user.name
%p
%b Email:
= @user.email
%p
%b Password:
= @user.password
= link_to 'Edit', edit_user_path(@user)
\|
= link_to 'Back', users_path
This diff is collapsed.
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
devise:
confirmations:
confirmed: "Your email address has been successfully confirmed."
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account is not activated yet."
invalid: "Invalid %{authentication_keys} or password."
locked: "Your account is locked."
last_attempt: "You have one more attempt before your account is locked."
not_found_in_database: "Invalid %{authentication_keys} or password."
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your email address before continuing."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock instructions"
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
passwords:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password has been changed successfully. You are now signed in."
updated_not_active: "Your password has been changed successfully."
registrations:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have signed up successfully."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
updated: "Your account has been updated successfully."
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
sessions:
signed_in: "Signed in successfully."
signed_out: "Signed out successfully."
already_signed_out: "Signed out successfully."
unlocks:
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
errors:
messages:
already_confirmed: "was already confirmed, please try signing in"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
expired: "has expired, please request a new one"
not_found: "not found"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
Rails.application.routes.draw do
devise_for :users
resources :users
root 'main#start_page'
end
class CreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.string :name, null: false
t.string :email
t.string :encrypted_password, null: false
t.datetime :remember_created_at
t.timestamps
end
end
end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_05_142932) do
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "email"
t.string "encrypted_password", null: false
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
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