Skip to content

Commit

Permalink
Added the account settings page, which was forgotten.
Browse files Browse the repository at this point in the history
  • Loading branch information
Huludini committed Feb 17, 2016
1 parent 683dd12 commit 4e11c81
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 1 deletion.
68 changes: 68 additions & 0 deletions app/Http/Controllers/Front/AccountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Http\Controllers\Front;

use App\UserInfo;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class AccountController extends Controller
{
/**
* AccountController constructor.
*/
public function __construct()
{
$this->middleware( 'auth' );
}

/**
* Show the account settings page
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getSettings()
{
pagetitle( [ trans( 'main.settings' ), settings( 'server_name' ) ] );
return view( 'front.account.index' );
}

/**
* Save the user's new password
*
* @param Request $request
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function postPassword( Request $request )
{
$this->validate($request, [
'current_password' => 'required|current_pass|max:255',
'new_password' => 'required|confirmed|min:6'
]);

$user = Auth::user();
$user->password = Hash::make( $request->new_password );
$user->save();

DB::connection('account')
->table('accounts')
->where('id', $user->id)
->update(['password' => $request->new_password]);

DB::connection('member')
->table('tb_user')
->where('idnum', $user->id)
->update([
'password' => $request->new_password,
'pwd' => Hash::make( $request->new_password )
]);

flash()->success( trans( 'main.settings_saved' ) );
return redirect( 'account/settings#password' );
}
}
8 changes: 8 additions & 0 deletions app/Http/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
$breadcrumbs->push( trans( 'main.home' ), url( '/' ) );
});

/* Account Settings */
Breadcrumbs::register( 'account.settings', function( $breadcrumbs )
{
$breadcrumbs->parent( 'home' );
$breadcrumbs->push( trans( 'main.account' ) );
$breadcrumbs->push( trans( 'main.settings' ) );
});

/* News */
Breadcrumbs::register( 'news.index', function( $breadcrumbs )
{
Expand Down
4 changes: 4 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

Route::group(['middleware' => ['web']], function () {

/* Account Settings */
Route::get( 'account/settings', ['as' => 'account.settings', 'uses' => 'Front\AccountController@getSettings'] );
Route::post( 'account/settings/password', 'Front\AccountController@postPassword' );

/* Character */
Route::get( 'character/select/{role_id}', 'Front\CharacterController@getIndex' );

Expand Down
38 changes: 38 additions & 0 deletions app/Providers/CustomValidation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class CustomValidation extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Validator::extend('current_pass', function($attribute, $value, $parameters, $validator) {
$user = Auth::user();
if ( Hash::make( $value ) !== $user->password )
{
return FALSE;
}
return TRUE;
});
}

/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
Intervention\Image\ImageServiceProvider::class,
Laravolt\Avatar\ServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
App\Providers\CustomValidation::class,

],

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
| specify a specific custom language line for a given attribute rule.
|
*/

'current_pass' => 'Your password doesn\'t match your current one.',
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
Expand Down
90 changes: 90 additions & 0 deletions resources/views/front/account/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@extends( 'front.header' )

@section( 'content' )
<div class="portlet light">
<div class="portlet-body">
<div class="tabbable-custom nav-justified">
<ul class="nav nav-tabs nav-justified">
<li class="active">
<a href="#overview" data-toggle="tab"> <i class="icon-speedometer"></i> {{ trans( 'main.acc_tabs.overview.title' ) }} </a>
</li>
<li>
<a href="#password" data-toggle="tab"> <i class="icon-lock"></i> {{ trans( 'main.acc_tabs.password.title' ) }} </a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="overview">
<div class="portlet-body form">
<div class="row">
<div class="col-md-12">
<form role="form" class="form-horizontal">
<div class="form-body">
<div class="col-md-6">
<div class="form-group form-md-line-input">
<label class="col-md-3 control-label" for="form_control_1">{{ trans( 'main.acc_tabs.overview.fields.name' ) }}</label>
<div class="col-md-9">
<div class="form-control form-control-static"> {{ Auth::user()->username }} </div>
<div class="form-control-focus"> </div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-md-line-input">
<label class="col-md-3 control-label" for="form_control_1">{{ trans( 'main.acc_tabs.overview.fields.password' ) }}</label>
<div class="col-md-9">
<div class="form-control form-control-static"> ******** </div>
<div class="form-control-focus"> </div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="password">
<div class="portlet light">
<div class="portlet-body form">
<form action="{{ url( 'account/settings/password' ) }}" method="post" class="form-horizontal">
{!! csrf_field() !!}
<div class="form-body">
<div class="form-group form-md-line-input">
<label class="col-md-3 control-label" for="current_password">{{ trans( 'main.acc_tabs.password.fields.current' ) }}</label>
<div class="col-md-9">
<input name="current_password" type="password" class="form-control" id="current_password">
<div class="form-control-focus"> </div>
<span class="help-block">{{ trans( 'main.acc_tabs.password.fields.current_desc' ) }}</span>
</div>
</div>
<div class="form-group form-md-line-input">
<label class="col-md-3 control-label" for="new_password">{{ trans( 'main.acc_tabs.password.fields.new' ) }}</label>
<div class="col-md-9">
<input name="new_password" type="password" class="form-control" id="new_password">
<div class="form-control-focus"> </div>
</div>
</div>
<div class="form-group form-md-line-input">
<label class="col-md-3 control-label" for="new_password_confirmation">{{ trans( 'main.acc_tabs.password.fields.confirm' ) }}</label>
<div class="col-md-9">
<input name="new_password_confirmation" type="password" class="form-control" id="new_password_confirmation">
<div class="form-control-focus"> </div>
</div>
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-2 col-md-9">
<button type="submit" class="btn green">{{ trans( 'main.save' ) }}</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

0 comments on commit 4e11c81

Please sign in to comment.