6 changed files with 112 additions and 73 deletions
-
56app/Http/Controllers/Auth/ChangePasswordController.php
-
73app/Http/Controllers/Auth/RegisterController.php
-
22resources/views/auth/passwords/change.blade.php
-
1resources/views/layouts/partials/top-nav.blade.php
-
4routes/web.php
-
29tests/Feature/Auth/UserChangePasswordTest.php
@ -0,0 +1,56 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Auth; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class ChangePasswordController extends Controller |
|||
{ |
|||
/** |
|||
* Create a new controller instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->middleware('auth'); |
|||
} |
|||
|
|||
public function getChangePassword() |
|||
{ |
|||
return view('auth.passwords.change'); |
|||
} |
|||
|
|||
protected function postChangePassword(Request $req) |
|||
{ |
|||
$this->validate($req, [ |
|||
'old_password' => 'required', |
|||
'password' => 'required|between:6,15|confirmed', |
|||
'password_confirmation' => 'required', |
|||
], [ |
|||
'old_password.required' => 'Password lama harus diisi.', |
|||
'password.required' => 'Password baru harus diisi.', |
|||
'password.between' => 'Password baru harus antara 6 - 15 karakter.', |
|||
'password.confirmed' => 'Konfirmasi password baru tidak sesuai.', |
|||
'password_confirmation.required' => 'Konfirmasi password baru harus diisi.', |
|||
]); |
|||
|
|||
$input = $req->except('_token'); |
|||
|
|||
if (app('hash')->check($input['old_password'], auth()->user()->password)) |
|||
{ |
|||
$user = auth()->user(); |
|||
$user->password = $input['password']; |
|||
$user->save(); |
|||
|
|||
flash()->success(trans('auth.old_password_success')); |
|||
return back(); |
|||
} |
|||
|
|||
flash()->error(trans('auth.old_password_failed')); |
|||
return back(); |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Auth; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
use App\User; |
|||
use Illuminate\Foundation\Auth\RegistersUsers; |
|||
use Illuminate\Support\Facades\Validator; |
|||
|
|||
class RegisterController extends Controller |
|||
{ |
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| Register Controller |
|||
|-------------------------------------------------------------------------- |
|||
| |
|||
| This controller handles the registration of new users as well as their |
|||
| validation and creation. By default this controller uses a trait to |
|||
| provide this functionality without requiring any additional code. |
|||
| |
|||
*/ |
|||
|
|||
use RegistersUsers; |
|||
|
|||
/** |
|||
* Where to redirect users after registration. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $redirectTo = '/home'; |
|||
|
|||
/** |
|||
* Create a new controller instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->middleware('guest'); |
|||
} |
|||
|
|||
/** |
|||
* Get a validator for an incoming registration request. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return \Illuminate\Contracts\Validation\Validator |
|||
*/ |
|||
protected function validator(array $data) |
|||
{ |
|||
return Validator::make($data, [ |
|||
'name' => 'required|string|max:255', |
|||
'email' => 'required|string|email|max:255|unique:users', |
|||
'password' => 'required|string|min:6|confirmed', |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Create a new user instance after a valid registration. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return User |
|||
*/ |
|||
protected function create(array $data) |
|||
{ |
|||
return User::create([ |
|||
'name' => $data['name'], |
|||
'email' => $data['email'], |
|||
'password' => bcrypt($data['password']), |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('auth.change_password')) |
|||
|
|||
@section('content') |
|||
<div class="col-md-6 col-md-offset-3"> |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('auth.change_password') }}</h3></div> |
|||
{!! Form::open(['route'=>'change-password']) !!} |
|||
<div class="panel-body"> |
|||
{!! FormField::password('old_password', ['label'=> trans('auth.old_password')]) !!} |
|||
{!! FormField::password('password', ['label'=>trans('auth.new_password')]) !!} |
|||
{!! FormField::password('password_confirmation', ['label'=>trans('auth.new_password_confirmation')]) !!} |
|||
</div> |
|||
<div class="panel-footer"> |
|||
{!! Form::submit(trans('auth.change_password'), ['class'=>'btn btn-info']) !!} |
|||
{!! link_to_route('home',trans('app.cancel'),[],['class'=>'btn btn-default']) !!} |
|||
</div> |
|||
{!! Form::close() !!} |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
namespace Tests\Feature\Auth; |
|||
|
|||
use App\User; |
|||
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|||
use Tests\BrowserKitTestCase; |
|||
|
|||
class UserChangePasswordTest extends BrowserKitTestCase |
|||
{ |
|||
use DatabaseMigrations; |
|||
|
|||
/** @test */ |
|||
public function user_can_change_password() |
|||
{ |
|||
$user = factory(User::class)->make(['username' => '123456']); |
|||
$this->actingAs($user); |
|||
$this->visit(route('change-password')); |
|||
|
|||
$this->type('secret','old_password'); |
|||
$this->type('member','password'); |
|||
$this->type('member','password_confirmation'); |
|||
$this->press(trans('auth.change_password')); |
|||
$this->see(trans('auth.old_password_success')); |
|||
$this->seePageIs(route('change-password')); |
|||
|
|||
$this->assertTrue(app('hash')->check('member', $user->password)); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue