Skip to content

Commit

Permalink
User profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienheyd committed Apr 13, 2017
1 parent e315a19 commit 0cd055d
Show file tree
Hide file tree
Showing 91 changed files with 11,989 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ roles and permissions.
* Menu items activated by [hieu-le/active](https://github.com/letrunghieu/active)
* Server-sided datatables methods provided by [yajra/laravel-datatables](https://github.com/yajra/laravel-datatables)
* Multi-language date support by [jenssegers/date](https://github.com/jenssegers/date)
* Image manipulation by [intervention/image](https://github.com/intervention/image)
* Localized English-French

## Installation
Expand Down Expand Up @@ -131,6 +132,7 @@ Available loaders are :
* [`boilerplate::load.icheck`](src/resources/views/vendor/boilerplate/load/icheck.blade.php) : [iCheck](http://icheck.fronteed.com/) - [Example](src/resources/views/vendor/boilerplate/plugins/demo/icheck.blade.php)
* [`boilerplate::load.select2`](src/resources/views/vendor/boilerplate/load/select2.blade.php) : [Select2](https://select2.github.io/) - [Example](src/resources/views/vendor/boilerplate/plugins/demo/select2.blade.php)
* [`boilerplate::load.moment`](src/resources/views/vendor/boilerplate/load/moment.blade.php) : [MomentJs](http://momentjs.com/)
* [`boilerplate::load.fileinput`](src/resources/views/vendor/boilerplate/load/fileinput.blade.php) : [Bootstrap FileInput](http://plugins.krajee.com/file-input)

More will come...

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"hieu-le/active": "^3.4",
"yajra/laravel-datatables-oracle": "^7.3",
"lavary/laravel-menu": "^1.6",
"jenssegers/date": "^3.2"
"jenssegers/date": "^3.2",
"intervention/image": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0||~5.0"
Expand Down
7 changes: 7 additions & 0 deletions src/BoilerplateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public function register()
$this->_registerDatatables();
$this->_registerDate();
$this->_registerMenu();
$this->_registerImage();
}

private function _registerImage()
{
$this->app->register(\Intervention\Image\ImageServiceProvider::class);
$this->loader->alias('Image', \Intervention\Image\Facades\Image::class);
}

/**
Expand Down
55 changes: 54 additions & 1 deletion src/Controllers/Users/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use App\Http\Requests;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Yajra\Datatables\Datatables;
use Sebastienheyd\Boilerplate\Models\Role;
use Sebastienheyd\Boilerplate\Models\User;
use Image;
use Auth;
use URL;

Expand Down Expand Up @@ -250,4 +250,57 @@ public function firstLoginPost(Request $request)

return redirect()->route('boilerplate.home')->with('growl', [__('boilerplate::users.newpassword'), 'success']);
}

public function profile()
{
return view('boilerplate::users.profile', ['user' => Auth::user()]);
}

public function profilePost(Request $request)
{
$this->validate($request, [
'avatar' => 'mimes:jpeg,png|max:10000',
'last_name' => 'required',
'first_name' => 'required',
'password_confirmation' => 'same:password'
]);

$avatar = $request->file('avatar');
$user = Auth::user();

if ($avatar && $file = $avatar->isValid()) {
$destinationPath = dirname($user->avatar_path);
if(!is_dir($destinationPath)) mkdir($destinationPath, 0766, true);
$extension = $avatar->getClientOriginalExtension();
$fileName = md5($user->id.$user->email) . '_tmp.' . $extension;
$avatar->move($destinationPath, $fileName);

Image::make($destinationPath . DIRECTORY_SEPARATOR . $fileName)
->fit(100, 100)
->save($user->avatar_path);

unlink($destinationPath . DIRECTORY_SEPARATOR . $fileName);
}

$input = $request->all();

if($input['password'] !== null) {
$input['password'] = bcrypt($input['password']);
$input['remember_token'] = str_random(32);
} else {
unset($input['password']);
}

$user->update($input);

return redirect()->route('user.profile')->with('growl', [__('boilerplate::users.profile.successupdate'), 'success']);
}

public function avatarDelete()
{
$user = Auth::user();
if(is_file($user->avatar_path)) {
unlink($user->avatar_path);
}
}
}
64 changes: 64 additions & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,101 @@ public function sendPasswordResetNotification($token)
$this->notify(new ResetPasswordNotification($token));
}

/**
* Send notification when a new user is created
*
* @param string $token
*/
public function sendNewUserNotification($token)
{
$this->notify(new NewUserNotification($token, $this));
}

/**
* Return last name in uppercase by default
*
* @param $value
* @return mixed|string
*/
public function getLastNameAttribute($value)
{
return mb_strtoupper($value);
}

/**
* Return first name with first char of every word in uppercase
*
* @param $value
* @return mixed|string
*/
public function getFirstNameAttribute($value)
{
return mb_convert_case($value, MB_CASE_TITLE);
}

/**
* Return instance of Jenssegers\Date\Date
*
* @param $value
* @return \Jenssegers\Date\Date
*/
public function getCreatedAtAttribute($value)
{
return Date::parse($value);
}

public function getNameAttribute()
{
return $this->first_name.' '.$this->last_name;
}

/**
* Return last login date formatted
*
* @param string $format
* @param string $default
* @return mixed|string
*/
public function getLastLogin($format = 'Y-m-d H:i:s', $default = '')
{
if($this->last_login === null) return $default;
return Date::parse($this->last_login)->format($format);
}

/**
* Return role list as a string
*
* @return string
*/
public function getRolesList()
{
$res = [];
foreach ($this->roles as $role) { $res[] = __($role->display_name); }
if(empty($res)) return '-';
return join(', ', $res);
}

/**
* Check if current user has an avatar
*
* @return string|false
*/
public function getAvatarPathAttribute()
{
return public_path('images/avatars/'.md5($this->id.$this->email).'.jpg');
}

/**
* Return current user avatar uri
*
* @return string
*/
public function getAvatarUrlAttribute()
{
if(is_file($this->avatar_path)) {
$ts = filemtime($this->avatar_path);
return asset('images/avatars/'.md5($this->id.$this->email).'.jpg?t='.$ts);
}
return asset("/images/default_user.png");
}
}
2 changes: 1 addition & 1 deletion src/ViewComposers/MenuComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function make(Builder $menu)
$menu->add(__('boilerplate::layout.access'), ['url' => '#', 'class' => 'treeview'])
->id('access')
->data('order', 1000)
->prepend('<i class="fa fa-lock"></i>')
->prepend('<i class="fa fa-users"></i>')
->append('<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>');

if(if_route_pattern(['roles.*', 'users.*'])) $menu->find('access')->active();
Expand Down
2 changes: 2 additions & 0 deletions src/config/boilerplate/app.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

return [
'vendorname' => 'Boilerplate', // Vendor name
'vendorlink' => '', // Vendor URL
'logo-lg' => '<b>BO</b>ilerplate', // Logo displayed on large screen (title on the top of the main menu)
'logo-mini' => 'BO', // Logo displayed on small screen
'prefix' => '', // Backend prefix. Ex: "admin" => "http://..../admin"
Expand Down
1 change: 1 addition & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"animate.css": "^3.5.2",
"bootbox": "^4.4.0",
"bootstrap": "^3.3.7",
"bootstrap-fileinput": "^4.3.8",
"bootstrap-notify": "^3.1.3",
"css-spacing": "^1.0.6",
"drmonty-datatables-plugins": "^1.10.12",
Expand Down
2 changes: 1 addition & 1 deletion src/public/css/boilerplate.css

Large diffs are not rendered by default.

Binary file added src/public/images/default_user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions src/public/js/plugins/bootstrap-fileinput/.github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
Contributing to bootstrap-fileinput
===================================
Looking to contribute something to bootstrap-fileinput? **Here's how you can help.**

Please take a moment to review this document in order to make the contribution
process easy and effective for everyone involved.

Following these guidelines helps to communicate that you respect the time of
the developers managing and developing this open source project. In return,
they should reciprocate that respect in addressing your issue or assessing
patches and features.

Using the issue tracker
-----------------------
When [reporting bugs][reporting-bugs] or
[requesting features][requesting-features], the
[issue tracker on GitHub][issue-tracker] is the recommended channel to use.

The issue tracker **is not** a place for support requests. Refer the
[plugin documentation](http://plugins.krajee.com/file-input),
[plugin demos](http://plugins.krajee.com/file-input/demo), and / or refer to the
[webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help.

Reporting bugs with bootstrap-fileinput
---------------------------------------
We really appreciate clear bug reports that _consistently_ show an issue
_within bootstrap-fileinput_.

The ideal bug report follows these guidelines:

1. **Use the [GitHub issue search][issue-search]** &mdash; Check if the issue
has already been reported.
2. **Check if the issue has been fixed** &mdash; Try to reproduce the problem
using the code in the `master` branch.
3. **Isolate the problem** &mdash; Try to create an
[isolated js fiddle][isolated-case] that consistently reproduces the problem.

Please try to be as detailed as possible in your bug report, especially if an
isolated test case cannot be made. Some useful questions to include the answer
to are:

- What steps can be used to reproduce the issue?
- What is the bug and what is the expected outcome?
- What browser(s) and Operating System have you tested with?
- Does the bug happen consistently across all tested browsers?
- What version of jQuery are you using? And what version of bootstrap-fileinput?
- Are you using bootstrap-fileinput with other plugins?

All of these questions will help others fix and identify any potential bugs.

Requesting features in bootstrap-fileinput
------------------------------------------
Before starting work on a major feature for bootstrap-fileinput, **read the
[documentation](http://plugins.krajee.com/file-input) first** or you may risk spending a considerable amount of
time on something which the project developers are not interested in bringing into the project.

### Submitting a pull request

We use GitHub's pull request system for submitting patches. Here are some
guidelines to follow when creating the pull request for your fix.

1. Make sure to create a ticket for your pull request. This will serve as the
bug ticket, and any discussion about the bug will take place there. Your pull
request will be focused on the specific changes that fix the bug.
2. Make sure to reference the ticket you are fixing within your pull request.
This will allow us to close off the ticket once we merge the pull request, or
follow up on the ticket if there are any related blocking issues.
3. Explain why the specific change was made. Not everyone who is reviewing your
pull request will be familiar with the problem it is fixing.
4. Run your tests first. If your tests aren't passing, the pull request won't
be able to be merged. If you're breaking existing tests, make sure that you
aren't causing any breaking changes.
5. Only include source changes. While it's not required, only including changes
from the `src` directory will prevent merge conflicts from occuring. Making
this happen can be as a simple as not committing changes from the `dist`
directory.

By following these steps, you will make it easier for your pull request to be
reviewed and eventually merged.

Triaging issues and pull requests
---------------------------------
Anyone can help the project maintainers triage issues and review pull requests.

### Handling new issues

bootstrap-fileinput regularly receives new issues which need to be tested and organized.

When a new issue that comes in that is similar to another existing issue, it
should be checked to make sure it is not a duplicate. Duplicates issues should
be marked by replying to the issue with "Duplicate of #[issue number]" where
`[issue number]` is the url or issue number for the existing issue. This will
allow the project maintainers to quickly close off additional issues and keep
the discussion focused within a single issue.

If you can test issues that are reported to bootstrap-fileinput that contain test cases and
confirm under what conditions bugs happen, that will allow others to identify
what causes a bug quicker.

### Reviewing pull requests

It is very common for pull requests to be opened for issues that contain a clear
solution to the problem. These pull requests should be rigorously reviewed by
the community before being accepted. If you are not sure about a piece of
submitted code, or know of a better way to do something, do not hesitate to make
a comment on the pull request.

### Reviving old tickets

If you come across tickets which have not been updated for a while, you are
encouraged to revive them. While this can be as simple as saying `:+1:`, it is
best if you can include more information on the issue. Common bugs and feature
requests are more likely to be fixed, whether it is by the community or the
developers, so keeping tickets up to date is encouraged.

Licensing
---------

It should also be made clear that **all code contributed to bootstrap-fileinput** must be
licensable under the [BSD-3 license][licensing]. Code that cannot be released
under this license **cannot be accepted** into the project.

[isolated-case]: https://jsfiddle.net/
[issue-search]: https://github.com/kartik-v/bootstrap-fileinput/search?q=&type=Issues
[issue-tracker]: https://github.com/kartik-v/bootstrap-fileinput/issues
[licensing]: https://github.com/kartik-v/bootstrap-fileinput/blob/master/LICENSE.md
[reporting-bugs]: #reporting-bugs-with-bootstrap-fileinput
[requesting-features]: #requesting-features-in-bootstrap-fileinput
Loading

0 comments on commit 0cd055d

Please sign in to comment.