Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class PasswordsController < ApplicationController
allow_unauthenticated_access
before_action :set_user_by_token, only: %i[ edit update ]
layout "session"

def new
end
Expand All @@ -9,7 +10,6 @@ def create
if user = User.find_by(email: params[:email])
PasswordsMailer.reset(user).deliver_later
end

redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
end

Expand All @@ -25,9 +25,10 @@ def update
end

private
def set_user_by_token
@user = User.find_by_password_reset_token!(params[:token])
rescue ActiveSupport::MessageVerifier::InvalidSignature
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
end

def set_user_by_token
@user = User.find_by_password_reset_token!(params[:token])
rescue ActiveSupport::MessageVerifier::InvalidSignature
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
end
end
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SessionsController < ApplicationController
allow_unauthenticated_access only: %i[ new create ]
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }
layout "session"

def new
end
Expand Down
50 changes: 50 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
class UsersController < ApplicationController
before_action :set_user, only: %i[ edit update destroy ]

def index
@users = User.all
end

def new
@user = User.new
end

def create
@user = User.new(user_params)

respond_to do |format|
if @user.save
format.html { redirect_to users_path, notice: "User was successfully created." }
else
format.html { render :new, status: :unprocessable_entity }
end
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space here can be removed

def edit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space before this method

end

def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to users_path, notice: "User was successfully updated." }
else
format.html { render :edit, status: :unprocessable_entity }
end
end
end

def destroy
@user.destroy!

respond_to do |format|
format.html { redirect_to users_path, status: :see_other, notice: "User was successfully destroyed." }
end
end

private

def set_user
@user = User.find(params.expect(:id))
end

def user_params
params.expect(user: [ :email, :password, :is_admin ])
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class User < ApplicationRecord

normalizes :email, with: ->(e) { e.strip.downcase }

validates :email, presence: true, uniqueness: true
validates :email, presence: true, uniqueness: true, format: URI::MailTo::EMAIL_REGEXP
validates :password_digest, presence: true
end
6 changes: 3 additions & 3 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<div id="sidebar">
<div class="sidebar-wrapper active">
<div class="sidebar-header position-relative">
Expand Down Expand Up @@ -73,10 +73,10 @@
</li>

<li class="sidebar-item">
<a href="application-chat.html" class="sidebar-link">
<%= link_to users_path, class: 'sidebar-link' do %>
<i class="bi bi-people"></i>
<span>Users</span>
</a>
<% end %>
</li>
</ul>
</div>
Expand Down
47 changes: 47 additions & 0 deletions app/views/layouts/mazer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for(:title) || "Skillrx" %></title>

<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= yield :head %>

<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>


<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/app.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/app-dark.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/iconly.css">

<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/initTheme.js"></script>

<!-- Start content here -->
<%= render "layouts/sidebar" %>

<%= yield %>
<!-- End content -->

<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/components/dark.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/extensions/perfect-scrollbar/perfect-scrollbar.min.js"></script>

<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/js/app.js"></script>

<!-- Need: Apexcharts -->
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/extensions/apexcharts/apexcharts.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/pages/dashboard.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions app/views/layouts/session.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for(:title) || "Skillrx" %></title>

<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= yield :head %>

<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>


<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/app.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/app-dark.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/css/iconly.css">

<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/initTheme.js"></script>

<!-- Start content here -->
<%= yield %>
<!-- End content -->

<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/components/dark.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/extensions/perfect-scrollbar/perfect-scrollbar.min.js"></script>

<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/compiled/js/app.js"></script>

<!-- Need: Apexcharts -->
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/extensions/apexcharts/apexcharts.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/zuramai/mazer@docs/demo/assets/static/js/pages/dashboard.js"></script>
</body>
</html>
36 changes: 30 additions & 6 deletions app/views/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
<h1>Forgot your password?</h1>

<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>

<%= form_with url: passwords_path do |form| %>
<%= form.email_field :email, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %><br>
<%= form.submit "Email reset instructions" %>
<% end %>
<div class="row h-100 p-4">
<div class="col-lg-5 col-12">
<div id="auth-left">
<div class="auth-logo">

</div>
<h1 class="auth-title">Forgot Password</h1>
<p class="auth-subtitle mb-5">Input your email and we will send you reset password link.</p>

