Co-authored-by: Kiara Grouwstra <kiara@bij1.org> Reviewed-on: #34
This commit is contained in:
parent
e08e1d17cf
commit
c028d3af7e
|
@ -1,5 +1,5 @@
|
|||
class MainController < ApplicationController
|
||||
before_action :set_user_room, only: [:join, :users, :stream, :stemmen]
|
||||
before_action :set_user_room, only: [:join, :users, :stream, :stemmen, :checkin]
|
||||
|
||||
def index
|
||||
end
|
||||
|
@ -26,12 +26,7 @@ class MainController < ApplicationController
|
|||
end
|
||||
|
||||
def stream
|
||||
start = Time.new(2023, 02, 19, 0, 0, 0, "+01:00")
|
||||
@running = false
|
||||
if Time.now > start or @user.moderator
|
||||
@user.update(presence: true)
|
||||
@running = true
|
||||
end
|
||||
update_running
|
||||
end
|
||||
|
||||
def stemmen
|
||||
|
@ -40,9 +35,25 @@ class MainController < ApplicationController
|
|||
render :votes
|
||||
end
|
||||
|
||||
def checkin
|
||||
# HTTP basic auth
|
||||
http_basic_authenticate_or_request_with name: Rails.application.config.admin_name,
|
||||
password: Rails.application.config.admin_password
|
||||
|
||||
notice = ""
|
||||
if @user.presence
|
||||
notice = "Warning: user already checked in!"
|
||||
else
|
||||
notice = "Success: user is now checked in!"
|
||||
@user.update(presence: true)
|
||||
end
|
||||
redirect_to user_url(@user.id), notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
def set_user_room
|
||||
@user = User.find_by token: params[:token]
|
||||
# check if the user was found
|
||||
if @user.nil?
|
||||
redirect_to 'https://bij1.org/', status: :unauthorized
|
||||
else
|
||||
|
@ -50,4 +61,13 @@ class MainController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_running
|
||||
start = Time.new(2023, 02, 19, 0, 0, 0, "+01:00")
|
||||
@running = false
|
||||
if Time.now > start or @user.moderator
|
||||
@user.update(presence: true)
|
||||
@running = true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,5 +20,6 @@ Rails.application.routes.draw do
|
|||
get ':token', to: 'main#stemmen', as: 'user_elections'
|
||||
get ':token/stream', to: 'main#stream', as: 'user_stream'
|
||||
get ':token/inbellen', to: 'main#join', as: 'join_room'
|
||||
get ':token/checkin', to: 'main#checkin', as: 'checkin'
|
||||
root 'main#index'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue