This commit is contained in:
2020-07-28 11:07:41 +02:00
11 changed files with 107 additions and 18 deletions
@@ -68,17 +68,18 @@ class UserController extends Controller
"email" => "required|email|unique:users",
"password" => "required|max:60",
"phone" => "required|unique:users",
"roles" => "max:255"
]);
// Log::debug("FINISHED VALIDATION?");
$rolez = $request->input("roles", [ "User" ]);
$user = new User($data);
// Log::debug("CREATED USER [NOT PERSISTED YET]");
$user->assignRole([ "R1", "R2" ]);
$user->assignRole($rolez);
$user->save();
// Log::debug("SAVED USER");
@@ -166,16 +167,16 @@ class UserController extends Controller
//$user->save();
} else { // Else if you're not on the admin site (user site)
if ($request->input('password') != null) { // If you're editing the password
if ($request->input('password') != $request->input('confirmpassword')) { // If new password and new password confirm is not the same, go back.
return Response::detect("users.editpass");
} elseif (!Hash::check($request->input('oldpassword'), $user->password)) { // If the written current password and current password in DB is not the same, go back.
return Response::detect("users.editpass");
if ($request->input('password') != $request->input('confirmpassword')) { // If new password and new password confirm is not the same, go back with fail message.
return redirect()->route("users.accounteditpass")->with('error#notsamepass', '<p class="text-center">Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!</p>');
} elseif (!Hash::check($request->input('oldpassword'), $user->password)) { // If the written current password and current password in DB is not the same, go back with fail message.
return redirect()->route("users.accounteditpass")->with('error#oldpass', '<p class="text-center">Det indtastede password i `Nuværende Password` er ikke dit nuværende password!</p>');
} else { // If new password and current password is the same AND current written and current DB password is the same. Then update and logout.
/** @var User $user */
$user->update($data);
Auth::logout();
return redirect()->route("users.login");
return redirect()->route("users.login")->with('success#passwordchange', '<p class="text-center">Dit password er hermed ændret!</p>');
}
} else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user.
$user->update($data);
@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use App\UserEvent;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class UserEventController extends Controller
{
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create(Request $request)
{
// Get written data from events.index
$data = $request->validate([
"user_id" => "required|max:255",
"event_id" => "required|max:255"
]);
// Check the UserEvent table if there is a row that has the user_id AND the event_id
$getTableInfo = UserEvent::where('user_id', $request->user_id)
->where('event_id', $request->event_id)->get();
// If the row has both, then go back and show an error - Cause you're not allowed to be on the same event twice.
if (count($getTableInfo) > 0)
return redirect()->route("events.index")->with('error#' . $request->event_id, '<p class="text-center">Du har allerede tilmeldt dig denne Aktivitet!</p>');
// If not, then it keeps going and saves and shows a success message
$UserEvent = new UserEvent($data);
$UserEvent->save();
return redirect()->route("events.index")->with('signup#' . $request->event_id, '<p class="text-center">Du er hermed tilmeldt denne aktivitet!</p>');
}
}