Skip to content

Commit

Permalink
Merge branch 'users'
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredobarron committed Oct 24, 2018
2 parents b72c6fd + f094c27 commit 9cff2b7
Show file tree
Hide file tree
Showing 27 changed files with 7,443 additions and 754 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/Profile/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function updateAuthUser (Request $request)
public function updatePasswordAuthUser(Request $request)
{
$this->validate($request, [
'current' => 'required',
'password' => 'required|confirmed',
'password_confirmation' => 'required'
'current' => 'required|string',
'password' => 'required|string|confirmed',
'password_confirmation' => 'required|string'
]);

$user = User::find(Auth::id());
Expand Down
87 changes: 87 additions & 0 deletions app/Http/Controllers/Users/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace App\Http\Controllers\Users;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;

use Avatar;

use App\User;

class UserController extends Controller
{
public function filter (Request $request)
{
$query = User::query();

if($request->search) {
$query->where('name', 'LIKE', '%'.$request->search.'%');
}

$users = $query->orderBy($request->column, $request->direction)
->paginate($request->perPage);

return $users;
}

public function show ($user)
{
return User::findOrFail($user);
}

public function store (Request $request)
{
$this->validate($request, [
'name' => 'required|string',
'email' => 'required|email|unique:users',
'password' => 'required|string'
]);

$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password)
]);

$avatar = Avatar::create($user->name)->getImageObject()->encode('png');
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);

return $user;
}

public function update (Request $request)
{
$this->validate($request, [
'name' => 'required|string',
'email' => 'required|email|unique:users,email,'.$request->id,
'password' => 'string|nullable'
]);

$user = User::find($request->id);

if ($user->name != $request->name) {
$avatar = Avatar::create($request->name)->getImageObject()->encode('png');
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
$user->name = $request->name;
}
if ($user->email != $request->email) {
$user->email = $request->email;
}
if ($request->password != '') {
$user->password = Hash::make($request->password);
}

$user->save();

return $user;
}

public function destroy ($user)
{
return User::destroy($user);
}
}
4 changes: 4 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;

use Storage;

class User extends Authenticatable
{
use Notifiable;
use SoftDeletes;

/**
* The attributes that are mass assignable.
Expand All @@ -30,6 +32,8 @@ class User extends Authenticatable
'password', 'remember_token',
];

protected $dates = ['deleted_at'];

protected $appends = ['avatar_url'];

public function getAvatarUrlAttribute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function up()
$table->string('avatar')->default('avatar.png');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}

Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"perfect-scrollbar": "^1.4.0",
"simple-line-icons": "^2.4.1",
"vue-clip": "^1.0.0",
"vue-moment": "^4.0.0",
"vue-multiselect": "^2.1.0",
"vue-toasted": "^1.1.24"
}
}
46 changes: 41 additions & 5 deletions public/css/app.css

Large diffs are not rendered by default.

Loading

0 comments on commit 9cff2b7

Please sign in to comment.