|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\ApiKey; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Model\User\AccountActivate; |
|
8
|
|
|
use App\User; |
|
9
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; |
|
10
|
|
|
use App\Http\Controllers\Auth\BaseAuthController; |
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
use Validator; |
|
13
|
|
|
|
|
14
|
|
|
class AuthController extends BaseAuthController |
|
15
|
|
|
{ |
|
16
|
|
|
/* |
|
17
|
|
|
|-------------------------------------------------------------------------- |
|
18
|
|
|
| Registration & Login Controller |
|
19
|
|
|
|-------------------------------------------------------------------------- |
|
20
|
|
|
| |
|
21
|
|
|
| This controller handles the registration of new users, as well as the |
|
22
|
|
|
| authentication of existing users. By default, this controller uses |
|
23
|
|
|
| a simple trait to add these behaviors. Why don't you explore it? |
|
24
|
|
|
| |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
// use AuthenticatesAndRegistersUsers; |
|
28
|
|
|
|
|
29
|
|
|
/* to redirect after login */ |
|
30
|
|
|
|
|
31
|
|
|
//protected $redirectTo = 'home'; |
|
32
|
|
|
|
|
33
|
|
|
/* Direct After Logout */ |
|
34
|
|
|
protected $redirectAfterLogout = 'home'; |
|
35
|
|
|
protected $loginPath = 'auth/login'; |
|
36
|
|
|
|
|
37
|
|
|
//protected $loginPath = 'login'; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->middleware('guest', ['except' => 'getLogout']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function sendActivationByGet($email, Request $request) |
|
48
|
|
|
{ |
|
49
|
|
|
try { |
|
50
|
|
|
$mail = $this->sendActivation($email, $request->method()); |
|
51
|
|
|
if ($mail == 'success') { |
|
52
|
|
|
return redirect()->back()->with('success', 'Activation link has sent to your email address'); |
|
53
|
|
|
} |
|
54
|
|
|
} catch (\Exception $ex) { |
|
55
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function Activate($token, AccountActivate $activate, Request $request, User $user) |
|
62
|
|
|
{ |
|
63
|
|
|
try { |
|
64
|
|
|
if ($activate->where('token', $token)->first()) { |
|
65
|
|
|
$email = $activate->where('token', $token)->first()->email; |
|
66
|
|
|
} else { |
|
67
|
|
|
throw new NotFoundHttpException(); |
|
68
|
|
|
} |
|
69
|
|
|
//dd($email); |
|
70
|
|
|
$url = 'auth/login'; |
|
71
|
|
|
$user = $user->where('email', $email)->first(); |
|
72
|
|
|
if ($user->where('email', $email)->first()) { |
|
73
|
|
|
$user->active = 1; |
|
74
|
|
|
$user->save(); |
|
75
|
|
|
|
|
76
|
|
|
$zoho = $this->reqFields($user, $email); |
|
77
|
|
|
$auth = ApiKey::where('id', 1)->value('zoho_api_key'); |
|
78
|
|
|
$addToZoho = $this->addToZoho($auth,$zoho); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
// $mailchimp = new \App\Http\Controllers\Common\MailChimpController(); |
|
81
|
|
|
// $r = $mailchimp->addSubscriber($user->email); |
|
82
|
|
|
|
|
83
|
|
|
if (\Session::has('session-url')) { |
|
84
|
|
|
$url = \Session::get('session-url'); |
|
85
|
|
|
|
|
86
|
|
|
return redirect($url); |
|
87
|
|
|
} |
|
88
|
|
|
return redirect($url)->with('success', 'Email verification successful.Please login to access your account !!'); |
|
89
|
|
|
} else { |
|
90
|
|
|
throw new NotFoundHttpException(); |
|
91
|
|
|
} |
|
92
|
|
|
} catch (\Exception $ex) { |
|
93
|
|
|
if ($ex->getCode() == 400) { |
|
94
|
|
|
return redirect($url)->with('success', 'Email verification successful, Please login to access your account'); |
|
95
|
|
|
} |
|
96
|
|
|
return redirect($url)->with('fails', $ex->getMessage()); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get a validator for an incoming registration request. |
|
102
|
|
|
* |
|
103
|
|
|
* @param array $data |
|
104
|
|
|
* |
|
105
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
106
|
|
|
*/ |
|
107
|
|
|
public function validator(array $data) |
|
108
|
|
|
{ |
|
109
|
|
|
return Validator::make($data, [ |
|
110
|
|
|
'name' => 'required|max:255', |
|
111
|
|
|
'email' => 'required|email|max:255|unique:users', |
|
112
|
|
|
'password' => 'required|confirmed|min:6', |
|
113
|
|
|
]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Create a new user instance after a valid registration. |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $data |
|
120
|
|
|
* |
|
121
|
|
|
* @return User |
|
122
|
|
|
*/ |
|
123
|
|
|
public function create(array $data) |
|
124
|
|
|
{ |
|
125
|
|
|
return User::create([ |
|
126
|
|
|
'name' => $data['name'], |
|
127
|
|
|
'email' => $data['email'], |
|
128
|
|
|
'password' => bcrypt($data['password']), |
|
129
|
|
|
]); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
public function requestOtp(Request $request) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->validate($request, [ |
|
136
|
|
|
'code' => 'required|numeric', |
|
137
|
|
|
'mobile' => 'required|numeric', |
|
138
|
|
|
]); |
|
139
|
|
|
|
|
140
|
|
|
$number = $request->oldnumber; |
|
141
|
|
|
$newNumber = $request->newnumber; |
|
142
|
|
|
User::where('mobile', $number)->update(['mobile'=>$newNumber]); |
|
143
|
|
|
|
|
144
|
|
|
try { |
|
145
|
|
|
$code = $request->input('code'); |
|
146
|
|
|
$mobile = $request->input('mobile'); |
|
147
|
|
|
$number = $code.$mobile; |
|
148
|
|
|
$result = $this->sendOtp($mobile, $code); |
|
149
|
|
|
$response = ['type' => 'success', 'message' => 'OTP has been sent to '.$number.'.Please Verify to Login']; |
|
150
|
|
|
|
|
151
|
|
|
return response()->json($response); |
|
152
|
|
|
} catch (\Exception $ex) { |
|
153
|
|
|
$result = [$ex->getMessage()]; |
|
154
|
|
|
|
|
155
|
|
|
return response()->json(compact('result'), 500); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
public function retryOTP(Request $request) |
|
162
|
|
|
{ |
|
163
|
|
|
$this->validate($request, [ |
|
164
|
|
|
'code' => 'required|numeric', |
|
165
|
|
|
'mobile' => 'required|numeric', |
|
166
|
|
|
]); |
|
167
|
|
|
|
|
168
|
|
|
try { |
|
169
|
|
|
$code = $request->input('code'); |
|
170
|
|
|
$mobile = $request->input('mobile'); |
|
171
|
|
|
$otp = $request->input('otp'); |
|
172
|
|
|
$number = $code.$mobile; |
|
173
|
|
|
$result = $this->sendOtp($mobile, $code); |
|
174
|
|
|
// dd($result); |
|
175
|
|
|
|
|
176
|
|
|
$array = json_decode($result, true); |
|
177
|
|
|
$response = ['type' => 'success', 'message' => 'OTP has been resent to '.$number.'.Please Enter the OTP to login!!']; |
|
178
|
|
|
|
|
179
|
|
|
return response()->json($response); |
|
180
|
|
|
} catch (\Exception $ex) { |
|
181
|
|
|
$result = [$ex->getMessage()]; |
|
182
|
|
|
|
|
183
|
|
|
return response()->json(compact('result'), 500); |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function verifyOtp($mobile, $code, $otp) |
|
188
|
|
|
{ |
|
189
|
|
|
$client = new \GuzzleHttp\Client(); |
|
190
|
|
|
$number = $code.$mobile; |
|
191
|
|
|
$response = $client->request('GET', 'https://control.msg91.com/api/verifyRequestOTP.php', [ |
|
192
|
|
|
'query' => ['authkey' => '54870AO9t5ZB1IEY5913f8e2', 'mobile' => $number, 'otp' => $otp], |
|
193
|
|
|
]); |
|
194
|
|
|
|
|
195
|
|
|
return $response->getBody()->getContents(); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function postOtp(Request $request) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->validate($request, [ |
|
201
|
|
|
'otp' => 'required|numeric', |
|
202
|
|
|
]); |
|
203
|
|
|
|
|
204
|
|
|
try { |
|
205
|
|
|
$code = $request->input('code'); |
|
206
|
|
|
$mobile = $request->input('mobile'); |
|
207
|
|
|
$otp = $request->input('otp'); |
|
208
|
|
|
$userid = $request->input('id'); |
|
209
|
|
|
$verify = $this->verifyOtp($mobile, $code, $otp); |
|
210
|
|
|
$array = json_decode($verify, true); |
|
211
|
|
|
if ($array['type'] == 'error') { |
|
212
|
|
|
throw new \Exception('OTP Not Verified!'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$user = User::find($userid); |
|
216
|
|
|
if ($user) { |
|
217
|
|
|
$user->mobile = $mobile; |
|
218
|
|
|
$user->mobile_code = $code; |
|
219
|
|
|
$user->mobile_verified = 1; |
|
220
|
|
|
$user->save(); |
|
221
|
|
|
} |
|
222
|
|
|
$check = $this->checkVerify($user); |
|
223
|
|
|
$response = ['type' => 'success', 'proceed' => $check, 'user_id' => $userid, 'message' =>'Mobile verified..']; |
|
224
|
|
|
|
|
225
|
|
|
return response()->json($response); |
|
226
|
|
|
// return redirect('/login'); |
|
227
|
|
|
} catch (\Exception $ex) { |
|
228
|
|
|
$result = [$ex->getMessage()]; |
|
229
|
|
|
if ($ex->getMessage() == 'OTP Not Verified!') { |
|
230
|
|
|
$errors = ['OTP Not Verified!']; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
return response()->json(compact('result'), 500); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function verifyEmail(Request $request) |
|
238
|
|
|
{ |
|
239
|
|
|
$this->validate($request, [ |
|
240
|
|
|
'email' => 'required|email', |
|
241
|
|
|
]); |
|
242
|
|
|
$email = $request->oldmail; |
|
243
|
|
|
$newMail = $request->newmail; |
|
244
|
|
|
User::where('mobile', $email)->update(['mobile'=>$newMail]); |
|
245
|
|
|
|
|
246
|
|
|
try { |
|
247
|
|
|
$email = $request->input('email'); |
|
248
|
|
|
$userid = $request->input('id'); |
|
249
|
|
|
$user = User::find($userid); |
|
250
|
|
|
$check = $this->checkVerify($user); |
|
251
|
|
|
$method = 'POST'; |
|
252
|
|
|
//$this->sendActivation($email, $request->method()); |
|
253
|
|
|
$this->sendActivation($email, $method); |
|
254
|
|
|
$response = ['type' => 'success', 'proceed' => $check, 'email' => $email, 'message' => 'Activation link has been sent to '.$email]; |
|
255
|
|
|
|
|
256
|
|
|
return response()->json($response); |
|
257
|
|
|
|
|
258
|
|
|
} catch (\Exception $ex) { |
|
259
|
|
|
$result = [$ex->getMessage()]; |
|
260
|
|
|
|
|
261
|
|
|
return response()->json(compact('result'), 500); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function checkVerify($user) |
|
266
|
|
|
{ |
|
267
|
|
|
$check = false; |
|
268
|
|
|
if ($user->active == '1' && $user->mobile_verified == '1') { |
|
269
|
|
|
\Auth::login($user); |
|
270
|
|
|
$check = true; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
return $check; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
public function accountManager() |
|
277
|
|
|
{ |
|
278
|
|
|
$manager = ''; |
|
279
|
|
|
$users = new User(); |
|
280
|
|
|
$account_count = $users->select(\DB::raw("count('manager') as count"), 'manager') |
|
281
|
|
|
->whereNotNull('manager') |
|
282
|
|
|
->groupBy('manager') |
|
283
|
|
|
->pluck('count', 'manager') |
|
284
|
|
|
->toArray(); |
|
285
|
|
|
if ($account_count) { |
|
286
|
|
|
$manager = array_keys($account_count, min($account_count))[0]; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
return $manager; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
public function getState(Request $request, $state) |
|
293
|
|
|
{ |
|
294
|
|
|
try { |
|
295
|
|
|
$id = $state; |
|
296
|
|
|
$states = \App\Model\Common\State::where('country_code_char2', $id) |
|
297
|
|
|
->orderBy('state_subdivision_name', 'asc')->get(); |
|
298
|
|
|
foreach ($states as $stateList) { |
|
299
|
|
|
echo '<option value='.$stateList->state_subdivision_code.'>'.$stateList->state_subdivision_name.'</option>'; |
|
300
|
|
|
} |
|
301
|
|
|
} catch (\Exception $ex) { |
|
302
|
|
|
echo "<option value=''>Problem while loading</option>"; |
|
303
|
|
|
|
|
304
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public function accountManagerMail($user) |
|
309
|
|
|
{ |
|
310
|
|
|
$manager = $user->manager() |
|
311
|
|
|
|
|
312
|
|
|
->where('position', 'manager') |
|
313
|
|
|
->select('first_name', 'last_name', 'email', 'mobile_code', 'mobile', 'skype') |
|
314
|
|
|
->first(); |
|
315
|
|
|
if ($user && $user->role == 'user' && $manager) { |
|
316
|
|
|
$settings = new \App\Model\Common\Setting(); |
|
317
|
|
|
$setting = $settings->first(); |
|
318
|
|
|
$from = $setting->email; |
|
319
|
|
|
$to = $user->email; |
|
320
|
|
|
$templates = new \App\Model\Common\Template(); |
|
321
|
|
|
$template = $templates |
|
322
|
|
|
->join('template_types', 'templates.type', '=', 'template_types.id') |
|
323
|
|
|
->where('template_types.name', '=', 'manager_email') |
|
324
|
|
|
->select('templates.data', 'templates.name') |
|
325
|
|
|
->first(); |
|
326
|
|
|
$template_data = $template->data; |
|
327
|
|
|
$template_name = $template->name; |
|
328
|
|
|
$template_controller = new \App\Http\Controllers\Common\TemplateController(); |
|
329
|
|
|
$replace = [ |
|
330
|
|
|
'name' => $user->first_name.' '.$user->last_name, |
|
331
|
|
|
'manager_first_name' => $manager->first_name, |
|
332
|
|
|
'manager_last_name' => $manager->last_name, |
|
333
|
|
|
'manager_email' => $manager->email, |
|
334
|
|
|
'manager_code' => $manager->mobile_code, |
|
335
|
|
|
'manager_mobile' => $manager->mobile, |
|
336
|
|
|
'manager_skype' => $manager->skype, |
|
337
|
|
|
]; |
|
338
|
|
|
//dd($from, $to, $template_data, $template_name, $replace); |
|
339
|
|
|
$template_controller->mailing($from, $to, $template_data, $template_name, $replace, 'manager_email'); |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
public function updateUserEmail(Request $request) |
|
344
|
|
|
{ |
|
345
|
|
|
$email = $request->oldemail; |
|
346
|
|
|
$newEmail = $request->newemail; |
|
347
|
|
|
User::where('email', $email)->update(['email'=>$newEmail]); |
|
348
|
|
|
$message = 'User email updated successfully'; |
|
349
|
|
|
|
|
350
|
|
|
return $message; |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.