|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Client\helpdesk; |
|
4
|
|
|
|
|
5
|
|
|
// controllers |
|
6
|
|
|
use App\Http\Controllers\Common\PhpMailController; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
// requests |
|
9
|
|
|
use App\Http\Requests\helpdesk\OtpVerifyRequest; |
|
10
|
|
|
use App\Http\Requests\helpdesk\ProfilePassword; |
|
11
|
|
|
use App\Http\Requests\helpdesk\ProfileRequest; |
|
12
|
|
|
use App\Http\Requests\helpdesk\TicketRequest; |
|
13
|
|
|
// models |
|
14
|
|
|
use App\Model\helpdesk\Manage\Help_topic; |
|
15
|
|
|
use App\Model\helpdesk\Settings\CommonSettings; |
|
16
|
|
|
use App\Model\helpdesk\Settings\Company; |
|
17
|
|
|
use App\Model\helpdesk\Settings\System; |
|
18
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Thread; |
|
19
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
20
|
|
|
use App\Model\helpdesk\Utility\CountryCode; |
|
21
|
|
|
use App\Model\helpdesk\Utility\Otp; |
|
22
|
|
|
use App\User; |
|
23
|
|
|
use Auth; |
|
24
|
|
|
// classes |
|
25
|
|
|
use DateTime; |
|
26
|
|
|
use DB; |
|
27
|
|
|
use Exception; |
|
28
|
|
|
use GeoIP; |
|
29
|
|
|
use Hash; |
|
30
|
|
|
use Illuminate\Http\Request; |
|
31
|
|
|
use Input; |
|
32
|
|
|
use Lang; |
|
33
|
|
|
use Socialite; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* GuestController. |
|
37
|
|
|
* |
|
38
|
|
|
* @author Ladybird <[email protected]> |
|
39
|
|
|
*/ |
|
40
|
|
|
class GuestController extends Controller |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* Create a new controller instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @return type void |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(PhpMailController $PhpMailController) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->middleware('board'); |
|
50
|
|
|
$this->PhpMailController = $PhpMailController; |
|
|
|
|
|
|
51
|
|
|
// checking authentication |
|
52
|
|
|
$this->middleware('auth'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get profile. |
|
57
|
|
|
* |
|
58
|
|
|
* @return type Response |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getProfile(CountryCode $code) |
|
61
|
|
|
{ |
|
62
|
|
|
$user = Auth::user(); |
|
63
|
|
|
$location = GeoIP::getLocation(); |
|
64
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
65
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
|
66
|
|
|
$status = $settings->status; |
|
67
|
|
|
|
|
68
|
|
|
return view('themes.default1.client.helpdesk.profile', compact('user')) |
|
|
|
|
|
|
69
|
|
|
->with(['phonecode' => $phonecode->phonecode, |
|
70
|
|
|
'verify' => $status, ]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Save profile data. |
|
75
|
|
|
* |
|
76
|
|
|
* @param type $id |
|
|
|
|
|
|
77
|
|
|
* @param type ProfileRequest $request |
|
78
|
|
|
* |
|
79
|
|
|
* @return type Response |
|
80
|
|
|
*/ |
|
81
|
|
|
public function postProfile(ProfileRequest $request) |
|
82
|
|
|
{ |
|
83
|
|
|
try { |
|
84
|
|
|
// geet authenticated user details |
|
85
|
|
|
$user = Auth::user(); |
|
86
|
|
View Code Duplication |
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) { |
|
|
|
|
|
|
87
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput(); |
|
|
|
|
|
|
88
|
|
|
} else { |
|
89
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); |
|
90
|
|
|
if (!count($code)) { |
|
91
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
$user->country_code = $request->country_code; |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
$user->fill($request->except('profile_pic', 'mobile')); |
|
96
|
|
|
$user->gender = $request->input('gender'); |
|
97
|
|
|
$user->save(); |
|
98
|
|
|
if (Input::file('profile_pic')) { |
|
99
|
|
|
// fetching picture name |
|
100
|
|
|
$name = Input::file('profile_pic')->getClientOriginalName(); |
|
101
|
|
|
// fetching upload destination path |
|
102
|
|
|
$destinationPath = 'uploads/profilepic'; |
|
103
|
|
|
// adding a random value to profile picture filename |
|
104
|
|
|
$fileName = rand(0000, 9999).'.'.$name; |
|
105
|
|
|
// moving the picture to a destination folder |
|
106
|
|
|
Input::file('profile_pic')->move($destinationPath, $fileName); |
|
107
|
|
|
// saving filename to database |
|
108
|
|
|
$user->profile_pic = $fileName; |
|
109
|
|
|
} |
|
110
|
|
|
if ($request->get('mobile')) { |
|
111
|
|
|
$user->mobile = $request->get('mobile'); |
|
112
|
|
|
} else { |
|
113
|
|
|
$user->mobile = null; |
|
114
|
|
|
} |
|
115
|
|
|
if ($user->save()) { |
|
116
|
|
|
return redirect()->back()->with('success', Lang::get('lang.Profile-Updated-sucessfully')); |
|
|
|
|
|
|
117
|
|
|
} else { |
|
118
|
|
|
return redirect()->back()->route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully')); |
|
119
|
|
|
} |
|
120
|
|
|
} catch (Exception $e) { |
|
121
|
|
|
return redirect()->back()->route('profile')->with('fails', $e->getMessage()); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
*@category fucntion to check if mobile number is unqique or not |
|
127
|
|
|
* |
|
128
|
|
|
*@param string $mobile |
|
129
|
|
|
* |
|
130
|
|
|
*@return bool true(if mobile exists in users table)/false (if mobile does not exist in user table) |
|
131
|
|
|
*/ |
|
132
|
|
|
public function checkMobile($mobile) |
|
133
|
|
|
{ |
|
134
|
|
|
if ($mobile) { |
|
135
|
|
|
$check = User::where('mobile', '=', $mobile) |
|
136
|
|
|
->where('id', '<>', \Auth::user()->id) |
|
137
|
|
|
->first(); |
|
138
|
|
|
if (count($check) > 0) { |
|
139
|
|
|
return true; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return false; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get Ticket page. |
|
148
|
|
|
* |
|
149
|
|
|
* @param type Help_topic $topic |
|
150
|
|
|
* |
|
151
|
|
|
* @return type Response |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getTicket(Help_topic $topic) |
|
154
|
|
|
{ |
|
155
|
|
|
$topics = $topic->get(); |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
return view('themes.default1.client.helpdesk.tickets.form', compact('topics')); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* getform. |
|
162
|
|
|
* |
|
163
|
|
|
* @param type Help_topic $topic |
|
164
|
|
|
* |
|
165
|
|
|
* @return type |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getForm(Help_topic $topic) |
|
168
|
|
|
{ |
|
169
|
|
|
if (\Config::get('database.install') == '%0%') { |
|
170
|
|
|
return \Redirect::route('licence'); |
|
171
|
|
|
} |
|
172
|
|
|
if (System::first()->status == 1) { |
|
173
|
|
|
$topics = $topic->get(); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
return view('themes.default1.client.helpdesk.form', compact('topics')); |
|
176
|
|
|
} else { |
|
177
|
|
|
return \Redirect::route('home'); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Get my ticket. |
|
183
|
|
|
* |
|
184
|
|
|
* @param type Tickets $tickets |
|
185
|
|
|
* @param type Ticket_Thread $thread |
|
186
|
|
|
* @param type User $user |
|
187
|
|
|
* |
|
188
|
|
|
* @return type Response |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getMyticket() |
|
191
|
|
|
{ |
|
192
|
|
|
return view('themes.default1.client.helpdesk.mytickets'); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get ticket-thread. |
|
197
|
|
|
* |
|
198
|
|
|
* @param type Ticket_Thread $thread |
|
199
|
|
|
* @param type Tickets $tickets |
|
200
|
|
|
* @param type User $user |
|
201
|
|
|
* |
|
202
|
|
|
* @return type Response |
|
203
|
|
|
*/ |
|
204
|
|
|
public function thread(Ticket_Thread $thread, Tickets $tickets, User $user) |
|
|
|
|
|
|
205
|
|
|
{ |
|
206
|
|
|
$user_id = Auth::user()->id; |
|
207
|
|
|
//dd($user_id); |
|
208
|
|
|
/* get the ticket's id == ticket_id of thread */ |
|
209
|
|
|
$tickets = $tickets->where('user_id', '=', $user_id)->first(); |
|
|
|
|
|
|
210
|
|
|
//dd($ticket); |
|
211
|
|
|
$thread = $thread->where('ticket_id', $tickets->id)->first(); |
|
|
|
|
|
|
212
|
|
|
//dd($thread); |
|
213
|
|
|
// $tickets = $tickets->whereId($id)->first(); |
|
|
|
|
|
|
214
|
|
|
return view('themes.default1.client.guest-user.view_ticket', compact('thread', 'tickets')); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* ticket Edit. |
|
219
|
|
|
* |
|
220
|
|
|
* @return |
|
221
|
|
|
*/ |
|
222
|
|
|
public function ticketEdit() |
|
223
|
|
|
{ |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Post porfile password. |
|
228
|
|
|
* |
|
229
|
|
|
* @param type $id |
|
|
|
|
|
|
230
|
|
|
* @param type ProfilePassword $request |
|
231
|
|
|
* |
|
232
|
|
|
* @return type Response |
|
233
|
|
|
*/ |
|
234
|
|
|
public function postProfilePassword(ProfilePassword $request) |
|
235
|
|
|
{ |
|
236
|
|
|
$user = Auth::user(); |
|
237
|
|
|
//echo $user->password; |
|
|
|
|
|
|
238
|
|
|
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) { |
|
239
|
|
|
$user->password = Hash::make($request->input('new_password')); |
|
240
|
|
|
try { |
|
241
|
|
|
$user->save(); |
|
242
|
|
|
|
|
243
|
|
|
return redirect()->back()->with('success2', Lang::get('lang.password_updated_sucessfully')); |
|
244
|
|
|
} catch (Exception $e) { |
|
245
|
|
|
return redirect()->back()->with('fails2', $e->getMessage()); |
|
246
|
|
|
} |
|
247
|
|
|
} else { |
|
248
|
|
|
return redirect()->back()->with('fails2', Lang::get('lang.password_was_not_updated_incorrect_old_password')); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Ticekt reply. |
|
254
|
|
|
* |
|
255
|
|
|
* @param type Ticket_Thread $thread |
|
256
|
|
|
* @param type TicketRequest $request |
|
257
|
|
|
* |
|
258
|
|
|
* @return type Response |
|
259
|
|
|
*/ |
|
260
|
|
|
public function reply(Ticket_Thread $thread, TicketRequest $request) |
|
261
|
|
|
{ |
|
262
|
|
|
$thread->ticket_id = $request->input('ticket_ID'); |
|
|
|
|
|
|
263
|
|
|
$thread->title = $request->input('To'); |
|
|
|
|
|
|
264
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
|
|
265
|
|
|
$thread->body = $request->input('reply_content'); |
|
|
|
|
|
|
266
|
|
|
$thread->poster = 'user'; |
|
|
|
|
|
|
267
|
|
|
$thread->save(); |
|
268
|
|
|
$ticket_id = $request->input('ticket_ID'); |
|
269
|
|
|
$tickets = Tickets::where('id', '=', $ticket_id)->first(); |
|
|
|
|
|
|
270
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first(); |
|
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
return Redirect('thread/'.$ticket_id); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* Get Checked ticket. |
|
277
|
|
|
* |
|
278
|
|
|
* @param type Tickets $ticket |
|
279
|
|
|
* @param type User $user |
|
280
|
|
|
* |
|
281
|
|
|
* @return type response |
|
282
|
|
|
*/ |
|
283
|
|
|
public function getCheckTicket(Tickets $ticket, User $user) |
|
|
|
|
|
|
284
|
|
|
{ |
|
285
|
|
|
return view('themes.default1.client.helpdesk.guest-user.newticket', compact('ticket')); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* Post Check ticket. |
|
290
|
|
|
* |
|
291
|
|
|
* @param type CheckTicket $request |
|
292
|
|
|
* @param type User $user |
|
293
|
|
|
* @param type Tickets $ticket |
|
294
|
|
|
* @param type Ticket_Thread $thread |
|
295
|
|
|
* |
|
296
|
|
|
* @return type Response |
|
297
|
|
|
*/ |
|
298
|
|
|
public function PostCheckTicket(Request $request) |
|
299
|
|
|
{ |
|
300
|
|
|
$validator = \Validator::make($request->all(), [ |
|
301
|
|
|
'email' => 'required|email', |
|
302
|
|
|
'ticket_number' => 'required', |
|
303
|
|
|
]); |
|
304
|
|
|
if ($validator->fails()) { |
|
305
|
|
|
return redirect()->back() |
|
306
|
|
|
->withErrors($validator) |
|
307
|
|
|
->withInput() |
|
308
|
|
|
->with('check', '1'); |
|
309
|
|
|
} |
|
310
|
|
|
$Email = $request->input('email'); |
|
311
|
|
|
$Ticket_number = $request->input('ticket_number'); |
|
312
|
|
|
$ticket = Tickets::where('ticket_number', '=', $Ticket_number)->first(); |
|
313
|
|
|
if ($ticket == null) { |
|
314
|
|
|
return \Redirect::route('form')->with('fails', Lang::get('lang.there_is_no_such_ticket_number')); |
|
315
|
|
|
} else { |
|
316
|
|
|
$userId = $ticket->user_id; |
|
317
|
|
|
$user = User::where('id', '=', $userId)->first(); |
|
318
|
|
View Code Duplication |
if ($user->role == 'user') { |
|
|
|
|
|
|
319
|
|
|
$username = $user->first_name; |
|
320
|
|
|
} else { |
|
321
|
|
|
$username = $user->first_name.' '.$user->last_name; |
|
322
|
|
|
} |
|
323
|
|
|
if ($user->email != $Email) { |
|
324
|
|
|
return \Redirect::route('form')->with('fails', Lang::get("lang.email_didn't_match_with_ticket_number")); |
|
325
|
|
|
} else { |
|
326
|
|
|
$code = $ticket->id; |
|
327
|
|
|
$code = \Crypt::encrypt($code); |
|
328
|
|
|
|
|
329
|
|
|
$company = $this->company(); |
|
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
$this->PhpMailController->sendmail( |
|
332
|
|
|
$from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $user->email], $message = ['subject' => 'Ticket link Request ['.$Ticket_number.']', 'scenario' => 'check-ticket'], $template_variables = ['user' => $username, 'ticket_link_with_number' => \URL::route('check_ticket', $code)] |
|
333
|
|
|
); |
|
334
|
|
|
|
|
335
|
|
|
return \Redirect::back() |
|
336
|
|
|
->with('success', Lang::get('lang.we_have_sent_you_a_link_by_email_please_click_on_that_link_to_view_ticket')); |
|
337
|
|
|
} |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* get ticket email. |
|
343
|
|
|
* |
|
344
|
|
|
* @param type $id |
|
345
|
|
|
* |
|
346
|
|
|
* @return type |
|
347
|
|
|
*/ |
|
348
|
|
|
public function get_ticket_email($id, CommonSettings $common_settings) |
|
349
|
|
|
{ |
|
350
|
|
|
$common_setting = $common_settings->select('status') |
|
|
|
|
|
|
351
|
|
|
->where('option_name', '=', 'user_set_ticket_status') |
|
352
|
|
|
->first(); |
|
353
|
|
|
|
|
354
|
|
|
return view('themes.default1.client.helpdesk.ckeckticket', compact('id', 'common_setting')); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* get ticket status. |
|
359
|
|
|
* |
|
360
|
|
|
* @param type Tickets $ticket |
|
361
|
|
|
* |
|
362
|
|
|
* @return type |
|
363
|
|
|
*/ |
|
364
|
|
|
public function getTicketStat(Tickets $ticket) |
|
365
|
|
|
{ |
|
366
|
|
|
return view('themes.default1.client.helpdesk.ckeckticket', compact('ticket')); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* get company. |
|
371
|
|
|
* |
|
372
|
|
|
* @return type |
|
373
|
|
|
*/ |
|
374
|
|
View Code Duplication |
public function company() |
|
|
|
|
|
|
375
|
|
|
{ |
|
376
|
|
|
$company = Company::Where('id', '=', '1')->first(); |
|
377
|
|
|
if ($company->company_name == null) { |
|
378
|
|
|
$company = 'Support Center'; |
|
379
|
|
|
} else { |
|
380
|
|
|
$company = $company->company_name; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
return $company; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
View Code Duplication |
public function resendOTP(OtpVerifyRequest $request) |
|
|
|
|
|
|
387
|
|
|
{ |
|
388
|
|
|
if (\Schema::hasTable('sms')) { |
|
389
|
|
|
$sms = DB::table('sms')->get(); |
|
390
|
|
|
if (count($sms) > 0) { |
|
391
|
|
|
\Event::fire(new \App\Events\LoginEvent($request)); |
|
392
|
|
|
|
|
393
|
|
|
return 1; |
|
394
|
|
|
} |
|
395
|
|
|
} else { |
|
396
|
|
|
return 'Plugin has not been setup successfully.'; |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
View Code Duplication |
public function verifyOTP() |
|
|
|
|
|
|
401
|
|
|
{ |
|
402
|
|
|
// dd(Input::all()); |
|
|
|
|
|
|
403
|
|
|
// $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first(); |
|
|
|
|
|
|
404
|
|
|
$otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id')) |
|
405
|
|
|
->first(); |
|
406
|
|
|
if ($otp != null) { |
|
407
|
|
|
$otp_length = strlen(Input::get('otp')); |
|
408
|
|
|
if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) { |
|
409
|
|
|
$otp2 = Hash::make(Input::get('otp')); |
|
|
|
|
|
|
410
|
|
|
$date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); |
|
411
|
|
|
$date2 = date('Y-m-d h:i:sa'); |
|
412
|
|
|
$time1 = new DateTime($date2); |
|
413
|
|
|
$time2 = new DateTime($date1); |
|
414
|
|
|
$interval = $time1->diff($time2); |
|
415
|
|
|
if ($interval->i > 10 || $interval->h > 0) { |
|
416
|
|
|
$message = Lang::get('lang.otp-expired'); |
|
417
|
|
|
|
|
418
|
|
|
return $message; |
|
419
|
|
|
} else { |
|
420
|
|
|
if (Hash::check(Input::get('otp'), $otp->otp)) { |
|
421
|
|
|
Otp::where('user_id', '=', Input::get('u_id')) |
|
422
|
|
|
->update(['otp' => '']); |
|
423
|
|
|
// User::where('id', '=', $user->id) |
|
|
|
|
|
|
424
|
|
|
// ->update(['active' => 1]); |
|
|
|
|
|
|
425
|
|
|
// $this->openTicketAfterVerification($user->id); |
|
|
|
|
|
|
426
|
|
|
return 1; |
|
427
|
|
|
} else { |
|
428
|
|
|
$message = Lang::get('lang.otp-not-matched'); |
|
429
|
|
|
|
|
430
|
|
|
return $message; |
|
431
|
|
|
} |
|
432
|
|
|
} |
|
433
|
|
|
} else { |
|
434
|
|
|
$message = Lang::get('lang.otp-invalid'); |
|
435
|
|
|
|
|
436
|
|
|
return $message; |
|
437
|
|
|
} |
|
438
|
|
|
} else { |
|
439
|
|
|
$message = Lang::get('lang.otp-not-matched'); |
|
440
|
|
|
|
|
441
|
|
|
return $message; |
|
442
|
|
|
} |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
public function sync() |
|
446
|
|
|
{ |
|
447
|
|
|
try { |
|
448
|
|
|
$provider = $this->getProvider(); |
|
449
|
|
|
$this->changeRedirect(); |
|
450
|
|
|
$users = Socialite::driver($provider)->user(); |
|
451
|
|
|
$this->forgetSession(); |
|
452
|
|
|
$user['provider'] = $provider; |
|
|
|
|
|
|
453
|
|
|
$user['social_id'] = $users->id; |
|
454
|
|
|
$user['name'] = $users->name; |
|
455
|
|
|
$user['email'] = $users->email; |
|
456
|
|
|
$user['username'] = $users->nickname; |
|
457
|
|
|
$user['avatar'] = $users->avatar; |
|
458
|
|
|
|
|
459
|
|
|
return redirect('client-profile')->with('success', 'Additional informations fetched'); |
|
460
|
|
|
} catch (Exception $ex) { |
|
461
|
|
|
dd($ex); |
|
462
|
|
|
|
|
463
|
|
|
return redirect('client-profile')->with('fails', $ex->getMessage()); |
|
464
|
|
|
} |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
public function getProvider() |
|
468
|
|
|
{ |
|
469
|
|
|
$provider = \Session::get('provider'); |
|
470
|
|
|
|
|
471
|
|
|
return $provider; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
public function changeRedirect() |
|
475
|
|
|
{ |
|
476
|
|
|
$provider = \Session::get('provider'); |
|
477
|
|
|
$url = \Session::get($provider.'redirect'); |
|
478
|
|
|
\Config::set("services.$provider.redirect", $url); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
public function forgetSession() |
|
482
|
|
|
{ |
|
483
|
|
|
$provider = $this->getProvider(); |
|
484
|
|
|
\Session::forget('provider'); |
|
485
|
|
|
\Session::forget($provider.'redirect'); |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
public function checkArray($key, $array) |
|
489
|
|
|
{ |
|
490
|
|
|
$value = ''; |
|
491
|
|
|
if (array_key_exists($key, $array)) { |
|
492
|
|
|
$value = $array[$key]; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
return $value; |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
public function updateUser($user = []) |
|
499
|
|
|
{ |
|
500
|
|
|
$userid = \Auth::user()->id; |
|
501
|
|
|
$useremail = \Auth::user()->email; |
|
502
|
|
|
$email = $this->checkArray('email', $user); //$user['email']; |
|
503
|
|
|
if ($email !== '' && $email !== $useremail) { |
|
504
|
|
|
throw new Exception('Sorry! your current email and '.ucfirst($user['provider']).' email is different so system can not sync'); |
|
505
|
|
|
} |
|
506
|
|
|
$this->update($userid, $user); |
|
|
|
|
|
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
public function update($userid, $user, $provider) |
|
510
|
|
|
{ |
|
511
|
|
|
$email = $this->checkArray('email', $user); |
|
512
|
|
|
$this->deleteUser($userid, $user, $provider); |
|
513
|
|
|
$this->insertAdditional($userid, $provider, $user); |
|
514
|
|
|
$this->changeEmail($email); |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
public function deleteUser($userid, $user, $provider) |
|
518
|
|
|
{ |
|
519
|
|
|
$info = new \App\UserAdditionalInfo(); |
|
520
|
|
|
$infos = $info->where('owner', $userid)->where('service', $provider)->get(); |
|
|
|
|
|
|
521
|
|
|
if ($infos->count() > 0 && count($user) > 0) { |
|
522
|
|
|
foreach ($infos as $key => $detail) { |
|
523
|
|
|
//if ($user[$key] !== $detail->$key) { |
|
|
|
|
|
|
524
|
|
|
$detail->delete(); |
|
525
|
|
|
//} |
|
526
|
|
|
} |
|
527
|
|
|
} |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
public function insertAdditional($id, $provider, $user = []) |
|
531
|
|
|
{ |
|
532
|
|
|
$info = new \App\UserAdditionalInfo(); |
|
533
|
|
|
if (count($user) > 0) { |
|
534
|
|
|
foreach ($user as $key => $value) { |
|
535
|
|
|
$info->create([ |
|
536
|
|
|
'owner' => $id, |
|
537
|
|
|
'service' => $provider, |
|
538
|
|
|
'key' => $key, |
|
539
|
|
|
'value' => $value, |
|
540
|
|
|
]); |
|
541
|
|
|
} |
|
542
|
|
|
} |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
public function changeEmail($email) |
|
546
|
|
|
{ |
|
547
|
|
|
$user = \Auth::user(); |
|
548
|
|
|
if ($user && $email && !$user->email) { |
|
549
|
|
|
$user->email = $email; |
|
550
|
|
|
$user->save(); |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
|
|
} |
|
554
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.