Change Password

master
NoNameGuy 2017-06-04 18:18:47 +01:00
parent 64db4abc50
commit 3b2df08562
3 changed files with 65 additions and 7 deletions

View File

@ -11,6 +11,9 @@ use App\Vehicles;
use App\User;
use App\Station;
use Validator;
use Hash;
class UserPageController extends Controller
{
public function index(Request $request)
@ -62,4 +65,54 @@ class UserPageController extends Controller
Auth::user()->vehicles()->where('id', $request->$data)->delete();
}
public function admin_credential_rules(array $data)
{
$messages = [
'current-password.required' => 'Please enter current password',
'password.required' => 'Please enter password',
];
$validator = Validator::make($data, [
'current-password' => 'required',
'password' => 'required|same:password',
'password_confirmation' => 'required|same:password',
], $messages);
return $validator;
}
public function postCredentials(Request $request)
{
if(Auth::Check())
{
$request_data = $request->All();
$validator = $this->admin_credential_rules($request_data);
if($validator->fails())
{
return response()->json(array('error' => $validator->getMessageBag()->toArray()), 400);
}
else
{
$current_password = Auth::User()->password;
if(Hash::check($request_data['current-password'], $current_password))
{
$user_id = Auth::User()->id;
$obj_user = User::find($user_id);
$obj_user->password = Hash::make($request_data['password']);;
$obj_user->save();
return "ok";
}
else
{
$error = array('current-password' => 'Please enter correct current password');
return response()->json(array('error' => $error), 400);
}
}
}
else
{
return redirect()->to('/');
}
}
}

View File

@ -170,26 +170,29 @@
</div>
<form id="form-change-password" role="form" method="POST" action="{{ route('editPass') }}" novalidate class="form-horizontal">
<div class="col-sm-6">
<div class="form-group">
<label>Password Antiga: </label>
<input class="form-control" id="txtName" name="name" type="text">
<label for="current-password" class="col-sm-4 control-label">Password Antiga: </label>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="password" class="form-control" id="current-password" name="current-password" placeholder="Password">
</div>
<div class="form-group">
<label>Password Nova: </label>
<input class="form-control" id="txtEmail" name="email" type="text">
<label for="password" class="col-sm-4 control-label">Password Nova: </label>
<input type="password" class="form-control" id="password" name="password" placeholder="Nova Password">
</div>
<div class="form-group">
<label>Confirmar Nova Password: </label>
<input class="form-control" id="txtEmail" name="email" type="text">
<label for="password_confirmation" class="col-sm-4 control-label">Confirmar Password</label>
<input type="password" class="form-control" id="password_confirmation" name="password_confirmation" placeholder="Confirmar Password">
</div>
<a href="#" class="btn btn-success">Alterar Password</a>
<button type="submit" class="btn btn-danger">Alterar Password</a>
</div>
</form>
</div>
</div>

View File

@ -57,3 +57,5 @@ Route::post('/showGpsCoordinates', 'LandingController@index');
Route::get('/api/districts', 'LandingController@apiDistricts')->name('apidistricts');
Route::get('/api/stations/{district}/{brand}/{fuelType}', 'LandingController@apiStations')->name('apistations');
Route::get('/userpage/edit/{id}', 'UserPageController@edit')->name('editVehicle');
Route::post('/userpage/editPass', 'UserPageController@postCredentials')->name('editPass');