1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms\Controllers; |
4
|
|
|
|
5
|
|
|
use Chuckbe\Chuckcms\Chuck\SiteRepository; |
6
|
|
|
use Chuckbe\Chuckcms\Models\Site; |
7
|
|
|
use Chuckbe\Chuckcms\Models\User; |
8
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
9
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
10
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Illuminate\Routing\Controller as BaseController; |
13
|
|
|
|
14
|
|
|
class SiteController extends BaseController |
15
|
|
|
{ |
16
|
|
|
use AuthorizesRequests; |
17
|
|
|
use DispatchesJobs; |
18
|
|
|
use ValidatesRequests; |
19
|
|
|
|
20
|
|
|
private $site; |
21
|
|
|
private $siteRepository; |
22
|
|
|
private $user; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create a new controller instance. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Site $site, SiteRepository $siteRepository, User $user) |
30
|
|
|
{ |
31
|
|
|
$this->site = $site; |
32
|
|
|
$this->siteRepository = $siteRepository; |
33
|
|
|
$this->user = $user; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function save(Request $request) |
37
|
|
|
{ |
38
|
|
|
//validate the request |
39
|
|
|
$this->validate(request(), [//@todo create custom Request class for site validation |
40
|
|
|
'site_name' => 'max:185|required', |
41
|
|
|
'site_slug' => 'max:70', |
42
|
|
|
'site_domain' => 'required', |
43
|
|
|
'company.*' => 'string|nullable', |
44
|
|
|
'socialmedia.*' => 'string|nullable', |
45
|
|
|
'favicon.*' => 'string|nullable', |
46
|
|
|
'logo.*' => 'string|nullable', |
47
|
|
|
'integrations.*' => 'string|nullable', |
48
|
|
|
'lang' => 'array', |
49
|
|
|
'site_id' => 'required|nullable', |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
//update or create settings |
53
|
|
|
$this->siteRepository->updateOrCreateFromRequest($request); |
54
|
|
|
|
55
|
|
|
//redirect back |
56
|
|
|
return redirect()->route('dashboard.settings')->with('notification', 'Instellingen opgeslagen!'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function activateIndex($token) |
60
|
|
|
{ |
61
|
|
|
// Look up the user |
62
|
|
|
$user = $this->user->where('token', $token)->where('active', 0)->first(); |
63
|
|
|
|
64
|
|
|
if (!$user) { |
65
|
|
|
//if the invite doesn't exist do something more graceful than this |
66
|
|
|
return redirect()->route('page'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return view('chuckcms::backend.users._accept', compact('user', 'token')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function activate(Request $request) |
73
|
|
|
{ |
74
|
|
|
$this->validate(request(), [//@todo create custom Request class for user password validation |
75
|
|
|
'password' => 'required|min:8|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/', |
76
|
|
|
'password_again' => 'required|same:password', |
77
|
|
|
'_user_token' => 'required', |
78
|
|
|
'_user_id' => 'required', |
79
|
|
|
]); |
80
|
|
|
|
81
|
|
|
$token = $request->get('_user_token'); |
82
|
|
|
$user_id = $request->get('_user_id'); |
83
|
|
|
|
84
|
|
|
// Look up the user |
85
|
|
|
if (!$user = $this->user->where('token', $token)->where('id', $user_id)->where('active', 0)->first()) { |
|
|
|
|
86
|
|
|
//if the user doesn't exist do something more graceful than this |
87
|
|
|
return redirect()->route('page'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->user->where('token', $token)->where('id', $user_id)->where('active', 0)->update([ |
91
|
|
|
'active' => 1, |
92
|
|
|
'password' => bcrypt($request->get('password')), |
93
|
|
|
]); |
94
|
|
|
|
95
|
|
|
return redirect()->route('login'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|