parent
882d0a51ed
commit
4f190f67f0
25 changed files with 323 additions and 6 deletions
@ -1,2 +1,3 @@ |
||||
class ApplicationController < ActionController::Base |
||||
include Clearance::Controller |
||||
end |
||||
|
@ -0,0 +1,20 @@ |
||||
class BoardsController < ApplicationController |
||||
before_action :require_login |
||||
|
||||
def edit |
||||
@users = User.where(active: true) |
||||
@users += Array.new(5 - @users.size) { User.new } |
||||
end |
||||
|
||||
def update |
||||
User.update_board_members(board_params) |
||||
|
||||
redirect_to edit_board_path |
||||
end |
||||
|
||||
private |
||||
|
||||
def board_params |
||||
params.require('users') |
||||
end |
||||
end |
@ -0,0 +1,9 @@ |
||||
class ActiveGuard < Clearance::SignInGuard |
||||
def call |
||||
if signed_in? && !current_user.active |
||||
failure(t('sessions.new.deactivated_error')) |
||||
else |
||||
next_guard |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,27 @@ |
||||
class User < ApplicationRecord |
||||
include Clearance::User |
||||
|
||||
def self.update_board_members(new_emails) |
||||
where(active: true).each do |user| |
||||
if !new_emails.include?(user.email) |
||||
user.update(active: false) |
||||
|
||||
# TODO: notify board member of deactivation |
||||
end |
||||
end |
||||
|
||||
new_emails.each do |email| |
||||
user = User.find_by(email: email) |
||||
|
||||
if user |
||||
if !user.active? |
||||
# TODO: notify board member of activation |
||||
user.update(active: true, password: SecureRandom.hex(32)) |
||||
end |
||||
else |
||||
# TODO: notify board member of activation |
||||
User.create(email: email, password: SecureRandom.hex(32)) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@ |
||||
<h1><%= t('boards.edit.title') %></h1> |
||||
|
||||
<p><%= t('boards.edit.warning') %></p> |
||||
|
||||
<%= form_with scope: :users, url: board_path, method: :put do |form| %> |
||||
<table class='lined'> |
||||
<% @users.each do |user| %> |
||||
<tr> |
||||
<td> |
||||
<%= form.email_field nil, value: user.email %> |
||||
</td> |
||||
</tr> |
||||
<% end %> |
||||
</table> |
||||
|
||||
<div> |
||||
<%= form.submit %> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,8 @@ |
||||
<p><%= t(".opening") %></p> |
||||
|
||||
<p> |
||||
<%= link_to t(".link_text", default: "Change my password"), |
||||
url_for([@user, :password, action: :edit, token: @user.confirmation_token]) %> |
||||
</p> |
||||
|
||||
<p><%= t(".closing") %></p> |
@ -0,0 +1,5 @@ |
||||
<%= t(".opening") %> |
||||
|
||||
<%= url_for([@user, :password, action: :edit, token: @user.confirmation_token]) %> |
||||
|
||||
<%= t(".closing") %> |
@ -0,0 +1,3 @@ |
||||
<div id="clearance" class="password-reset"> |
||||
<p><%= t(".description") %></p> |
||||
</div> |
@ -0,0 +1,18 @@ |
||||
<div id="clearance" class="password-reset"> |
||||
<h2><%= t(".title") %></h2> |
||||
|
||||
<p><%= t(".description") %></p> |
||||
|
||||
<%= form_for :password_reset, |
||||
url: [@user, :password, token: @user.confirmation_token], |
||||
html: { method: :put } do |form| %> |
||||
<div class="password-field"> |
||||
<%= form.label :password %> |
||||
<%= form.password_field :password %> |
||||
</div> |
||||
|
||||
<div class="submit-field"> |
||||
<%= form.submit %> |
||||
</div> |
||||
<% end %> |
||||
</div> |
@ -0,0 +1,16 @@ |
||||
<div id="clearance" class="password-reset"> |
||||
<h2><%= t(".title") %></h2> |
||||
|
||||
<p><%= t(".description") %></p> |
||||
|
||||
<%= form_for :password, url: passwords_path do |form| %> |
||||
<div class="text-field"> |
||||
<%= form.label :email %> |
||||
<%= form.email_field :email %> |
||||
</div> |
||||
|
||||
<div class="submit-field"> |
||||
<%= form.submit %> |
||||
</div> |
||||
<% end %> |
||||
</div> |
@ -0,0 +1,28 @@ |
||||
<%= form_for :session, url: session_path do |form| %> |
||||
<table> |
||||
<tr> |
||||
<td> |
||||
<%= form.label :email %> |
||||
</td> |
||||
<td> |
||||
<%= form.email_field :email %> |
||||
</td> |
||||
</tr> |
||||
|
||||
<tr> |
||||
<td><%= form.label :password %></td> |
||||
<td><%= form.password_field :password %></td> |
||||
</tr> |
||||
</table> |
||||
|
||||
<div class="submit-field"> |
||||
<%= form.submit %> |
||||
</div> |
||||
|
||||
<div class="other-links"> |
||||
<% if Clearance.configuration.allow_sign_up? %> |
||||
<%= link_to t(".sign_up"), sign_up_path %> |
||||
<% end %> |
||||
<%= link_to t(".forgot_password"), new_password_path %> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,5 @@ |
||||
<div id="clearance" class="sign-in"> |
||||
<h2><%= t(".title") %></h2> |
||||
|
||||
<%= render partial: '/sessions/form' %> |
||||
</div> |
@ -0,0 +1,8 @@ |
||||
Clearance.configure do |config| |
||||
config.allow_sign_up = false |
||||
config.mailer_sender = ENV['SMTP_FROM_ADDRESS'] |
||||
config.rotate_csrf_on_sign_in = true |
||||
config.secure_cookie = true |
||||
config.signed_cookie = true |
||||
config.sign_in_guards = ["ActiveGuard"] |
||||
end |
@ -0,0 +1,64 @@ |
||||
--- |
||||
en: |
||||
clearance: |
||||
models: |
||||
clearance_mailer: |
||||
change_password: Change your password |
||||
clearance_mailer: |
||||
change_password: |
||||
closing: If you didn't request this, ignore this email. Your password has |
||||
not been changed. |
||||
link_text: Change my password |
||||
opening: "Someone, hopefully you, requested we send you a link to change |
||||
your password:" |
||||
flashes: |
||||
failure_after_create: Bad email or password. |
||||
failure_after_update: Password can't be blank. |
||||
failure_when_forbidden: Please double check the URL or try submitting |
||||
the form again. |
||||
failure_when_not_signed_in: Please sign in to continue. |
||||
failure_when_missing_email: Email can't be blank. |
||||
helpers: |
||||
label: |
||||
password: |
||||
email: Email address |
||||
password_reset: |
||||
password: Choose password |
||||
session: |
||||
password: Password |
||||
user: |
||||
password: Password |
||||
submit: |
||||
password: |
||||
submit: Reset password |
||||
password_reset: |
||||
submit: Save this password |
||||
session: |
||||
submit: Sign in |
||||
user: |
||||
create: Sign up |
||||
layouts: |
||||
application: |
||||
sign_in: Sign in |
||||
sign_out: Sign out |
||||
passwords: |
||||
create: |
||||
description: You will receive an email within the next few minutes. It |
||||
contains instructions for changing your password. |
||||
edit: |
||||
description: Your password has been reset. Choose a new password below. |
||||
title: Change your password |
||||
new: |
||||
description: To be emailed a link to reset your password, please enter |
||||
your email address. |
||||
title: Reset your password |
||||
sessions: |
||||
form: |
||||
forgot_password: Forgot password? |
||||
sign_up: Sign up |
||||
new: |
||||
title: Sign in |
||||
users: |
||||
new: |
||||
sign_in: Sign in |
||||
title: Sign up |
@ -0,0 +1,15 @@ |
||||
class CreateUsers < ActiveRecord::Migration[7.0] |
||||
def change |
||||
create_table :users, id: :uuid do |t| |
||||
t.timestamps null: false |
||||
t.string :email, null: false |
||||
t.string :encrypted_password, limit: 128, null: false |
||||
t.string :confirmation_token, limit: 128 |
||||
t.string :remember_token, limit: 128, null: false |
||||
end |
||||
|
||||
add_index :users, :email |
||||
add_index :users, :confirmation_token, unique: true |
||||
add_index :users, :remember_token, unique: true |
||||
end |
||||
end |
@ -0,0 +1,7 @@ |
||||
class AddActiveToUser < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :users do |t| |
||||
t.boolean :active, null: false, default: true |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue