1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
|
7
|
|
|
use Auth; |
8
|
|
|
use Hash; |
9
|
|
|
use Cloudder; |
10
|
|
|
use App\Http\Requests; |
11
|
|
|
|
12
|
|
|
class AccountController extends Controller |
13
|
|
|
{ |
14
|
|
|
protected $user; |
15
|
|
|
protected $id; |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->user = Auth::user(); |
20
|
|
|
$this->id = $this->user->id; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getAccountPage() |
24
|
|
|
{ |
25
|
|
|
return view('account.dashboard')->withAccount($this->user); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Store a newly created resource in storage. |
30
|
|
|
* |
31
|
|
|
* @param Request $request |
32
|
|
|
* @return Response |
33
|
|
|
*/ |
34
|
|
|
public function updateProfile(Request $request) |
35
|
|
|
{ |
36
|
|
|
$this->validate($request, [ |
37
|
|
|
'email' => 'required|email|min:3|unique:users,email,'. $this->id, |
38
|
|
|
'fullname' => 'required|min:3' |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$values = $request->all(); |
42
|
|
|
$this->user->fill($values)->save(); |
43
|
|
|
|
44
|
|
|
return redirect()->back()->with('info','Your Profile has been updated successfully'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function updateAvatar(Request $request) |
48
|
|
|
{ |
49
|
|
|
$this->validate($request, [ |
50
|
|
|
'file_name' => 'required|mimes:jpeg,bmp,png|between:1,7000', |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$filename = $request->file('file_name')->getRealPath(); |
54
|
|
|
|
55
|
|
|
Cloudder::upload($filename, null); |
56
|
|
|
list($width, $height) = getimagesize($filename); |
57
|
|
|
|
58
|
|
|
$fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]); |
59
|
|
|
|
60
|
|
|
$this->user->update(['avatar' => $fileUrl]); |
61
|
|
|
|
62
|
|
|
return redirect()->back()->with('info', 'Your Avatar has been updated Successfully'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function changePassword(Request $request) |
66
|
|
|
{ |
67
|
|
|
$this->validate($request, [ |
68
|
|
|
'password' => 'required|min:6|confirmed', |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
$this->user->password = Hash::make($request->password); |
72
|
|
|
$this->user->save(); |
73
|
|
|
|
74
|
|
|
return redirect()->back()->with('info', 'Password successfully updated'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function redirectToConfirmDeletePage() |
78
|
|
|
{ |
79
|
|
|
return view('account.confirm'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function dontDeleteAccount() |
83
|
|
|
{ |
84
|
|
|
return redirect('/account'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function deleteAccount(Request $request) |
88
|
|
|
{ |
89
|
|
|
$this->user->delete(); |
90
|
|
|
|
91
|
|
|
$request->session()->flush(); |
92
|
|
|
|
93
|
|
|
return redirect("/"); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|