Fixed - Being able to change credentials without removing password

Added - Checking if the password is the same to confirm password in admin
This commit is contained in:
Anders 2020-07-31 11:14:24 +02:00
parent d8ff713b90
commit 1f5660001e
3 changed files with 22 additions and 9 deletions

View File

@ -121,14 +121,24 @@ class UserController extends Controller
*/
public function update(Request $request, $id)
{
$data = $request->all();
$user = User::find($id);
if($id === Auth::id() || auth()->user()->hasPermissionTo("user.edit")) {
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);
if ($request->password != "") { // If you have edited the password, then run this
if ($request->password == $request->password2) { // If the password is the same as confirm password, then update everything from user
$data = $request->all();
/** @var User $user */
$user->update($data);
} else // Else go back with an error message
return redirect()->route("users.edit", ['user' => $id])->with('error#passnotsame', '<p>Der stod ikke det samme i `Password` & `Confirm Password`!</p>');
}
else { // If you haven't touched the password, then update everything else but password
$data = $request->only(['name_first', 'name_last', 'email', 'phone', 'roles']);
/** @var User $user */
$user->update($data);
}
$user->roles()->detach();
$user->forgetCachedPermissions();
@ -138,6 +148,7 @@ class UserController extends Controller
//$user->save();
} else { // Else if you're not on the admin site (user site)
$data = $request->all();
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 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>');
@ -148,9 +159,10 @@ class UserController extends Controller
$user->update($data);
Auth::logout();
return redirect()->route("users.login")->with('success#passwordchange', '<p class="text-center">Dit password er hermed ændret!</p>');
return redirect()->route("users.login")->with('success#passwordchange', '<p class="text-center text-white">Dit password er hermed ændret!</p>');
}
} else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user.
$data = $request->all();
$user->update($data);
return redirect()->route("users.account")->with('success#credentialschanged', '<p class="text-center">Dine oplysninger er hermed ændret!</p>');

View File

@ -11,6 +11,7 @@
@section("content")
<h1>Rediger Bruger:</h1>
{!! session()->get('error#passnotsame') !!}
<form method="post" action="{{ route("users.update", ['user' => $user]) }}" style="display: inline-table;">
@csrf
@method("put")
@ -24,7 +25,7 @@
<input type="password" name="password" id="password1" value="" placeholder="******">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-new" onclick="show('password1', 'fa-new')"></span>
<label for="password2">Confirm Password: (Forblives blank, hvis password ikke skal ændres)</label>
<input type="password" id="password2" value="" placeholder="******">
<input type="password" name="password2" id="password2" value="" placeholder="******">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-confirm" onclick="show('password2', 'fa-confirm')"></span>
<label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" value="{{ $user->phone }}" required>

View File

@ -12,13 +12,13 @@
@method("put")
<span>Nuværende Password:</span>
<input type="password" name="oldpassword" id="old" placeholder="******">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-old" onclick="show('old', 'fa-old')"></span>
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-old" onclick="show('old', 'fa-old')"></span>
<span>Nyt Password:</span>
<input class="w-100" type="password" name="password" id="new" placeholder="******" required style="width: calc(100% - 8px)">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-new" onclick="show('new', 'fa-new')"></span>
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-new" onclick="show('new', 'fa-new')"></span>
<span>Bekræft Nyt Password:</span>
<input class="w-100" type="password" name="confirmpassword" id="confirm" placeholder="******" required style="width: calc(100% - 8px)">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-confirm" onclick="show('confirm', 'fa-confirm')"></span>
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-confirm" onclick="show('confirm', 'fa-confirm')"></span>
{!! session()->get('error#notsamepass') !!}
{!! session()->get('error#oldpass') !!}
<button type="submit" class="btn text-center btn-sde-blue mt-1">Rediger</button>