OTPVerificationController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Auth\Events\PasswordReset;
  5. use Auth;
  6. use Nexmo;
  7. use App\Models\OtpConfiguration;
  8. use App\Models\User;
  9. use App\Utility\SmsUtility;
  10. use Twilio\Rest\Client;
  11. use Hash;
  12. class OTPVerificationController extends Controller
  13. {
  14. /**
  15. * Display a listing of the resource.
  16. *
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function verification(Request $request){
  20. if (Auth::check() && Auth::user()->email_verified_at == null) {
  21. return view('otp_systems.frontend.user_verification');
  22. }
  23. else {
  24. flash('You have already verified your number')->warning();
  25. return redirect()->route('home');
  26. }
  27. }
  28. /**
  29. * @param \Illuminate\Http\Request $request
  30. * @param int $id
  31. * @return \Illuminate\Http\Response
  32. */
  33. public function verify_phone(Request $request){
  34. $user = Auth::user();
  35. if ($user->verification_code == $request->verification_code) {
  36. $user->email_verified_at = date('Y-m-d h:m:s');
  37. $user->save();
  38. flash('Your phone number has been verified successfully')->success();
  39. return redirect()->route('home');
  40. }
  41. else{
  42. flash('Invalid Code')->error();
  43. return back();
  44. }
  45. }
  46. /**
  47. * @param \Illuminate\Http\Request $request
  48. * @param int $id
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function resend_verificcation_code(Request $request){
  52. $user = Auth::user();
  53. $user->verification_code = rand(100000,999999);
  54. $user->save();
  55. SmsUtility::phone_number_verification($user);
  56. return back();
  57. }
  58. /**
  59. * @param \Illuminate\Http\Request $request
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function reset_password_with_code(Request $request){
  64. if (($user = User::where('phone', $request->phone)->where('verification_code', $request->code)->first()) != null) {
  65. if($request->password == $request->password_confirmation){
  66. $user->password = Hash::make($request->password);
  67. $user->email_verified_at = date('Y-m-d h:m:s');
  68. $user->save();
  69. event(new PasswordReset($user));
  70. auth()->login($user, true);
  71. if(auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff')
  72. {
  73. return redirect()->route('admin.dashboard');
  74. }
  75. return redirect()->route('home');
  76. }
  77. else {
  78. flash("Password and confirm password didn't match")->warning();
  79. return back();
  80. }
  81. }
  82. else {
  83. flash("Verification code mismatch")->error();
  84. return back();
  85. }
  86. }
  87. /**
  88. * @param User $user
  89. * @return void
  90. */
  91. public function send_code($user){
  92. SmsUtility::phone_number_verification($user);
  93. }
  94. /**
  95. * @param Order $order
  96. * @return void
  97. */
  98. public function send_order_code($order){
  99. $phone = json_decode($order->shipping_address)->phone;
  100. if($phone != null){
  101. SmsUtility::order_placement($phone, $order);
  102. }
  103. }
  104. /**
  105. * @param Order $order
  106. * @return void
  107. */
  108. public function send_delivery_status($order){
  109. $phone = json_decode($order->shipping_address)->phone;
  110. if($phone != null){
  111. SmsUtility::delivery_status_change($phone, $order);
  112. }
  113. }
  114. /**
  115. * @param Order $order
  116. * @return void
  117. */
  118. public function send_payment_status($order){
  119. $phone = json_decode($order->shipping_address)->phone;
  120. if($phone != null){
  121. SmsUtility::payment_status_change($phone, $order);
  122. }
  123. }
  124. }