1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Page module controller |
4
|
|
|
* |
5
|
|
|
* Controller for displaying pages |
6
|
|
|
* |
7
|
|
|
* @category Controller |
8
|
|
|
* @subpackage Backend |
9
|
|
|
* @package Olapus |
10
|
|
|
* @author Jan Drda <[email protected]> |
11
|
|
|
* @copyright Jan Drda |
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace App\Http\Controllers\Frontend; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use App\Application; |
19
|
|
|
use App\Campaign; |
20
|
|
|
use App\Payment; |
21
|
|
|
use App\Transaction; |
22
|
|
|
use App\User; |
23
|
|
|
use App\Recommendation; |
24
|
|
|
use Illuminate\Http\Request; |
25
|
|
|
use Illuminate\Support\Facades\View; |
26
|
|
|
use Illuminate\Support\Facades\Mail; |
27
|
|
|
use Illuminate\Support\Facades\Hash; |
28
|
|
|
use DB; |
29
|
|
|
use Carbon\Carbon; |
30
|
|
|
use Cache; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
class PageController extends FrontendController |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get homepage |
39
|
|
|
* |
40
|
|
|
* @param Request $request |
41
|
|
|
* @return View|void |
42
|
|
|
*/ |
43
|
|
|
public function getHomepage(Request $request){ |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Load data |
47
|
|
|
*/ |
48
|
|
|
$this->_arViewData = $this->_loadPageByUrl('/'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Number of users |
52
|
|
|
*/ |
53
|
|
|
$this->_arViewData['users_no'] = User::count() + 135000; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Number of campaigns |
57
|
|
|
*/ |
58
|
|
|
$this->_arViewData['campaigns_no'] = Campaign::count(); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Number of payments total |
62
|
|
|
*/ |
63
|
|
|
$this->_arViewData['payments_no_total'] = Payment::sum('amount'); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Number of payments last month |
67
|
|
|
*/ |
68
|
|
|
$this->_arViewData['payments_no_last_month'] = Payment::where('created_at', '>=', Carbon::now()->subMonth())->count(); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Return view |
72
|
|
|
*/ |
73
|
|
|
return $this->_showViewOr404('frontend.homepage'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get contact |
78
|
|
|
* |
79
|
|
|
* @param Request $request |
80
|
|
|
* @return View|void |
81
|
|
|
*/ |
82
|
|
|
public function getContact(Request $request){ |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Clear sessions |
86
|
|
|
*/ |
87
|
|
|
$this->_resetSessionFields($request); |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Load page |
91
|
|
|
*/ |
92
|
|
|
$this->_arViewData = $this->_loadPageByUrl('kontaktujte-nas'); |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return view |
96
|
|
|
*/ |
97
|
|
|
return $this->_showViewOr404('frontend.contact'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Send e-mail to DB |
102
|
|
|
* |
103
|
|
|
* @param Request $request |
104
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
105
|
|
|
*/ |
106
|
|
|
public function registerEmail(Request $request){ |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Validate |
110
|
|
|
*/ |
111
|
|
|
if(env('RECAPTCHA_ENABLED') == 1){ |
112
|
|
|
$this->validate($request, [ |
113
|
|
|
'email' => 'email|required|max:255', |
114
|
|
|
'g-recaptcha-response' => 'required|recaptcha' |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
else { |
118
|
|
|
|
119
|
|
|
$this->validate($request, [ |
120
|
|
|
'email' => 'email|required|max:255' |
121
|
|
|
]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* User data |
126
|
|
|
*/ |
127
|
|
|
$ip = $request->ip(); |
128
|
|
|
$email = $request->email; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* TEMPORARY |
132
|
|
|
*/ |
133
|
|
|
//DB::table('users')->where('email', $email)->delete(); |
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Check if user exists |
137
|
|
|
*/ |
138
|
|
|
$user = User::where('email', $email)->orWhere('ip', $ip)->first(); |
139
|
|
|
$login = NULL; |
|
|
|
|
140
|
|
|
$password = NULL; |
|
|
|
|
141
|
|
|
$activation_code = base64_encode(Hash::make($email . time())); |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* User not exists |
145
|
|
|
*/ |
146
|
|
|
if(empty($user)){ |
147
|
|
|
|
148
|
|
|
$login = $email; |
149
|
|
|
$password = str_random(10); |
150
|
|
|
|
151
|
|
|
$user = new User(); |
152
|
|
|
$user->email = $login; |
|
|
|
|
153
|
|
|
$user->name = ''; |
|
|
|
|
154
|
|
|
$user->password = Hash::make($password); |
|
|
|
|
155
|
|
|
$user->activation_code = $activation_code; |
|
|
|
|
156
|
|
|
$user->ip = $ip; |
|
|
|
|
157
|
|
|
$user->usergroup_id = 2; |
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Save recommendation |
161
|
|
|
*/ |
162
|
|
|
if(Cache::has('recommendation_id')){ |
163
|
|
|
|
164
|
|
|
$recommendation_id = Cache::get('recommendation_id'); |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Delete |
168
|
|
|
*/ |
169
|
|
|
Cache::forget('recommendation_id'); |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Check if recommendation was not used |
173
|
|
|
*/ |
174
|
|
|
$test = User::where('recommendation_id', $recommendation_id)->first(); |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* If not , add to user |
179
|
|
|
*/ |
180
|
|
|
if(empty($test)){ |
181
|
|
|
$user->recommendation_id = $recommendation_id; |
|
|
|
|
182
|
|
|
|
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$user->save(); |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Send e-mail |
190
|
|
|
*/ |
191
|
|
|
Mail::send(['emails.html.registration', 'emails.plain.registration'], [ |
192
|
|
|
'user' => $user, |
193
|
|
|
'login' => $login, |
194
|
|
|
'password' => $password, |
195
|
|
|
'activation_code' => $activation_code |
196
|
|
|
|
197
|
|
|
], function ($message) { |
198
|
|
|
$message->from(env('MAIL_FROM_EMAIL', '[email protected]'), env('MAIL_FROM_NAME', 'Surimail.cz')); |
199
|
|
|
$message->to(request('email'), request('email')); |
200
|
|
|
$message->subject('Registrace na serveru Surimail.cz'); |
201
|
|
|
|
202
|
|
|
}); |
203
|
|
|
|
204
|
|
|
$request->session()->flash('success', 'Děkujeme za registraci! Další instrukce naleznete ve Vašem e-mailu!'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* User exists - error |
209
|
|
|
*/ |
210
|
|
|
else{ |
211
|
|
|
|
212
|
|
|
$request->session()->flash('custom_error', 'Zadaný e-mail nebo IP již existuje'); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
return redirect(route('frontend.homepage.index')); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Check activation code |
220
|
|
|
* |
221
|
|
|
* @param $email |
222
|
|
|
* @param $activationCode |
223
|
|
|
* @param Request $request |
224
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
225
|
|
|
*/ |
226
|
|
|
public function checkActivationCode($email, $activationCode, Request $request){ |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Check if user exists |
230
|
|
|
*/ |
231
|
|
|
$user = User::where('email', $email)->where('activation_code', $activationCode)->first(); |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* User not exists or code is not valid |
235
|
|
|
*/ |
236
|
|
|
if(empty($user)){ |
237
|
|
|
$request->session()->flash('custom_error', 'Zadaný e-mail neexistuje nebo je neplatný aktivační kód'); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* User exists - activate him |
242
|
|
|
*/ |
243
|
|
|
else{ |
244
|
|
|
$user->active = true; |
245
|
|
|
$user->activation_code = str_random(16); |
246
|
|
|
$user->save(); |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Add reward for registration |
250
|
|
|
*/ |
251
|
|
|
$rewardsCount = Transaction::where('transactionstatus_id', 5)->where('user_id', $user->id)->count(); |
252
|
|
|
if($rewardsCount < 1){ |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Save transaction |
256
|
|
|
*/ |
257
|
|
|
$this->_saveTransation(5, $user->id, $this->_getSettings(6)); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Add reward for recommedation |
262
|
|
|
*/ |
263
|
|
|
|
264
|
|
|
if(!empty($user->recomendation_id) ){ |
265
|
|
|
|
266
|
|
|
$recommendation = Recommendation::find($user->reccomendation_id); |
267
|
|
|
|
268
|
|
|
if(!empty($recommendation)){ |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Check transaction |
272
|
|
|
*/ |
273
|
|
|
$transactionCount = Transaction::where('recommendation_id', $recommendation->id)->count(); |
274
|
|
|
|
275
|
|
|
if($transactionCount < 1){ |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Find user and save money |
279
|
|
|
*/ |
280
|
|
|
$rUser = User::find($recommendation->user_id); |
281
|
|
|
|
282
|
|
|
if(!empty($rUser)){ |
283
|
|
|
|
284
|
|
|
$this->_saveTransation(2, $rUser->id, $this->_getSettings(2)); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
$request->session()->flash('success', 'Gratulujeme, váš účet byl úspěšně aktivován. Přihlásit se můžete zde: ' |
291
|
|
|
. '<br><a href="'.route('admin.dashboard.index').'">'.route('admin.dashboard.index').'</a>'); |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Save reward |
295
|
|
|
*/ |
296
|
|
|
if($user->recommendation_id != null && $user->recommendation_id > 0){ |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Load recommendation |
300
|
|
|
*/ |
301
|
|
|
$recommendation = Recommendation::find($user->recommendation_id); |
302
|
|
|
|
303
|
|
|
$this->_saveTransation(2, $recommendation->user_id, $this->_getSettings(2), null, null, $user->recommendation_id); |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
return redirect(route('frontend.homepage.index')); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Get blank page |
312
|
|
|
* |
313
|
|
|
* @param $pageUrl |
314
|
|
|
* @param Request $request |
315
|
|
|
* @return View|void |
316
|
|
|
*/ |
317
|
|
|
public function index($pageUrl, Request $request){ |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Clear sessions |
321
|
|
|
*/ |
322
|
|
|
$this->_resetSessionFields($request); |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Load page |
326
|
|
|
*/ |
327
|
|
|
$this->_arViewData = $this->_loadPageByUrl($pageUrl); |
|
|
|
|
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Return view |
331
|
|
|
*/ |
332
|
|
|
return $this->_showViewOr404('frontend.blank'); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Check recommendation |
337
|
|
|
* |
338
|
|
|
* @param $id |
339
|
|
|
* @param Request $request |
340
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
341
|
|
|
*/ |
342
|
|
|
public function checkRecommmendation($id, Request $request){ |
|
|
|
|
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @todo Use validator |
346
|
|
|
*/ |
347
|
|
|
if(is_numeric($id)){ |
348
|
|
|
|
349
|
|
|
$recommendation = Recommendation::find($id); |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* If exists, than remember |
353
|
|
|
*/ |
354
|
|
|
if(!empty($recommendation)){ |
355
|
|
|
Cache::forever('recommendation_id', $id); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
return redirect(route('frontend.homepage.index')); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
} |
363
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.