Merge branch 'master' into LiveSearch

This commit is contained in:
Neerholt
2020-07-27 14:23:13 +02:00
committed by GitHub
41 changed files with 439 additions and 134 deletions
@@ -8,6 +8,7 @@ use Illuminate\Http\Response;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Spatie\Permission\Models\Role;
@@ -77,6 +78,7 @@ class UserController extends Controller
// Log::debug("CREATED USER [NOT PERSISTED YET]");
$user->assignRole([ "R1", "R2" ]);
$user->save();
// Log::debug("SAVED USER");
@@ -151,19 +153,36 @@ class UserController extends Controller
// else if(Auth::user()->hasPermissionTo("user.edit")) {
$user = User::find($id);
/** @var User $user */
$user->update($data);
if ($request->roles != null) {
if ($request->roles != null) { //You can only edit roles on the admin site, so if there is an input roles, then update user info and edit roles
/** @var User $user */
$user->update($data);
$user->roles()->detach();
$user->forgetCachedPermissions();
foreach ($request->roles as $role){
$user->assignRole($role);
}
//$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");
} 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");
}
} else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user.
$user->update($data);
}
}
$user->save();
// }
$users = User::query()->paginate(20);