Skip to content

Commit 9d6926a

Browse files
Merge pull request #1 from modulr/profile
Add view edit profile and change password, Create avatar to user
2 parents c7c8e91 + c2c9516 commit 9d6926a

File tree

25 files changed

+1469
-268
lines changed

25 files changed

+1469
-268
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ DB_USERNAME=user
4545
DB_PASSWORD=password
4646
```
4747

48+
49+
#### File System
50+
```
51+
// Generate symbolic link to Storage
52+
php artisan storage:link
53+
```
54+
55+
```
56+
// Add params into .env file
57+
FILESYSTEM_DRIVER=public
58+
```
59+
60+
4861
## Run
4962

5063
```
@@ -69,18 +82,33 @@ https://medium.com/modulr/create-scaffold-with-laravel-5-7-f5ab353dff1c
6982
## Modules
7083

7184
- Auth
85+
- Login
86+
- register
87+
- Remember Password
88+
89+
90+
- Profile
91+
- Edit Name and email
92+
- Change password
93+
94+
7295
- Users & Roles --> _Comming soon..._
7396

7497

7598
## Packages
7699

100+
##### Backend
77101
- [Laravel Authentication](https://laravel.com/docs/5.7/authentication)
102+
- [Laravolt Avatar](https://github.com/laravolt/avatar)
103+
104+
105+
##### Frontend
78106
- [Laravel Frontend](https://laravel.com/docs/5.7/frontend)
79-
- [Vuejs](https://vuejs.org/)
80107
- [Bootstrap 4](https://getbootstrap.com/)
81108
- [Core UI](https://coreui.io/)
82109
- [Fontawesome 5](https://fontawesome.com/)
83110
- [simple-line-icons](http://simplelineicons.com/)
111+
- [vue-toasted](https://shakee93.github.io/vue-toasted/)
84112

85113

86114

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Illuminate\Support\Facades\Validator;
99
use Illuminate\Foundation\Auth\RegistersUsers;
1010

11+
use Avatar;
12+
use Storage;
13+
1114
class RegisterController extends Controller
1215
{
1316
/*
@@ -63,10 +66,15 @@ protected function validator(array $data)
6366
*/
6467
protected function create(array $data)
6568
{
66-
return User::create([
69+
$user = User::create([
6770
'name' => $data['name'],
6871
'email' => $data['email'],
6972
'password' => Hash::make($data['password']),
7073
]);
74+
75+
$avatar = Avatar::create($user->name)->getImageObject()->encode('png');
76+
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
77+
78+
return $user;
7179
}
7280
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Profile;
4+
5+
use Illuminate\Http\Request;
6+
use App\Http\Controllers\Controller;
7+
8+
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\Hash;
10+
11+
use Avatar;
12+
use Storage;
13+
14+
use App\User;
15+
16+
class ProfileController extends Controller
17+
{
18+
public function getAuthUser ()
19+
{
20+
return Auth::user();
21+
}
22+
23+
public function updateAuthUser (Request $request)
24+
{
25+
$this->validate($request, [
26+
'name' => 'required|string',
27+
'email' => 'required|email|unique:users,email,'.Auth::id()
28+
]);
29+
30+
$user = User::find(Auth::id());
31+
32+
$user->name = $request->name;
33+
$user->email = $request->email;
34+
$user->save();
35+
36+
$avatar = Avatar::create($user->name)->getImageObject()->encode('png');
37+
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
38+
39+
return $user;
40+
}
41+
42+
public function updateAuthUserPassword(Request $request)
43+
{
44+
$this->validate($request, [
45+
'current' => 'required',
46+
'password' => 'required|confirmed',
47+
'password_confirmation' => 'required'
48+
]);
49+
50+
$user = User::find(Auth::id());
51+
52+
if (!Hash::check($request->current, $user->password)) {
53+
return response()->json(['errors' => ['current'=> ['Current password does not match']]], 422);
54+
}
55+
56+
$user->password = Hash::make($request->password);
57+
$user->save();
58+
59+
return $user;
60+
}
61+
}

app/User.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Illuminate\Contracts\Auth\MustVerifyEmail;
77
use Illuminate\Foundation\Auth\User as Authenticatable;
88

9+
use Storage;
10+
911
class User extends Authenticatable
1012
{
1113
use Notifiable;
@@ -16,7 +18,7 @@ class User extends Authenticatable
1618
* @var array
1719
*/
1820
protected $fillable = [
19-
'name', 'email', 'password',
21+
'name', 'email', 'password', 'avatar',
2022
];
2123

2224
/**
@@ -27,4 +29,11 @@ class User extends Authenticatable
2729
protected $hidden = [
2830
'password', 'remember_token',
2931
];
32+
33+
protected $appends = ['avatar_url'];
34+
35+
public function getAvatarUrlAttribute()
36+
{
37+
return Storage::url('avatars/'.$this->id.'/'.$this->avatar);
38+
}
3039
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"php": "^7.1.3",
99
"fideloper/proxy": "^4.0",
1010
"laravel/framework": "5.7.*",
11-
"laravel/tinker": "^1.0"
11+
"laravel/tinker": "^1.0",
12+
"laravolt/avatar": "^2.0"
1213
},
1314
"require-dev": {
1415
"beyondcode/laravel-dump-server": "^1.0",

0 commit comments

Comments
 (0)