|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Dashboard |
|
5
|
|
|
* @author Ian Olson <[email protected]> |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2015, Laraflock |
|
8
|
|
|
* @link https://github.com/laraflock |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Laraflock\Dashboard\Controllers; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Http\Request; |
|
14
|
|
|
use Laracasts\Flash\Flash; |
|
15
|
|
|
use Laraflock\Dashboard\Exceptions\AuthenticationException; |
|
16
|
|
|
use Laraflock\Dashboard\Exceptions\FormValidationException; |
|
17
|
|
|
use Laraflock\Dashboard\Exceptions\UsersException; |
|
18
|
|
|
|
|
19
|
|
|
class AccountController extends BaseDashboardController |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Edit account information. |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Illuminate\View\View |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function edit() |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->view('account.edit'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Update account information. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Illuminate\Http\Request $request |
|
36
|
|
|
* @param $id |
|
37
|
|
|
* |
|
38
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse |
|
39
|
|
|
*/ |
|
40
|
6 |
|
public function update(Request $request, $id) |
|
41
|
|
|
{ |
|
42
|
6 |
|
if ($request->input('action') == 'update_account') { |
|
43
|
|
|
try { |
|
44
|
3 |
|
$this->userRepositoryInterface->update($request->all(), $id); |
|
45
|
3 |
|
} catch (FormValidationException $e) { |
|
46
|
1 |
|
Flash::error($e->getMessage()); |
|
47
|
|
|
|
|
48
|
1 |
|
return redirect() |
|
49
|
1 |
|
->route('account.edit') |
|
50
|
1 |
|
->withErrors($e->getErrors()) |
|
51
|
1 |
|
->withInput(); |
|
52
|
1 |
|
} catch (UsersException $e) { |
|
53
|
1 |
|
Flash::error($e->getMessage()); |
|
54
|
|
|
|
|
55
|
1 |
|
return redirect()->route('dashboard.index'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
Flash::success(trans('dashboard::dashboard.flash.account.success')); |
|
59
|
|
|
|
|
60
|
1 |
|
return redirect()->route('account.edit'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
if ($request->input('action') == 'change_password') { |
|
64
|
|
|
try { |
|
65
|
3 |
|
$this->userRepositoryInterface->updatePassword($request->all()); |
|
66
|
3 |
|
} catch (FormValidationException $e) { |
|
67
|
1 |
|
Flash::error($e->getMessage()); |
|
68
|
|
|
|
|
69
|
1 |
|
return redirect() |
|
70
|
1 |
|
->route('account.edit') |
|
71
|
1 |
|
->withErrors($e->getErrors()); |
|
72
|
1 |
|
} catch (AuthenticationException $e) { |
|
73
|
1 |
|
Flash::error(trans('dashboard::dashboard.flash.password.fail')); |
|
74
|
|
|
|
|
75
|
1 |
|
return redirect() |
|
76
|
1 |
|
->route('account.edit'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
Flash::success(trans('dashboard::dashboard.flash.password.success')); |
|
80
|
|
|
|
|
81
|
1 |
|
return redirect()->route('account.edit'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |