/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { // the user must be verified $user = Request::user(); // there must NOT be a grader for the user $grader = Grader::where('user_id', $user->id)->first(); return $user && $user->verified && !$user->hasRole('grader_a'); }
public function approve($grader_id) { $grader = Grader::find($grader_id); $grader->approved_at = Carbon::now(); $grader->approver_email = Auth::user()->email; $grader->approved = 1; $grader->save(); alert()->success('Μην ξεχνάς ότι ξέρουμε ποιος είσαι.', 'Επιτυχής Έκγριση!')->persistent('Το κατάλαβα'); return redirect()->back(); }
/** * The suggested grader has not accepted yet * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $user = $request->user(); //$suggestion = Suggestion::where('suggestor_email', $user->email)->first(); //$suggestion = $user->suggestion; $user = $request->user(); $grader = Grader::where('user_id', $user->id)->first(); // if($user->grader_status == 'na' || str_contains($user->grader_status, 'not_accepted')){ // return $next($request); // } if ($grader && !$user->hasRole('grader_a')) { return $next($request); } if (!$grader) { return $next($request); } return redirect()->route('home'); }
/** * Make sure the User is the owner of the Grader * * @return bool */ public function authorize() { $grader_id = $this->route()->parameter('graders'); $grader = Grader::find($grader_id); return $this->user()->id == $grader->user_id; }
public function update_b(EditGraderRequest $request, $id) { $grader = Grader::findOrFail($id); $input = $request->all(); if ($request->has('desired_category')) { $input['desired_category'] = implode('|', $input['desired_category']); } if ($request->has('teaching_xp')) { $input['teaching_xp'] = implode('|', $input['teaching_xp']); } if (!$request->has('english')) { $input['english'] = 0; $input['english_level'] = null; $input['lang_pref_english'] = 0; } if (!$request->has('french')) { $input['french'] = 0; $input['french_level'] = null; $input['lang_pref_french'] = 0; } if (!$request->has('german')) { $input['german'] = 0; $input['german_level'] = null; $input['lang_pref_german'] = 0; } if (!$request->has('italian')) { $input['italian'] = 0; $input['italian_level'] = null; $input['lang_pref_italian'] = 0; } if (!$request->has('propose_myself')) { $input['propose_myself'] = 0; $input['why_propose_myself'] = null; } if (!$request->has('lang_pref_english')) { $input['lang_pref_english'] = 0; } if (!$request->has('lang_pref_french')) { $input['lang_pref_french'] = 0; } if (!$request->has('lang_pref_german')) { $input['lang_pref_german'] = 0; } if (!$request->has('lang_pref_italian')) { $input['lang_pref_italian'] = 0; } if ($request->hasFile('personal_cv') && $request->file('personal_cv')->isValid()) { $input['personal_cv'] = $grader->addPersonalCV($request); } if ($request->delete_cv == 'delete_me') { $grader->personal_cv = null; $grader->save(); } if ($request->delete_photo == 'delete_me') { $grader->photo = null; $grader->save(); } if ($request->hasFile('photo') && $request->file('photo')->isValid()) { $grader->photo = $grader->addPhoto($request); $grader->save(); } $grader->fill($input)->save(); alert()->success('Τα στοιχεία σας ενημερώθηκαν επιτυχώς!', 'Επιτυχία'); return redirect()->back(); }
public function store_other_grader(CreateOtherGraderRequest $request) { $unique_string = $request->unique_string; // find the suggestion $suggestion = Suggestion::where('unique_string', $unique_string)->first(); $suggestion->logOutOtherUser(); $grader_email = $suggestion->grader_email; // Update the suggestor $suggestor_email = $suggestion->suggestor_email; $suggestor = User::where('email', $suggestor_email)->first(); $suggestor->grader_status .= ',accepted'; $suggestor->save(); // Update the Suggestion $suggestion->accepted = 'yes'; $suggestion->save(); // Create the user $user = User::create(['email' => $grader_email, 'password' => bcrypt($request->password), 'verification_token' => str_random(40), 'verified' => 1]); // Give the user the roles of user (id: 5) and grader A (id: 2) $user->roles()->attach(5); $user->roles()->attach(2); // Create the grader $data = $request->all(); $data['user_id'] = $user->id; $data['suggestions_count'] = 1; if (isset($data['desired_category'])) { $data['desired_category'] = implode('|', $data['desired_category']); } if (isset($data['teaching_xp'])) { $data['teaching_xp'] = implode('|', $data['teaching_xp']); } $grader = Grader::create($data); if ($request->hasFile('personal_cv') && $request->file('personal_cv')->isValid()) { $grader->personal_cv = $grader->addPersonalCV($request); $grader->save(); } if ($request->hasFile('photo') && $request->file('photo')->isValid()) { $grader->photo = $grader->addPhoto($request); $grader->save(); } // Notify the user $suggestion->sendAcceptanceEmail($request->last_name, $request->first_name); alert()->success('Ο Υποψήφιος θα ενημερωθεί για την αποδοχή σας. Μην ξεχνάτε ότι μπορείτε να επεξεργάζεστε τα στοιχεία σας όποτε επιθυμείτε.', 'Επιτυχής Υποβολή!')->persistent('Το κατάλαβα'); return redirect()->route('home'); }