Skip to content

Commit

Permalink
Update user profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
3brettb committed May 9, 2017
1 parent d8b809d commit 8f1fdf7
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 23 deletions.
84 changes: 84 additions & 0 deletions app/Http/Controllers/Action/UpdateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Http\Controllers\Action;

use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;

class UpdateController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Update user Password.
*
* @return \Illuminate\Http\Response
*/
public function password(Request $request)
{

$validator = Validator::make($request->all(), [
'current' => 'required',
'password' => 'required|min:6|confirmed'
]);

$validator->currentRequest = $request;

$validator->after(function($validator){
if(!Hash::check($validator->currentRequest->current, auth()->user()->password)){
$validator->errors()->add('current', 'The password entered did not match your current password.');
}
});

if ($validator->fails()) {
return Redirect::to(URL::previous() . "#account_settings")
->withErrors($validator)
->withInput();
}

auth()->user()->update([
"password" => bcrypt($request->password),
]);

return Redirect::to(URL::previous() . "#account_settings");
}

/**
* Update user profile attributes
*
* @return \Illuminate\Http\Response
*/
public function profile(Request $request)
{

$validator = Validator::make($request->all(), [
'email' => 'required|email|max:255|unique:users,email,'.auth()->user()->id,
'phone' => 'nullable|min:9|max:10|unique:users,phone,'.auth()->user()->id,
]);

if ($validator->fails()) {
return Redirect::to(URL::previous() . "#account_settings")
->withErrors($validator)
->withInput();
}

auth()->user()->update([
"email" => $request->email,
"phone" => $request->phone,
]);

return Redirect::to(URL::previous() . "#account_settings");
}
}
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'firstname', 'lastname', 'email', 'password', 'status',
'firstname', 'lastname', 'email', 'phone', 'password', 'status',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/menus/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="pull-left info">
<p>Team Name Here</p>
<a><i class="fa fa-circle bg-green"></i> {{auth()->user()->status}}</a>
<a><i class="fa fa-circle {{(auth()->user()->status == 'Online') ? 'text-green' : 'text-red'}}"></i> {{auth()->user()->status}}</a>
</div>
</div>
<!-- sidebar menu: : style can be found in sidebar.less -->
Expand Down
32 changes: 13 additions & 19 deletions resources/views/pages/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<div class="row">
<div class="col-sm-3" style="border-right: 1px solid lightgrey;">
<div class="list-group">
<a href="#" data-fill="overview" class="list-group-item active">Overview</a>
<a href="#" data-fill="account_settings" class="list-group-item list-group-item-action">Account Settings</a>
<a href="#overview" class="list-group-item">Overview</a>
<a href="#account_settings" class="list-group-item list-group-item-action">Account Settings</a>
</div>
</div>
<div id="dynamic-page-content" class="col-sm-9"></div>
Expand All @@ -37,29 +37,23 @@

@push('bottom-scripts')
$(document).ready(function() {
loc = (window.location.hash == "") ? "#overview" : window.location.hash;
window.location.hash = loc;
$(loc).addClass('active');
fill();
});

function fill(){
content = $("#dynamic-page-content")[0];
active = getactive();
data_id = $(active).data('fill');
new_data = $(getdata(data_id)).html();
$(content).html(new_data);
}

function getactive(){
return $(".list-group-item.active")[0];
}

function getdata(id){
return $("#"+id)[0];
}

$("a.list-group-item").on('click', function(item){
$(getactive()).removeClass("active");
$("a.list-group-item.active").removeClass("active");
$(this).addClass("active");
});

$(window).on('hashchange', function(){
fill();
});

function fill(){
$($("#dynamic-page-content")[0]).html($(window.location.hash).html());
}

@endpush
6 changes: 5 additions & 1 deletion resources/views/pages/profile/account.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Account Settings Panel
<h4 style="margin-top:0px;">Account Settings Panel</h4>

@include('pages.profile.forms.update_profile')

@include('pages.profile.forms.update_password')
52 changes: 52 additions & 0 deletions resources/views/pages/profile/forms/update_password.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<form class="form-horizontal" role="form" method="POST" action="{{ route('action.update.password') }}">
{{ csrf_field() }}

<div class="form-group{{ $errors->has('current') ? ' has-error' : '' }}">
<label for="current" class="col-md-4 control-label">Current Password</label>

<div class="col-md-6">
<input id="current" type="password" class="form-control" name="current" required>

@if ($errors->has('current'))
<span class="help-block">
<strong>{{ $errors->first('current') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>

<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>

@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>

@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('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">
Change Password
</button>
</div>
</div>
</form>
39 changes: 39 additions & 0 deletions resources/views/pages/profile/forms/update_profile.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<form class="form-horizontal" role="form" method="POST" action="{{ route('action.update.profile') }}">
{{ csrf_field() }}

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">Email</label>

<div class="col-md-6">
<input id="email" type="text" class="form-control" name="email" value="{{auth()->user()->email}}" required>

@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('phone') ? ' has-error' : '' }}">
<label for="phone" class="col-md-4 control-label">Phone</label>

<div class="col-md-6">
<input id="phone" type="text" class="form-control" name="phone" value="{{auth()->user()->phone}}">

@if ($errors->has('phone'))
<span class="help-block">
<strong>{{ $errors->first('phone') }}</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">
Save Profile
</button>
</div>
</div>
</form>
2 changes: 1 addition & 1 deletion resources/views/pages/profile/overview.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Overview Panel
<h4 style="margin-top:0px;">Overview Panel</h4>

0 comments on commit 8f1fdf7

Please sign in to comment.