two step verification module
This commit is contained in:
@@ -450,6 +450,34 @@ class AuthController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function enteredEmailOTP(Request $request)
|
||||
{
|
||||
// dd((int)$request->otp, Session::get('user-registration')['otp']);
|
||||
$validator = Validator::make($request->post(), [
|
||||
'otp' => 'required|min:4|max:4',
|
||||
// 'contact_number' => 'required|exists:users,contact_number|min:10|max:10'
|
||||
], [
|
||||
'required' => 'The :attribute field is required',
|
||||
// 'exists' => 'Contact Number has not been registered.',
|
||||
'min' => 'The :attribute field must be 4 digits',
|
||||
'max' => 'The :attribute field must be 4 digits',
|
||||
]);
|
||||
$validationMessage = $this->validationError($validator);
|
||||
if ($validationMessage) {
|
||||
return response()->json(['status' => 400, 'message' => $validationMessage], 400);
|
||||
}
|
||||
|
||||
$otp = (int)$request->otp;
|
||||
if (Session::has('user-registration')) {
|
||||
// $user = Session::get('user-registration');
|
||||
if (Session::get('user-registration')['otp'] == $otp) {
|
||||
return response()->json(['status' => 200, 'message' => 'OTP verified']);
|
||||
}
|
||||
return response()->json(['status' => 401, 'message' => 'Invalid OTP!']);
|
||||
}
|
||||
return response()->json(['status' => 401, 'message' => 'OTP Expired!']);
|
||||
}
|
||||
|
||||
public function signUp(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
@@ -505,14 +533,15 @@ class AuthController extends Controller
|
||||
]);
|
||||
if (!$userCreated) {
|
||||
return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400);
|
||||
}else{
|
||||
$user = User::where('email',$request->email)->first();
|
||||
} else {
|
||||
$user = User::where('email', $request->email)->first();
|
||||
$userToken = $user->createToken('apiToken')->plainTextToken;
|
||||
return response()->json(['status' => 200, 'message' => 'User Created','token' => $userToken,'data' => $user]);
|
||||
return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]);
|
||||
}
|
||||
} else {
|
||||
Session::forget('user-registration');
|
||||
$otp = $this->otpGenerate($request->email);
|
||||
$mobile_otp = $this->otpGenerate($request->contact_number);
|
||||
$userRegistration = [
|
||||
'name' => $request->name,
|
||||
'user_type' => 'Investor',
|
||||
@@ -520,7 +549,8 @@ class AuthController extends Controller
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
'contact_number' => $request->contact_number,
|
||||
'otp' => $otp
|
||||
'otp' => $otp,
|
||||
'mobile_otp' => $mobile_otp,
|
||||
];
|
||||
$userCreated = Session::put('user-registration', $userRegistration);
|
||||
$mailData = [
|
||||
@@ -528,6 +558,7 @@ class AuthController extends Controller
|
||||
'body' => 'This is for testing email using smtp.'
|
||||
];
|
||||
Mail::to($request->email)->send(new OtpMail($mailData, $otp));
|
||||
$this->thirdPartyOTP($request->contact_number,$mobile_otp);
|
||||
}
|
||||
// $name = $request->name;
|
||||
// $email = $request->email;
|
||||
@@ -561,14 +592,15 @@ class AuthController extends Controller
|
||||
]);
|
||||
if (!$userCreated) {
|
||||
return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400);
|
||||
}else{
|
||||
$user = User::where('email',$request->email2)->first();
|
||||
} else {
|
||||
$user = User::where('email', $request->email2)->first();
|
||||
$userToken = $user->createToken('apiToken')->plainTextToken;
|
||||
return response()->json(['status' => 200, 'message' => 'User Created','token' => $userToken,'data' => $user]);
|
||||
return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]);
|
||||
}
|
||||
} else {
|
||||
Session::forget('user-registration');
|
||||
$otp = $this->otpGenerate($request->email);
|
||||
$mobile_otp = $this->otpGenerate($validated['contact_number2']);
|
||||
$userRegistration = [
|
||||
'name' => $validated['name2'],
|
||||
'user_type' => 'Asset Manager',
|
||||
@@ -576,7 +608,8 @@ class AuthController extends Controller
|
||||
'email' => $validated['email2'],
|
||||
'contact_number' => $validated['contact_number2'],
|
||||
'password' => bcrypt($validated['password2']),
|
||||
'otp' => $otp
|
||||
'otp' => $otp,
|
||||
'mobile_otp' => $mobile_otp,
|
||||
];
|
||||
$userCreated = Session::put('user-registration', $userRegistration);
|
||||
$mailData = [
|
||||
@@ -584,6 +617,7 @@ class AuthController extends Controller
|
||||
'body' => 'This is for testing email using smtp.'
|
||||
];
|
||||
Mail::to($validated['email2'])->send(new OtpMail($mailData, $otp));
|
||||
$this->thirdPartyOTP($validated['contact_number2'],$mobile_otp);
|
||||
// Mail::to('yadavritikesh29@gmail.com')->send(new OtpMail($mailData, $otp));
|
||||
}
|
||||
// $name = $request->name;
|
||||
@@ -601,7 +635,8 @@ class AuthController extends Controller
|
||||
// return response()->json(['status' => 400, 'message' => 'Error creating user!'], 400);
|
||||
// }
|
||||
// $token = $userCreated->createToken('apiToken')->plainTextToken;
|
||||
return response()->json(['status' => 200, 'message' => 'User Created']);
|
||||
// return response()->json(['status' => 200, 'message' => 'User Created']);
|
||||
return response()->json(['status' => 200, 'message' => 'OTP has been sent to your email']);
|
||||
}
|
||||
|
||||
public function getUser(Request $request)
|
||||
@@ -716,7 +751,7 @@ class AuthController extends Controller
|
||||
$otp = (int)$request->otp;
|
||||
if (Session::has('user-registration')) {
|
||||
$userDetails = Session::get('user-registration');
|
||||
if ($userDetails['otp'] !== $otp) {
|
||||
if ($userDetails['mobile_otp'] !== $otp) {
|
||||
return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!']);
|
||||
}
|
||||
$userCreated = User::create([
|
||||
@@ -739,8 +774,9 @@ class AuthController extends Controller
|
||||
$data->notify(new UserAdmin($notify, $type));
|
||||
}
|
||||
|
||||
Auth::guard('users')->login($userCreated);
|
||||
// Auth::guard('users')->login($userCreated);
|
||||
return response()->json(['status' => 200, 'message' => 'OTP has been matched and User has been created!'], 200);
|
||||
// return response()->json(['status' => 200, 'message' => 'OTP has been matched'], 200);
|
||||
}
|
||||
|
||||
$checkOTP = User::where(['contact_number' => $request->contact_number, 'otp' => $request->otp])->first();
|
||||
@@ -860,7 +896,7 @@ class AuthController extends Controller
|
||||
]);
|
||||
|
||||
if ($insertOtp) {
|
||||
return response()->json(['message' => 'OTP Sent Succesfully', 'otp' => $otp,'status' => 200]);
|
||||
return response()->json(['message' => 'OTP Sent Succesfully', 'otp' => $otp, 'status' => 200]);
|
||||
}
|
||||
return response()->json(['message' => 'Error Sending OTP', 'status' => 400]);
|
||||
}
|
||||
@@ -887,7 +923,7 @@ class AuthController extends Controller
|
||||
}
|
||||
return response()->json(['status' => 200, 'message' => 'OTP has been matched!'], 200);
|
||||
}
|
||||
return response()->json(['message' => 'OTP Not Matched', 'status' => 400],400);
|
||||
return response()->json(['message' => 'OTP Not Matched', 'status' => 400], 400);
|
||||
}
|
||||
|
||||
public function forgotPasswordStepThree(Request $request)
|
||||
@@ -910,11 +946,11 @@ class AuthController extends Controller
|
||||
if ($validationMessage) {
|
||||
return response()->json(['status' => 400, 'message' => $validationMessage], 400);
|
||||
}
|
||||
|
||||
|
||||
$user = User::where(['contact_number' => $request->contact_number])->first();
|
||||
|
||||
if (Hash::check($request->password, $user->password)){
|
||||
return response()->json(['message' => 'New Password Cannot be Same as Old Password!', 'status' => 400],400);
|
||||
if (Hash::check($request->password, $user->password)) {
|
||||
return response()->json(['message' => 'New Password Cannot be Same as Old Password!', 'status' => 400], 400);
|
||||
}
|
||||
|
||||
$changePassword = User::where(['contact_number' => $request->contact_number])->update([
|
||||
|
||||
Reference in New Issue
Block a user