|
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\Http\Request; |
|
10
|
|
|
|
|
11
|
|
|
class BaseAuthController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
//Required Fields for Zoho |
|
14
|
|
|
public function reqFields($user, $email) |
|
15
|
|
|
{ |
|
16
|
|
|
$user = $user->where('email', $email)->first(); |
|
17
|
|
|
if ($user) { |
|
18
|
|
|
$xml = ' <Leads> |
|
19
|
|
|
<row no="1"> |
|
20
|
|
|
<FL val="Lead Source">Faveo Billing</FL> |
|
21
|
|
|
<FL val="Company">'.$user->company.'</FL> |
|
22
|
|
|
<FL val="First Name">'.$user->first_name.'</FL> |
|
23
|
|
|
<FL val="Last Name">'.$user->last_name.'</FL> |
|
24
|
|
|
<FL val="Email">'.$user->email.'</FL> |
|
25
|
|
|
<FL val="Manager">'.$user->manager.'</FL> |
|
26
|
|
|
|
|
27
|
|
|
<FL val="Phone">'.$user->mobile_code.''.$user->mobile.'</FL> |
|
28
|
|
|
<FL val="Mobile">'.$user->mobile_code.''.$user->mobile.'</FL> |
|
29
|
|
|
<FL val="Industry">'.$user->bussiness.'</FL> |
|
30
|
|
|
<FL val="City">'.$user->town.'</FL> |
|
31
|
|
|
<FL val="Street">'.$user->address.'</FL> |
|
32
|
|
|
<FL val="State">'.$user->state.'</FL> |
|
33
|
|
|
<FL val="Country">'.$user->country.'</FL> |
|
34
|
|
|
|
|
35
|
|
|
<FL val="Zip Code">'.$user->zip.'</FL> |
|
36
|
|
|
<FL val="No. of Employees">'.$user->company_size.'</FL> |
|
37
|
|
|
</row> |
|
38
|
|
|
</Leads>'; |
|
39
|
|
|
|
|
40
|
|
|
return $xml; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Sends Otp. |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public static function sendOtp($mobile, $code) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$client = new \GuzzleHttp\Client(); |
|
50
|
|
|
$number = $code.$mobile; |
|
51
|
|
|
$key = ApiKey::where('id', 1)->value('msg91_auth_key'); |
|
52
|
|
|
$response = $client->request('GET', 'https://control.msg91.com/api/sendotp.php', [ |
|
53
|
|
|
'query' => ['authkey' => $key, 'mobile' => $number], |
|
54
|
|
|
]); |
|
55
|
|
|
$send = $response->getBody()->getContents(); |
|
56
|
|
|
$array = json_decode($send, true); |
|
57
|
|
|
if ($array['type'] == 'error') { |
|
58
|
|
|
throw new \Exception($array['message']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $array['type']; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* ReSends Otp. |
|
66
|
|
|
*/ |
|
67
|
|
View Code Duplication |
public function sendForReOtp($mobile, $code) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
$client = new \GuzzleHttp\Client(); |
|
70
|
|
|
$number = $code.$mobile; |
|
71
|
|
|
$key = ApiKey::where('id', 1)->value('msg91_auth_key'); |
|
72
|
|
|
$response = $client->request('GET', 'https://control.msg91.com/api/retryotp.php', [ |
|
73
|
|
|
'query' => ['authkey' => $key, 'mobile' => $number], |
|
74
|
|
|
]); |
|
75
|
|
|
$send = $response->getBody()->getContents(); |
|
76
|
|
|
$array = json_decode($send, true); |
|
77
|
|
|
if ($array['type'] == 'error') { |
|
78
|
|
|
throw new \Exception($array['message']); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $array['type']; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Sends otp and email for confirmatiob. |
|
86
|
|
|
*/ |
|
87
|
|
|
public function requestOtpFromAjax(Request $request) |
|
88
|
|
|
{ |
|
89
|
|
|
// dd($request->allow()); |
|
90
|
|
|
$this->validate($request, [ |
|
91
|
|
|
'email' => 'required|email', |
|
92
|
|
|
'code' => 'required|numeric', |
|
93
|
|
|
'mobile' => 'required|numeric', |
|
94
|
|
|
]); |
|
95
|
|
|
$email = $request->oldemail; |
|
96
|
|
|
$newEmail = $request->newemail; |
|
97
|
|
|
$number = $request->oldnumber; |
|
98
|
|
|
$newNumber = $request->newnumber; |
|
99
|
|
|
User::where('email', $email)->update(['email'=>$newEmail, 'mobile'=>$newNumber]); |
|
100
|
|
|
|
|
101
|
|
|
try { |
|
102
|
|
|
$code = $request->input('code'); |
|
103
|
|
|
$mobile = $request->input('mobile'); |
|
104
|
|
|
$userid = $request->input('id'); |
|
105
|
|
|
$email = $request->input('email'); |
|
106
|
|
|
$pass = $request->input('password'); |
|
107
|
|
|
$number = $code.$mobile; |
|
108
|
|
|
|
|
109
|
|
|
$result = $this->sendOtp($mobile, $code); |
|
110
|
|
|
$method = 'POST'; |
|
111
|
|
|
|
|
112
|
|
|
$this->sendActivation($email, $method, $pass); |
|
|
|
|
|
|
113
|
|
|
$response = ['type' => 'success', 'message' => 'Activation link has been sent to '.$email.'.<br>OTP has been sent to '.$number.'.<br>Please enter the OTP received on your mobile No below. Incase you did not recieve OTP,please get in touch with us on <a href="mailto:[email protected]">[email protected]</a>']; |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
return response()->json($response); |
|
116
|
|
|
} catch (\Exception $ex) { |
|
117
|
|
|
$result = [$ex->getMessage()]; |
|
118
|
|
|
|
|
119
|
|
|
return response()->json(compact('result'), 500); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function sendActivation($email, $method, $str = '') |
|
124
|
|
|
{ |
|
125
|
|
|
try { |
|
126
|
|
|
$user = new User(); |
|
127
|
|
|
|
|
128
|
|
|
$activate_model = new AccountActivate(); |
|
|
|
|
|
|
129
|
|
|
$user = $user->where('email', $email)->first(); |
|
130
|
|
|
if (!$user) { |
|
131
|
|
|
return redirect()->back()->with('fails', 'Invalid Email'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if ($method == 'GET') { |
|
135
|
|
|
$activate_model = $activate_model->where('email', $email)->first(); |
|
|
|
|
|
|
136
|
|
|
$token = $activate_model->token; |
|
|
|
|
|
|
137
|
|
|
} else { |
|
138
|
|
|
$token = str_random(40); |
|
139
|
|
|
$activate = $activate_model->create(['email' => $email, 'token' => $token]); |
|
|
|
|
|
|
140
|
|
|
$token = $activate->token; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$url = url("activate/$token"); |
|
144
|
|
|
//check in the settings |
|
145
|
|
|
$settings = new \App\Model\Common\Setting(); |
|
146
|
|
|
$settings = $settings->where('id', 1)->first(); |
|
147
|
|
|
|
|
148
|
|
|
//template |
|
149
|
|
|
$template = new \App\Model\Common\Template(); |
|
150
|
|
|
$temp_id = $settings->where('id', 1)->first()->welcome_mail; |
|
|
|
|
|
|
151
|
|
|
$template = $template->where('id', $temp_id)->first(); |
|
|
|
|
|
|
152
|
|
|
$from = $settings->email; |
|
153
|
|
|
// var_dump($temp_id); |
|
154
|
|
|
// die(); |
|
155
|
|
|
$to = $user->email; |
|
|
|
|
|
|
156
|
|
|
$subject = $template->name; |
|
157
|
|
|
$data = $template->data; |
|
158
|
|
|
$replace = ['name' => $user->first_name.' '.$user->last_name, 'username' => $user->email, 'password' => $str, 'url' => $url]; |
|
|
|
|
|
|
159
|
|
|
$type = ''; |
|
160
|
|
|
|
|
161
|
|
View Code Duplication |
if ($template) { |
|
162
|
|
|
$type_id = $template->type; |
|
|
|
|
|
|
163
|
|
|
$temp_type = new \App\Model\Common\TemplateType(); |
|
|
|
|
|
|
164
|
|
|
$type = $temp_type->where('id', $type_id)->first()->name; |
|
|
|
|
|
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
//dd($from, $to, $data, $subject, $replace, $type); |
|
168
|
|
|
$templateController = new \App\Http\Controllers\Common\TemplateController(); |
|
169
|
|
|
$mail = $templateController->mailing($from, $to, $data, $subject, $replace, $type); |
|
170
|
|
|
|
|
171
|
|
|
return $mail; |
|
172
|
|
|
} catch (\Exception $ex) { |
|
173
|
|
|
throw new \Exception($ex->getMessage()); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Get the post register / login redirect path. |
|
179
|
|
|
* |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
|
|
public function redirectPath() |
|
183
|
|
|
{ |
|
184
|
|
|
if (\Session::has('session-url')) { |
|
185
|
|
|
$url = \Session::get('session-url'); |
|
186
|
|
|
|
|
187
|
|
|
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/'.$url; |
|
|
|
|
|
|
188
|
|
|
} else { |
|
189
|
|
|
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.