mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Upgraded to rails 8.0.2, moved from dalli to solid cache, moved from delayed_job to solid queue, and add solid cable. deploy/rails-dev-run.sh no longer needs to chmod. Fixed finished_at callback for matches. Migrated from Devise to built in rails auth. Added view tests for the bracket page testing that all bout numbers render for all matches in each bracket type.
This commit is contained in:
@@ -5,6 +5,21 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
after_action :set_csrf_cookie_for_ng
|
||||
|
||||
# Add helpers for authentication (replacing Devise)
|
||||
helper_method :current_user, :user_signed_in?
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
|
||||
end
|
||||
|
||||
def user_signed_in?
|
||||
current_user.present?
|
||||
end
|
||||
|
||||
def authenticate_user!
|
||||
redirect_to login_path, alert: "Please log in to access this page" unless user_signed_in?
|
||||
end
|
||||
|
||||
def set_csrf_cookie_for_ng
|
||||
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class MatAssignmentRulesController < ApplicationController
|
||||
before_action :set_tournament
|
||||
before_action :check_access_manage
|
||||
before_action :set_mat_assignment_rule, only: [:edit, :update, :show, :destroy]
|
||||
before_action :set_mat_assignment_rule, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@mat_assignment_rules = @tournament.mat_assignment_rules
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MatchesController < ApplicationController
|
||||
before_action :set_match, only: [:show, :edit, :update, :destroy, :stat]
|
||||
before_action :set_match, only: [:show, :edit, :update, :stat]
|
||||
before_action :check_access, only: [:edit,:update, :stat]
|
||||
|
||||
# GET /matches/1
|
||||
|
||||
57
app/controllers/password_resets_controller.rb
Normal file
57
app/controllers/password_resets_controller.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
class PasswordResetsController < ApplicationController
|
||||
before_action :get_user, only: [:edit, :update]
|
||||
before_action :valid_user, only: [:edit, :update]
|
||||
before_action :check_expiration, only: [:edit, :update]
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.find_by(email: params[:password_reset][:email].downcase)
|
||||
if @user
|
||||
@user.create_reset_digest
|
||||
@user.send_password_reset_email
|
||||
redirect_to root_url, notice: "Email sent with password reset instructions"
|
||||
else
|
||||
flash.now[:alert] = "Email address not found"
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:user][:password].empty?
|
||||
@user.errors.add(:password, "can't be empty")
|
||||
render 'edit'
|
||||
elsif @user.update(user_params)
|
||||
session[:user_id] = @user.id
|
||||
redirect_to root_url, notice: "Password has been reset"
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:password, :password_confirmation)
|
||||
end
|
||||
|
||||
def get_user
|
||||
@user = User.find_by(email: params[:email])
|
||||
end
|
||||
|
||||
def valid_user
|
||||
unless @user && @user.authenticated?(:reset, params[:id])
|
||||
redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
def check_expiration
|
||||
if @user.password_reset_expired?
|
||||
redirect_to new_password_reset_url, alert: "Password reset has expired"
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/controllers/sessions_controller.rb
Normal file
20
app/controllers/sessions_controller.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class SessionsController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(email: params[:session][:email].downcase)
|
||||
if user && user.authenticate(params[:session][:password])
|
||||
session[:user_id] = user.id
|
||||
redirect_to root_path, notice: "Logged in successfully"
|
||||
else
|
||||
flash.now[:alert] = "Invalid email/password combination"
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
session.delete(:user_id)
|
||||
redirect_to root_path, notice: "Logged out successfully"
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
class TournamentsController < ApplicationController
|
||||
before_action :set_tournament, only: [:all_results, :delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :set_tournament, only: [:all_results, :delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_manage, only: [:delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||
before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
||||
before_action :check_tournament_errors, only: [:generate_matches]
|
||||
@@ -229,6 +229,7 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
@tournament = Tournament.find(params[:id])
|
||||
@schools = @tournament.schools.includes(:delegates).sort_by{|school|school.name}
|
||||
@weights = @tournament.weights.sort_by{|x|[x.max]}
|
||||
@mats = @tournament.mats.sort_by{|mat|mat.name}
|
||||
|
||||
48
app/controllers/users_controller.rb
Normal file
48
app/controllers/users_controller.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
class UsersController < ApplicationController
|
||||
before_action :require_login, only: [:edit, :update]
|
||||
before_action :correct_user, only: [:edit, :update]
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
if @user.save
|
||||
session[:user_id] = @user.id
|
||||
redirect_to root_path, notice: "Account created successfully"
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
if @user.update(user_params)
|
||||
redirect_to root_path, notice: "Account updated successfully"
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:email, :password, :password_confirmation)
|
||||
end
|
||||
|
||||
def require_login
|
||||
unless current_user
|
||||
redirect_to login_path, alert: "Please log in to access this page"
|
||||
end
|
||||
end
|
||||
|
||||
def correct_user
|
||||
@user = User.find(params[:id])
|
||||
redirect_to root_path unless current_user == @user
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
class WeightsController < ApplicationController
|
||||
before_action :set_weight, only: [:pool_order, :show, :edit, :update, :destroy,:re_gen]
|
||||
before_action :check_access_manage, only: [:pool_order, :new,:create,:update,:destroy,:edit, :re_gen]
|
||||
before_action :set_weight, only: [:pool_order, :show, :edit, :update, :destroy]
|
||||
before_action :check_access_manage, only: [:pool_order, :new,:create,:update,:destroy,:edit]
|
||||
before_action :check_access_read, only: [:show]
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class WrestlersController < ApplicationController
|
||||
before_action :set_wrestler, only: [:show, :edit, :update, :destroy, :update_pool]
|
||||
before_action :check_access, only: [:new, :create, :update, :destroy, :edit, :update_pool]
|
||||
before_action :set_wrestler, only: [:show, :edit, :update, :destroy]
|
||||
before_action :check_access, only: [:new, :create, :update, :destroy, :edit]
|
||||
before_action :check_read_access, only: [:show]
|
||||
|
||||
# GET /wrestlers/1
|
||||
@@ -36,7 +36,7 @@ class WrestlersController < ApplicationController
|
||||
@school_permission_key = wrestler_params[:school_permission_key].presence
|
||||
@weights = @school.tournament.weights if @school
|
||||
|
||||
# Remove the key from attributes so it isn’t assigned to the model.
|
||||
# Remove the key from attributes so it isn't assigned to the model.
|
||||
@wrestler = Wrestler.new(wrestler_params.except(:school_permission_key))
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
Reference in New Issue
Block a user