|
@ -5,6 +5,8 @@ namespace App\Http\Controllers; |
|
|
use App\Models\User; |
|
|
use App\Models\User; |
|
|
use App\Models\Business; |
|
|
use App\Models\Business; |
|
|
use App\Models\Fingerprint; |
|
|
use App\Models\Fingerprint; |
|
|
|
|
|
use App\Notifications\MailNotification; |
|
|
|
|
|
use Illuminate\Support\Facades\Notification; |
|
|
use Illuminate\Support\Str; |
|
|
use Illuminate\Support\Str; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Validation\Rule; |
|
|
use Illuminate\Validation\Rule; |
|
@ -15,6 +17,7 @@ use Illuminate\Support\Facades\Hash; |
|
|
use Illuminate\Support\Facades\Cache; |
|
|
use Illuminate\Support\Facades\Cache; |
|
|
use Laravel\Socialite\Facades\Socialite; |
|
|
use Laravel\Socialite\Facades\Socialite; |
|
|
use Illuminate\Session\TokenMismatchException; |
|
|
use Illuminate\Session\TokenMismatchException; |
|
|
|
|
|
use phpDocumentor\Reflection\Type; |
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
|
|
|
|
class AuthController extends Controller |
|
|
class AuthController extends Controller |
|
@ -94,7 +97,7 @@ class AuthController extends Controller |
|
|
|
|
|
|
|
|
$request->merge(['password' => Hash::make($request->password)]); |
|
|
$request->merge(['password' => Hash::make($request->password)]); |
|
|
|
|
|
|
|
|
$code_data = ['verification_code' => $this->sendVerificationCode()]; |
|
|
|
|
|
|
|
|
$code_data = ['verification_code' => $this->sendVerificationCode(\request('email'), 'register')]; |
|
|
$method_data = ['method' => 'registerMain']; |
|
|
$method_data = ['method' => 'registerMain']; |
|
|
|
|
|
|
|
|
Cache::put($request->email, $request->all() + $code_data + $method_data, 3600); // remain one hour
|
|
|
Cache::put($request->email, $request->all() + $code_data + $method_data, 3600); // remain one hour
|
|
@ -114,11 +117,16 @@ class AuthController extends Controller |
|
|
return $this->createFingerPrint(); |
|
|
return $this->createFingerPrint(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function sendVerificationCode($contact_way = null) |
|
|
|
|
|
|
|
|
public function sendVerificationCode($contact_way, $type) |
|
|
{ |
|
|
{ |
|
|
$verification_code = 1234; // rand(10001, 99999)
|
|
|
|
|
|
|
|
|
$verification_code = rand(10001, 99999); |
|
|
|
|
|
|
|
|
//send code for user with contact way
|
|
|
|
|
|
|
|
|
Notification::route('mail', $contact_way)->notify( new MailNotification([ |
|
|
|
|
|
'greeting' => __('notification.auth.verification.greeting'), |
|
|
|
|
|
'subject' => __('notification.auth.verification.subject'), |
|
|
|
|
|
'body' => __('notification.auth.verification.body', ['code' => $verification_code]), |
|
|
|
|
|
'link' => __('notification.auth.verification.link', ['email' => $contact_way, 'type' => $type]), |
|
|
|
|
|
])); |
|
|
|
|
|
|
|
|
return $verification_code; |
|
|
return $verification_code; |
|
|
} |
|
|
} |
|
@ -136,11 +144,18 @@ class AuthController extends Controller |
|
|
'verification_code' => 'required|string|min:4|max:4|in:'.$user_info['verification_code'] |
|
|
'verification_code' => 'required|string|min:4|max:4|in:'.$user_info['verification_code'] |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
Cache::forget($request->email); |
|
|
|
|
|
|
|
|
// Cache::forget($request->email);
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($user_info['method'])) { |
|
|
|
|
|
Cache::forget($request->email); |
|
|
|
|
|
return call_user_func('self::'.$user_info['method'], $user_info); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return isset($user_info['method']) ? |
|
|
|
|
|
call_user_func('self::'.$user_info['method'], $user_info) : |
|
|
|
|
|
\response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,); |
|
|
|
|
|
|
|
|
return \response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,); |
|
|
|
|
|
|
|
|
|
|
|
// return isset($user_info['method']) ?
|
|
|
|
|
|
// call_user_func('self::'.$user_info['method'], $user_info) :
|
|
|
|
|
|
// \response()->json(['message' => 'Code verified successfully.'], Response::HTTP_OK,);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function forgetPassword(Request $request) |
|
|
public function forgetPassword(Request $request) |
|
@ -149,7 +164,7 @@ class AuthController extends Controller |
|
|
'email' => 'required|email|exists:users,email' |
|
|
'email' => 'required|email|exists:users,email' |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
$code_data = ['verification_code' => $this->sendVerificationCode()]; |
|
|
|
|
|
|
|
|
$code_data = ['verification_code' => $this->sendVerificationCode(\request('email', 'forget'))]; |
|
|
|
|
|
|
|
|
Cache::put($request->email, $request->all() + $code_data, 3600); // remain one hour
|
|
|
Cache::put($request->email, $request->all() + $code_data, 3600); // remain one hour
|
|
|
|
|
|
|
|
@ -178,6 +193,8 @@ class AuthController extends Controller |
|
|
|
|
|
|
|
|
Auth::setUser($user); |
|
|
Auth::setUser($user); |
|
|
|
|
|
|
|
|
|
|
|
Cache::forget($request->email); |
|
|
|
|
|
|
|
|
return $this->createFingerPrint(); |
|
|
return $this->createFingerPrint(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|