Browse Source

Move Change Passoword to Auth namespace

pull/21/head
Nafies Luthfi 7 years ago
parent
commit
9092466830
  1. 38
      app/Http/Controllers/Auth/ChangePasswordController.php
  2. 25
      app/Http/Controllers/ChangePasswordController.php
  3. 6
      routes/web.php
  4. 12
      tests/Feature/ChangePasswordTest.php

38
app/Http/Controllers/Auth/ChangePasswordController.php

@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Users\UpdatePasswordRequest;
class ChangePasswordController extends Controller
{
/**
* Display change user password form.
*
* @return \Illuminate\View\View
*/
public function show()
{
return view('users.change-password');
}
/**
* Proccessing user password change.
*
* @param \App\Http\Requests\Users\UpdatePasswordRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdatePasswordRequest $request)
{
$user = \Auth::user();
$user->password = bcrypt($request->new_password);
$updateResponse = array('error' => __('auth.change_password_error'));
if ($user->save()) {
$updateResponse = array('success' => __('auth.change_password_success'));
}
return redirect()->back()->with($updateResponse);
}
}

25
app/Http/Controllers/ChangePasswordController.php

@ -1,25 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\Users\UpdatePasswordRequest;
class ChangePasswordController extends Controller
{
public function show()
{
return view('users.change-password');
}
public function update(UpdatePasswordRequest $request)
{
$user = \Auth::user();
$user->password = bcrypt($request->new_password);
if ($user->save()) $updateResponse = array('success' => trans('auth.change_password_success'));
else $updateResponse = array('error' => trans('auth.change_password_error'));
return redirect()->back()->with($updateResponse);
}
}

6
routes/web.php

@ -15,6 +15,9 @@ Route::get('/', 'UsersController@search');
Auth::routes(); Auth::routes();
Route::get('profile/update-password', 'Auth\ChangePasswordController@show')->middleware('auth')->name('profile.change-password.form');
Route::post('profile/update-password', 'Auth\ChangePasswordController@update')->middleware('auth')->name('profile.change-password.update');
Route::get('home', 'HomeController@index')->name('home'); Route::get('home', 'HomeController@index')->name('home');
Route::get('profile', 'HomeController@index')->name('profile'); Route::get('profile', 'HomeController@index')->name('profile');
Route::post('family-actions/{user}/set-father', 'FamilyActionsController@setFather')->name('family-actions.set-father'); Route::post('family-actions/{user}/set-father', 'FamilyActionsController@setFather')->name('family-actions.set-father');
@ -24,9 +27,6 @@ Route::post('family-actions/{user}/add-wife', 'FamilyActionsController@addWife')
Route::post('family-actions/{user}/add-husband', 'FamilyActionsController@addHusband')->name('family-actions.add-husband'); Route::post('family-actions/{user}/add-husband', 'FamilyActionsController@addHusband')->name('family-actions.add-husband');
Route::post('family-actions/{user}/set-parent', 'FamilyActionsController@setParent')->name('family-actions.set-parent'); Route::post('family-actions/{user}/set-parent', 'FamilyActionsController@setParent')->name('family-actions.set-parent');
Route::get('profile/update-password', 'ChangePasswordController@show')->middleware('auth')->name('profile.change-password.form');
Route::post('profile/update-password', 'ChangePasswordController@update')->middleware('auth')->name('profile.change-password.update');
Route::get('profile-search', 'UsersController@search')->name('users.search'); Route::get('profile-search', 'UsersController@search')->name('users.search');
Route::get('users/{user}', 'UsersController@show')->name('users.show'); Route::get('users/{user}', 'UsersController@show')->name('users.show');
Route::get('users/{user}/edit', 'UsersController@edit')->name('users.edit'); Route::get('users/{user}/edit', 'UsersController@edit')->name('users.edit');

12
tests/Feature/ChangePasswordTest.php

@ -15,15 +15,15 @@ class ChangePasswordTest extends TestCase
$user = $this->loginAsUser(['password' => bcrypt('secret')]); $user = $this->loginAsUser(['password' => bcrypt('secret')]);
$this->visit(route('home')); $this->visit(route('home'));
$this->click(trans('auth.change_password'));
$this->click(__('auth.change_password'));
$this->submitForm(trans('auth.change_password'), [
$this->submitForm(__('auth.change_password'), [
'old_password' => 'secret', 'old_password' => 'secret',
'new_password' => 'rahasia', 'new_password' => 'rahasia',
'new_password_confirmation' => 'rahasia', 'new_password_confirmation' => 'rahasia',
]); ]);
$this->seeText(trans('auth.change_password_success'));
$this->seeText(__('auth.change_password_success'));
$this->assertTrue( $this->assertTrue(
app('hash')->check('rahasia', $user->password), app('hash')->check('rahasia', $user->password),
@ -37,15 +37,15 @@ class ChangePasswordTest extends TestCase
$user = $this->loginAsUser(['password' => bcrypt('secret')]); $user = $this->loginAsUser(['password' => bcrypt('secret')]);
$this->visit(route('home')); $this->visit(route('home'));
$this->click(trans('auth.change_password'));
$this->click(__('auth.change_password'));
$this->submitForm(trans('auth.change_password'), [
$this->submitForm(__('auth.change_password'), [
'old_password' => 'member1', 'old_password' => 'member1',
'new_password' => 'rahasia', 'new_password' => 'rahasia',
'new_password_confirmation' => 'rahasia', 'new_password_confirmation' => 'rahasia',
]); ]);
$this->seeText(trans('passwords.old_password'));
$this->seeText(__('passwords.old_password'));
$this->assertTrue( $this->assertTrue(
app('hash')->check('secret', $user->password), app('hash')->check('secret', $user->password),

Loading…
Cancel
Save