<%= form_with url: passwords_path do |form| %>
<div class="form-group position-relative has-icon-left mb-4">
<%= form.email_field :email, required: true, class:"form-control form-control-xl", autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %><br>
<div class="form-control-icon">
<i class="bi bi-envelope"></i>
</div>
</div>

<%= form.submit "Email reset instructions", class:"btn btn-primary btn-block btn-lg shadow-lg mt-5" %>
<% end %>

<div class="text-center mt-5 text-lg fs-4">
<p class="text-gray-600">Remember your account? <%= link_to "Login", new_session_path, class:"font-bold" %></p>
</div>
</div>
</div>
<div class="col-lg-7 d-none d-lg-block">
<div id="auth-right">
</div>
</div>
</div>
36 changes: 27 additions & 9 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>

<%= form_with url: session_path do |form| %>
<%= form.email_field :email, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %><br>
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
<%= form.submit "Sign in" %>
<% end %>
<br>

<%= link_to "Forgot password?", new_password_path %>
<div class="row h-100 p-4">
<div class="col-lg-5 col-12">
<div id="auth-left">
<div class="auth-logo">
</div>
<h1 class="auth-title">Log in</h1>
<p class="auth-subtitle mb-5">Log in with your data that you entered during registration.</p>
<%= form_with url: session_path do |form| %>
<div class="form-group position-relative has-icon-left mb-4">
<%= form.email_field :email, required: true, class:"form-control form-control-xl", autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %><br>
<div class="form-control-icon">
<i class="bi bi-person"></i>
</div>
</div>
<div class="form-group position-relative has-icon-left mb-4">
<%= form.password_field :password, required: true, class:"form-control form-control-xl", autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
<div class="form-control-icon">
<i class="bi bi-shield-lock"></i>
</div>
</div>
<%= form.submit "Sign in", class:"btn btn-primary btn-block btn-lg shadow-lg mt-5" %>
<% end %>
<div class="text-center mt-5 text-lg fs-4">
<p><%= link_to "Forgot password?", new_password_path, class:"font-bold" %></p>
</div>
</div>
</div>
38 changes: 38 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%= form_with(model: user) do |form| %>
<% if user.errors.any? %>
<div style="color: red">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% user.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="col-md-4">
<div class="form-group">
<%= form.label :email, style: "display: block" %>
<%= form.text_field :email, id: "basicInput", class: "form-control", autofocus: true %>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<%= form.label :password, style: "display: block" %>
<%= form.text_field :password, id: "basicInput", class: "form-control", autofocus: true %>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<%= form.label :is_admin, style: "display: block" %>
<%= form.check_box :is_admin, autofocus: true %>
</div>
</div>
<div class="mt-4">
<div class="col-12 d-flex justify-content-end">
<%= form.submit "Save User", class: "btn btn-primary me-1 mb-1" %>
<%= link_to "Cancel", users_path, class: "btn btn-light-secondary me-1 mb-1" %>
</div>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% content_for :title, "Editing user" %>

<h1>Editing user</h1>

<%= render "form", user: @user %>

<div class="mt-4">
<%= link_to "Show this user", @user %> |
<%= link_to "Back to users", users_path %>
</div>
38 changes: 38 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<h1>User list </h1>

<div class="page-heading">
<section class="section">
<div class="card">
<div class="card-body">
<%= link_to new_region_path, class: "btn btn-primary" do %>
<i class="bi bi-plus"></i> Add New User
<% end %>
<table class="table table-striped" id="table1">
<thead>
<tr>
<th>Email</th>
<th>Administrator</th>
<th>User actions</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= user.is_admin %></td>
<td class="text-end">
<%= link_to edit_user_path(user), class: "btn btn-secondary btn-sm pr-2" do %>
<i class="bi bi-pencil"></i> Edit
<% end %>
<%= button_to user, data: { confirm: "Are you sure?" }, method: :delete,form_class:"d-inline", class: "btn btn-danger btn-sm " do %>
<i class="bi bi-trash"></i> Delete
<% end %>
</td>
</tr>
<% end %>
<tbody>
</table>
</div>
</div>
</section>
</div>
Loading