Commit 054da225 authored by Micheal Mand's avatar Micheal Mand Committed by Nicolas Widart

Add "Edit Profile" page.

* Add new macro to use `Form::input` instead of `Form::text`

Allows for email, url, password, etc. input types.
Signed-off-by: 's avatarMicheal Mand <micheal@kmdwebdesigns.com>

* Add "Edit Profile" page

Closes #246
Signed-off-by: 's avatarMicheal Mand <micheal@kmdwebdesigns.com>
parent f1413694
...@@ -169,6 +169,36 @@ Form::macro('normalInput', function ($name, $title, ViewErrorBag $errors, $objec ...@@ -169,6 +169,36 @@ Form::macro('normalInput', function ($name, $title, ViewErrorBag $errors, $objec
return new HtmlString($string); return new HtmlString($string);
}); });
/**
* Add an input field of specified type
*
* @param string $type The type of field
* @param string $name The field name
* @param string $title The field title
* @param object $errors The laravel errors object
* @param null|object $object The entity of the field
*
* @return HtmlString
*/
Form::macro('normalInputOfType', function ($type, $name, $title, ViewErrorBag $errors, $object = null, array $options = []) {
$options = array_merge(['class' => "form-control", 'placeholder' => $title], $options);
$string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>";
$string .= Form::label($name, $title);
if (is_object($object)) {
$currentData = $object->{$name} ?: '';
} else {
$currentData = null;
}
$string .= Form::input($type, $name, old($name, $currentData), $options);
$string .= $errors->first($name, '<span class="help-block">:message</span>');
$string .= "</div>";
return new HtmlString($string);
});
/** /**
* @param string $name * @param string $name
* @param string $title * @param string $title
......
...@@ -46,6 +46,7 @@ return [ ...@@ -46,6 +46,7 @@ return [
'available keyboard shortcuts' => 'Available keyboard shortcuts on this page', 'available keyboard shortcuts' => 'Available keyboard shortcuts on this page',
'view website' => 'View Website', 'view website' => 'View Website',
'complete your profile' => 'Complete your profile', 'complete your profile' => 'Complete your profile',
'profile' => 'Profile',
'sign out' => 'Sign out', 'sign out' => 'Sign out',
], ],
'messages' => [ 'messages' => [
......
...@@ -21,4 +21,6 @@ return [ ...@@ -21,4 +21,6 @@ return [
'role not found' => 'Role not found.', 'role not found' => 'Role not found.',
'role updated' => 'Role successfully updated.', 'role updated' => 'Role successfully updated.',
'role deleted' => 'Role successfully deleted.', 'role deleted' => 'Role successfully deleted.',
/* Profile management */
'profile updated' => 'Profile successfully updated.',
]; ];
...@@ -8,12 +8,14 @@ return [ ...@@ -8,12 +8,14 @@ return [
'users' => 'Users', 'users' => 'Users',
'new-user' => 'New user', 'new-user' => 'New user',
'edit-user' => 'Edit user', 'edit-user' => 'Edit user',
'edit-profile' => 'Edit profile',
], ],
'breadcrumb' => [ 'breadcrumb' => [
'home' => 'Home', 'home' => 'Home',
'users' => 'Users', 'users' => 'Users',
'new' => 'New', 'new' => 'New',
'edit-user' => 'Edit user', 'edit-user' => 'Edit user',
'edit-profile' => 'Edit profile',
], ],
'tabs' => [ 'tabs' => [
'data' => 'Data', 'data' => 'Data',
...@@ -47,6 +49,7 @@ return [ ...@@ -47,6 +49,7 @@ return [
'or send reset password mail' => 'or, send reset password email', 'or send reset password mail' => 'or, send reset password email',
'send reset password email' => 'Send reset password email', 'send reset password email' => 'Send reset password email',
'my account' => 'My Account', 'my account' => 'My Account',
'profile' => 'Profile',
'api-keys' => 'Api Keys', 'api-keys' => 'Api Keys',
'generate new api key' => 'Generate new API key', 'generate new api key' => 'Generate new API key',
'delete api key confirm' => 'Deleting an api key will prevent any application to use this key.', 'delete api key confirm' => 'Deleting an api key will prevent any application to use this key.',
...@@ -58,6 +61,7 @@ return [ ...@@ -58,6 +61,7 @@ return [
'create user' => 'Create users', 'create user' => 'Create users',
'edit user' => 'Edit users', 'edit user' => 'Edit users',
'destroy user' => 'Delete users', 'destroy user' => 'Delete users',
'edit profile' => 'Edit Profile',
'list api key' => 'List api keys', 'list api key' => 'List api keys',
'create api key' => 'Create api keys', 'create api key' => 'Create api keys',
'destroy api key' => 'Delete api keys', 'destroy api key' => 'Delete api keys',
......
<?php
namespace Modules\User\Http\Controllers\Admin\Account;
use Illuminate\Http\Response;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\User\Contracts\Authentication;
use Modules\User\Http\Requests\UpdateProfileRequest;
use Modules\User\Repositories\UserRepository;
class ProfileController extends AdminBaseController
{
/**
* @var UserRepository
*/
private $user;
/**
* @var Authentication
*/
private $auth;
public function __construct(UserRepository $user, Authentication $auth)
{
parent::__construct();
$this->user = $user;
$this->auth = $auth;
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return Response
*/
public function edit()
{
$user = $this->auth->user();
return view('user::admin.account.profile.edit', compact('user'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @param UpdateProfileRequest $request
*
* @return Response
*/
public function update(UpdateProfileRequest $request)
{
$user = $this->auth->user();
$this->user->update($user, $request->all());
return redirect()->back()
->withSuccess(trans('user::messages.profile updated'));
}
}
<?php
namespace Modules\User\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Modules\User\Contracts\Authentication;
class UpdateProfileRequest extends FormRequest
{
public function rules()
{
$userId = app(Authentication::class)->id();
return [
'email' => "required|email|unique:users,email,{$userId}",
'first_name' => 'required',
'last_name' => 'required',
'password' => 'confirmed',
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
...@@ -73,6 +73,14 @@ $router->group(['prefix' => '/user'], function (Router $router) { ...@@ -73,6 +73,14 @@ $router->group(['prefix' => '/user'], function (Router $router) {
}); });
$router->group(['prefix' => '/account'], function (Router $router) { $router->group(['prefix' => '/account'], function (Router $router) {
$router->get('profile', [
'as' => 'admin.account.profile.edit',
'uses' => 'Account\ProfileController@edit',
]);
$router->put('profile', [
'as' => 'admin.account.profile.update',
'uses' => 'Account\ProfileController@update',
]);
$router->bind('userTokenId', function ($id) { $router->bind('userTokenId', function ($id) {
return app(\Modules\User\Repositories\UserTokenRepository::class)->find($id); return app(\Modules\User\Repositories\UserTokenRepository::class)->find($id);
}); });
......
@extends('layouts.master')
@section('content-header')
<h1>
{{ trans('user::users.title.edit-profile') }}
</h1>
<ol class="breadcrumb">
<li><a href="{{ URL::route('dashboard.index') }}"><i class="fa fa-dashboard"></i> {{ trans('core::core.breadcrumb.home') }}</a></li>
<li class="active">{{ trans('user::users.breadcrumb.edit-profile') }}</li>
</ol>
@stop
@section('content')
{!! Form::open(['route' => ['admin.account.profile.update'], 'method' => 'put']) !!}
<div class="row">
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a href="#account_tab" data-toggle="tab">{{ trans('user::users.tabs.data') }}</a></li>
<li class=""><a href="#password_tab" data-toggle="tab">{{ trans('user::users.tabs.new password') }}</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="account_tab">
<div class="box-body">
<div class="row">
<div class="col-md-4">
{{ Form::normalInput('first_name', trans('user::users.form.first-name'), $errors, $user) }}
</div>
<div class="col-md-4">
{{ Form::normalInput('last_name', trans('user::users.form.last-name'), $errors, $user) }}
</div>
<div class="col-md-4">
{{ Form::normalInputOfType('email', 'email', trans('user::users.form.email'), $errors, $user) }}
</div>
</div>
</div>
</div>
<div class="tab-pane" id="password_tab">
<div class="box-body">
<h4>{{ trans('user::users.new password setup') }}</h4>
<div class="row">
<div class="col-md-6">
{{ Form::normalInputOfType('password', 'password', trans('user::users.form.new password'), $errors) }}
</div>
<div class="col-md-6">
{{ Form::normalInputOfType('password', 'password_confirmation', trans('user::users.form.new password confirmation'), $errors) }}
</div>
</div>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('core::core.button.update') }}</button>
<a class="btn btn-danger pull-right btn-flat" href="{{ URL::route('admin.user.user.index')}}"><i class="fa fa-times"></i> {{ trans('core::core.button.cancel') }}</a>
</div>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
@stop
@section('footer')
<a data-toggle="modal" data-target="#keyboardShortcutsModal"><i class="fa fa-keyboard-o"></i></a> &nbsp;
@stop
@section('shortcuts')
@stop
@section('scripts')
<script>
$( document ).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
$('input[type="checkbox"].flat-blue, input[type="radio"].flat-blue').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
});
});
</script>
@stop
...@@ -60,6 +60,11 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender ...@@ -60,6 +60,11 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
}); });
$menu->group(trans('user::users.my account'), function (Group $group) { $menu->group(trans('user::users.my account'), function (Group $group) {
$group->weight(110); $group->weight(110);
$group->item(trans('user::users.profile'), function (Item $item) {
$item->weight(0);
$item->icon('fa fa-user');
$item->route('admin.account.profile.edit');
});
$group->item(trans('user::users.api-keys'), function (Item $item) { $group->item(trans('user::users.api-keys'), function (Item $item) {
$item->weight(1); $item->weight(1);
$item->icon('fa fa-key'); $item->icon('fa fa-key');
......
...@@ -59,9 +59,16 @@ ...@@ -59,9 +59,16 @@
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->
<li class="user-footer"> <li class="user-footer">
<a href="{{ URL::route('logout') }}" class="btn btn-default btn-flat"> <div class="pull-left">
{{trans('core::core.general.sign out')}} <a href="{{ route('admin.account.profile.edit') }}" class="btn btn-default btn-flat">
{{ trans('core::core.general.profile') }}
</a> </a>
</div>
<div class="pull-right">
<a href="{{ route('logout') }}" class="btn btn-danger btn-flat">
{{ trans('core::core.general.sign out') }}
</a>
</div>
</li> </li>
</ul> </ul>
</li> </li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment