<commit_before><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Requests\SlotRequest;
use App\Models\Slot;
use App\Models\UserRole;

use Illuminate\Support\Facades\Auth;

use App\Events\SlotChanged;
use Carbon\Carbon;

class SlotController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    // Helper function to determine if an event has passed
    private function eventHasPassed(Slot $slot)
    {
        $start_date = new Carbon($slot->start_date);

        if($start_date->lt(Carbon::now()))
        {
            return true;
        }

        return false;
    }

    // Helper function to determine allowed roles
    private function userAllowed(Slot $slot, $type)
    {
        $user = Auth::user();
        $roles = $slot->schedule->getRoles();
        $allowed = false;

        // Check each allowed role to see if the user has permission
        foreach($roles as $role)
        {
            $action = implode('-', [$type, $role->role->name, 'slot']);
            
            if($user->can($action))
            {
                $allowed = true;
            }
        }

        return $allowed;
    }

    
    // View form to take an existing slot
    public function takeForm(Request $request, Slot $slot)
    {
        return view('pages/slot/take', compact('slot'));
    }

    // Add yourself to an existing slot
    public function take(SlotRequest $request, Slot $slot)
    {
        // Error handling
        if($slot->schedule->password)
        {
            // TODO: Succeptable to timing attacks? lol
            if($request->get('password') != $slot->schedule->password)
            {
                $request->session()->flash('error', 'The password you entered is incorrect. Please contact your department lead to make sure you have the right password.');
                return redirect()->back();
            }
        }
        else<commit_msg>Added error message when trying to sign up for shifts without a name<commit_after><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Requests\SlotRequest;
use App\Models\Slot;
use App\Models\UserRole;

use Illuminate\Support\Facades\Auth;

use App\Events\SlotChanged;
use Carbon\Carbon;

class SlotController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    // Helper function to determine if an event has passed
    private function eventHasPassed(Slot $slot)
    {
        $start_date = new Carbon($slot->start_date);

        if($start_date->lt(Carbon::now()))
        {
            return true;
        }

        return false;
    }

    // Helper function to determine allowed roles
    private function userAllowed(Slot $slot, $type)
    {
        $user = Auth::user();
        $roles = $slot->schedule->getRoles();
        $allowed = false;

        // Check each allowed role to see if the user has permission
        foreach($roles as $role)
        {
            $action = implode('-', [$type, $role->role->name, 'slot']);
            
            if($user->can($action))
            {
                $allowed = true;
            }
        }

        return $allowed;
    }

    
    // View form to take an existing slot
    public function takeForm(Request $request, Slot $slot)
    {
        if(is_null(Auth::user()->data) or empty(Auth::user()->data->full_name))
        {
            $request->session()->flash('error', "You must enter your name before you can sign up for shifts.");
            return redirect('/profile/data/edit');
        }

        return view('pages/slot/take', compact('slot'));
    }

    // Add yourself to an existing slot
    public function take(SlotRequest $request, Slot $slot)
    {
        // Error handling
        if($slot->schedule->password)
        {
            // TODO: Succeptable to timing attacks? lol
            if($request->get('password') != $slot->schedule->password)
            {
                $request->session()->flash('error', 'The password you entered is incorrect. Please contact your department lead to make sure you have the right password.');
                return redirect()->back();
            }
        }
        else
{'fraction_non_alphanumeric': 0.11966202329298926, 'fraction_numerical': 0.0, 'mean_word_length': 2.0910374029640084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7241506', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1185, 'n_words': 335}