User management
This commit is contained in:
parent
ce5b729fef
commit
0b47cc4d8a
@ -51,6 +51,7 @@ module Authentication
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
|
return unless Current.session
|
||||||
return unless Current.session[:user_id]
|
return unless Current.session[:user_id]
|
||||||
User.find(Current.session[:user_id])
|
User.find(Current.session[:user_id])
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@title = "All users"
|
@title = "All users"
|
||||||
|
@users = User.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@ -11,7 +12,7 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
if @user.update(user_params)
|
if @user.update(user_params)
|
||||||
redirect_to @user
|
redirect_to contests_path
|
||||||
else
|
else
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
@ -22,6 +23,18 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@title = "New user"
|
||||||
|
@user = User.new()
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@user = User.new(user_params)
|
||||||
|
if @user.save
|
||||||
|
redirect_to users_path
|
||||||
|
else
|
||||||
|
@title = "New user"
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@ -34,6 +47,6 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.expect(user: [ :username, :email_address ])
|
params.expect(user: [ :username, :email_address, :password ])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,9 @@ html
|
|||||||
- if @current_user
|
- if @current_user
|
||||||
.float-end style="margin-top: -8px;"
|
.float-end style="margin-top: -8px;"
|
||||||
nav.navbar.bg-body-primary
|
nav.navbar.bg-body-primary
|
||||||
|
- if @current_user.admin
|
||||||
|
a.navbar-brand href=users_path
|
||||||
|
| Users
|
||||||
a.navbar-brand href=contests_path
|
a.navbar-brand href=contests_path
|
||||||
| Home
|
| Home
|
||||||
a.navbar-brand href=user_path(@current_user)
|
a.navbar-brand href=user_path(@current_user)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
= form_with model: user do |form|
|
= form_with model: user, method: method do |form|
|
||||||
|
- if method == :patch
|
||||||
|
h4 General settings
|
||||||
.row.mb-3
|
.row.mb-3
|
||||||
.col
|
.col
|
||||||
.input-group
|
.input-group
|
||||||
@ -9,7 +11,23 @@
|
|||||||
.row.mb-3
|
.row.mb-3
|
||||||
.col
|
.col
|
||||||
.form-floating
|
.form-floating
|
||||||
= form.text_field :email_address, autocomplete: "off", class: "form-control", type: "email"
|
= form.text_field :email_address, autocomplete: "off", class: "form-control"
|
||||||
= form.label :email_address, class: "required"
|
= form.label :email_address, class: "required"
|
||||||
div
|
- if method == :post
|
||||||
= form.submit "Save", class: "btn btn-primary"
|
.row.mb-3
|
||||||
|
.col
|
||||||
|
.form-floating
|
||||||
|
= form.password_field :password, autocomplete: "off", class: "form-control"
|
||||||
|
= form.label :password, class: "required"
|
||||||
|
= form.submit "Save", class: "btn btn-primary"
|
||||||
|
|
||||||
|
- if method == :patch
|
||||||
|
h4.mt-5 Change password
|
||||||
|
= form_with model: user, method: method do |form|
|
||||||
|
.row.mb-3
|
||||||
|
.col
|
||||||
|
.form-floating
|
||||||
|
= form.password_field :password, autocomplete: "off", class: "form-control"
|
||||||
|
= form.label :password, class: "required"
|
||||||
|
| New password
|
||||||
|
= form.submit "Save new password", class: "btn btn-primary"
|
@ -1 +1 @@
|
|||||||
= render "form", user: @user
|
= render "form", user: @user, method: :patch
|
@ -0,0 +1,27 @@
|
|||||||
|
table.table.table-striped.table-hover
|
||||||
|
thead
|
||||||
|
tr
|
||||||
|
th scope="col"
|
||||||
|
| Id
|
||||||
|
th scope="col"
|
||||||
|
| Name
|
||||||
|
th scope="col"
|
||||||
|
| Admin?
|
||||||
|
th scope="col"
|
||||||
|
| # contests
|
||||||
|
tbody
|
||||||
|
- @users.each do |user|
|
||||||
|
tr scope="row"
|
||||||
|
td
|
||||||
|
= user.id
|
||||||
|
td
|
||||||
|
= user.username
|
||||||
|
td
|
||||||
|
= user.admin ? "Yes" : "No"
|
||||||
|
td
|
||||||
|
= user.contests.length
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col
|
||||||
|
a.btn.btn-primary href=new_user_path
|
||||||
|
| New user
|
@ -1 +1 @@
|
|||||||
= render "form", user: @user
|
= render "form", user: @user, method: :post
|
Loading…
x
Reference in New Issue
Block a user