Browse Source
Merge pull request #15 from cendekia/add-change-password
Merge pull request #15 from cendekia/add-change-password
Add Change Password Feature - closes #14pull/17/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 229 additions and 2 deletions
-
25app/Http/Controllers/ChangePasswordController.php
-
39app/Http/Requests/Users/UpdatePasswordRequest.php
-
8app/Http/Requests/Users/UpdateRequest.php
-
12app/Providers/AppServiceProvider.php
-
3resources/lang/en/auth.php
-
3resources/lang/en/passwords.php
-
3resources/lang/id/auth.php
-
2resources/lang/id/passwords.php
-
1resources/views/layouts/partials/nav.blade.php
-
74resources/views/users/change-password.blade.php
-
2resources/views/users/edit.blade.php
-
3routes/web.php
-
1tests/CreatesApplication.php
-
55tests/Feature/ChangePasswordTest.php
@ -0,0 +1,25 @@ |
|||
<?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); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Users; |
|||
|
|||
use Illuminate\Foundation\Http\FormRequest; |
|||
|
|||
class UpdatePasswordRequest extends FormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'old_password' => 'min:6|max:15|current_password', |
|||
'new_password' => 'min:6|max:15|same_password|confirmed', |
|||
]; |
|||
} |
|||
|
|||
public function messages() |
|||
{ |
|||
return [ |
|||
'old_password.current_password' => trans('passwords.old_password'), |
|||
'new_password.same_password' => trans('passwords.same_password'), |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('content') |
|||
<div class="container"> |
|||
<div class="row"> |
|||
<div class="col-md-8 col-md-offset-2"> |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading">{{ trans('auth.change_password') }}</div> |
|||
|
|||
<div class="panel-body"> |
|||
@if (session('success') or session('error')) |
|||
<div class="alert alert-{{ session('success') ? 'success' : 'danger' }}"> |
|||
{{ session('success') ?: session('error')}} |
|||
</div> |
|||
@endif |
|||
<form class="form-horizontal" role="form" method="POST" action="{{ route('profile.change-password.update') }}"> |
|||
{{ csrf_field() }} |
|||
<div class="form-group{{ $errors->has('old_password') ? ' has-error' : '' }}"> |
|||
<label for="old_password" class="col-md-4 control-label">{{ trans('auth.old_password') }}</label> |
|||
|
|||
<div class="col-md-6"> |
|||
<input id="old_password" type="password" class="form-control" name="old_password" placeholder="******"> |
|||
|
|||
@if ($errors->has('old_password')) |
|||
<span class="help-block"> |
|||
<strong>{{ $errors->first('old_password') }}</strong> |
|||
</span> |
|||
@endif |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group{{ $errors->has('new_password') ? ' has-error' : '' }}"> |
|||
<label for="new_password" class="col-md-4 control-label">{{ trans('auth.new_password') }}</label> |
|||
|
|||
<div class="col-md-6"> |
|||
<input id="new_password" type="password" class="form-control" name="new_password" placeholder="******"> |
|||
|
|||
@if ($errors->has('new_password')) |
|||
<span class="help-block"> |
|||
<strong>{{ $errors->first('new_password') }}</strong> |
|||
</span> |
|||
@endif |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group{{ $errors->has('new_password_confirmation') ? ' has-error' : '' }}"> |
|||
<label for="new_password-confirm" class="col-md-4 control-label">{{ trans('auth.new_password_confirmation') }}</label> |
|||
<div class="col-md-6"> |
|||
<input id="new_password-confirm" type="password" class="form-control" name="new_password_confirmation" placeholder="******"> |
|||
|
|||
@if ($errors->has('new_password_confirmation')) |
|||
<span class="help-block"> |
|||
<strong>{{ $errors->first('new_password_confirmation') }}</strong> |
|||
</span> |
|||
@endif |
|||
</div> |
|||
</div> |
|||
<div class="form-group"> |
|||
<div class="col-md-6 col-md-offset-4"> |
|||
<button type="submit" class="btn btn-primary"> |
|||
{{ trans('auth.change_password') }} |
|||
</button> |
|||
<a href="{{ url()->previous() }}" class="btn"> |
|||
{{ trans('auth.back') }} |
|||
</a> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,55 @@ |
|||
<?php |
|||
|
|||
namespace Tests\Feature\Auth; |
|||
|
|||
use Tests\TestCase; |
|||
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|||
|
|||
class ChangePasswordTest extends TestCase |
|||
{ |
|||
use DatabaseMigrations; |
|||
|
|||
/** @test */ |
|||
public function user_can_change_password() |
|||
{ |
|||
$user = $this->loginAsUser(['password' => bcrypt('secret')]); |
|||
|
|||
$this->visit(route('home')); |
|||
$this->click(trans('auth.change_password')); |
|||
|
|||
$this->submitForm(trans('auth.change_password'), [ |
|||
'old_password' => 'secret', |
|||
'new_password' => 'rahasia', |
|||
'new_password_confirmation' => 'rahasia', |
|||
]); |
|||
|
|||
$this->seeText(trans('auth.change_password_success')); |
|||
|
|||
$this->assertTrue( |
|||
app('hash')->check('rahasia', $user->password), |
|||
'The password should changed!' |
|||
); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function user_cannot_change_password_if_old_password_wrong() |
|||
{ |
|||
$user = $this->loginAsUser(['password' => bcrypt('secret')]); |
|||
|
|||
$this->visit(route('home')); |
|||
$this->click(trans('auth.change_password')); |
|||
|
|||
$this->submitForm(trans('auth.change_password'), [ |
|||
'old_password' => 'member1', |
|||
'new_password' => 'rahasia', |
|||
'new_password_confirmation' => 'rahasia', |
|||
]); |
|||
|
|||
$this->seeText(trans('passwords.old_password')); |
|||
|
|||
$this->assertTrue( |
|||
app('hash')->check('secret', $user->password), |
|||
'The password shouldn\'t changed!' |
|||
); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue