1
0
forked from s421507/eOSP2

dodanie opcji zmiany hasła przez użytkownika

This commit is contained in:
Krzysztof Strzelecki 2019-12-26 16:04:17 +01:00
parent 969b9126c8
commit 1c9f20dd80
6 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Rules\ComparePasswords;
use Illuminate\Support\Facades\Hash;
use App\User;
class ChangePasswordController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create()
{
return view('changePassword');
}
public function update(Request $request)
{
$request->validate([
'current_password' => new ComparePasswords,
'password' => 'required|confirmed|min:6|different:current_password',
],
[
'required' => 'Podaj nowe hasło.',
'confirmed' => 'Nowe hasło się nie zgadza.',
'min' => ':attribute musi mieć przynajmniej :min znaków.',
'different' => 'Stare i nowe hasło nie mogą być identyczne.'
]);
User::find(auth()->user()->id)->update(['password'=> $request-> password]);
return redirect()->to('/userprofile')->with('success','Hasło zostało zmienione');
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Hash;
class ComparePasswords implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return Hash::check($value, auth()->user()->password);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Obecne hasło jest niepoprawne.';
}
}

View File

@ -0,0 +1,60 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
</ul>
@stop
@section('center-area')
@parent
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Zmiana hasła</div>
<div class="card-body">
<form method="POST" action="/userprofile/passwordchange">
@csrf
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Obecne hasło</label>
<div class="col-md-6">
<input id="current_password" type="password" class="form-control" name="current_password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Nowe hasło</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group row">
<label for="password_confirmation" class="col-md-4 col-form-label text-md-right">Powtórz nowe hasło</label>
<div class="col-md-6">
<input id="password_confirmation" type="password" class="form-control" name="password_confirmation">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
Zmień hasło
</button>
</div>
</div>
@include('inc.formerrors')
</form>
</div>
</div>
</div>
</div>
</div>
@stop

View File

@ -12,6 +12,15 @@
@parent
@if( auth()->check())
@if (\Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{!! \Session::get('success') !!}</li>
</ul>
</div>
@endif
<p align='center'>
<table class='firefighterViewTable'>
<tr>

View File

@ -3,6 +3,7 @@
@section('left-menu')
@parent
<ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul>
@stop

View File

@ -83,6 +83,8 @@ Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxReq
Route::get('/userprofile', 'userProfileController@create');
Route::get('/userprofile/edit', 'userProfileController@editForm');
Route::post('/userprofile/edit', 'userProfileController@update');
Route::get('/userprofile/passwordchange', 'ChangePasswordController@create');
Route::post('/userprofile/passwordchange', 'ChangePasswordController@update');;
Route::get('register/verify/{confirmationCode}', [