• Welcome to Autism Forums, a friendly forum to discuss Aspergers Syndrome, Autism, High Functioning Autism and related conditions.

    Your voice is missing! You will need to register to get access to the following site features:
    • Reply to discussions and create your own threads.
    • Our modern chat room. No add-ons or extensions required, just login and start chatting!
    • Private Member only forums for more serious discussions that you may wish to not have guests or search engines access to.
    • Your very own blog. Write about anything you like on your own individual blog.

    We hope to see you as a part of our community soon! Please also check us out @ https://www.twitter.com/aspiescentral

How to generate an otp from a link , compare the otp token with an otp token input from a post form and post form if conditions are met laravel.

PHOton

Member
0
i want to generate otp token when a link is clicked Request OTP and if the value entered by user in the form is the same as as the generated otp then check if total balance is greater than or equal to requsted amount, if all conditons are met then forward post form to database else throw error. Here is my view blade
<div>
<a href='/requestopt'> Request OTP</a>
</div>
<div class="mt-2 mb-4">
<h1 class="title1 text-dark">Fund Withdrawal</h1>
</div>

<div class="col-md-4">
<form method="POST" action="/verify_otp" >
@csrf
<div class="form-group">
<h5 class="text-dark">Source Account</h5>
<select class="form-control text-dark bg-light" name="payment">
<option value="btc">BitCOIN</option>
<option value="doge">DogeCOIN</option>
<option value="ltc">LiteCOIN</option>


</select>
</div>
<div class="form-group">
<h5 class="text-dark">Amount</h5>
<input type="text" name="amount" class="form-control text-dark bg-light" placeholder="Enter amount of btc" id="amount">
</div>
<div class="form-group">
<h5 class="text-dark">Enter Wallet Address</h5>
<input type="text" class="form-control text-dark bg-light" name ="cryptowlletaddr" placeholder="Enter Wall./Address" >
</div>
<div class="form-group">
<h5 class="text-dark">Enter OTP from Email!</h5>
<input type="text" name="OTP" class="form-control text-dark bg-light" placeholder="OTP">
</div>

<div class="form-group">
<span class="mb-1 ml-2 caption">
<span class="text-dark"><b>Processing Fees = 2%</b></span>
</span>
</div>

<div class="cta inline-group">
<button class="btn btn-success btn-block btn-sm" disbaled>
Withdraw!
</button>
</div>
</form>
</div>

Here is the route for the /requestotp
Route::any('/requestotp', 'TransactionController@requestotp');

Here is the route for verify_otp when withdraw! button is clicked
Route::post('verify_otp', 'TransactionController@verifyotp');

i have added OTP(uppercase) column to my users table Here is my crypto_transaction model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CrytoWithdrawal extends Model
{
use HasFactory;
protected $table= 'cryto_withdrawals';
protected $fillable = [
'payment',
'amount',
'cryptowlletaddr',
'OTP',
'user_id'
];
}

Here is my TransactionController
\```
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\USer;
use Validator;
use Exception;
use Log;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Mail;
use App\Mail\sendEmail;
use App\Models\crypto_tansaction;
use App\Models\cryto_payments;

class TransactionController extends Controller
{
public function requestotp(Request $request)
{

$otp = rand(1000,9999);
Log::info("otp = ".$otp);
$user = User::where('email','=',$request->email)->update(['otp' => $otp]);

if($user){
// send otp in the email
$mail_details = [
'subject' => 'Testing Application OTP',
'body' => 'Your OTP is : '. $otp
];

\Mail::to($request->email)->send(new sendEmail($mail_details));

return response(["status" => 200, "message" => "OTP sent successfully"]);
}
else{
return response(["status" => 401, 'message' => 'Invalid']);
}
}


public function verifyotp(Request $request){

$user = User::where([['email','=',$request->email],['otp','=',$request->otp]])->first()->User::where(['otp','=',$request->otp]) '=' cryto_transaction::where(['otp','=',$request->otp]);
$totalwithdrawal= CrytoWithdrawal::find(1)->sum('amount');
$totalamount= $amountpaid-$totalwithdrawal;
if($user){
$checkamount= $totalamount, '=', crypto_transaction::where(['amount', '=',$request->amount]);
if ($checkamount){
public function store(Request $request)
{
$withdraw = new crypto_transaction;
$withdraw->payment = $request->input('payment');
$withdraw->amount = $request->input('amount');
$withdraw->cryptowlletaddr = $request->input('cryptowlletaddr');
$withdraw->OTP = $request->input('OTP');
$withdraw->user_id = auth()->id();
$withdraw->save();
return redirect()->back()->with('status', 'Withdrawal Request Successfully Received');
}
}
else{
return response(["status" => 401, 'message' => 'Insufficient Amount']);
}

User::where('email','=',$request->email)->update(['otp' => null]);
$accessToken = auth()->user()->createToken('authToken')->accessToken;

return response(["status" => 200, "message" => "Success", 'user' => auth()->user(), 'access_token' => $accessToken]);
}
else{
return response(["status" => 401, 'message' => 'Invalid OPT token']);
}
}
}

Here is crypto_withdrawal table
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('crypto_withdrawals', function (Blueprint $table) {
$table->id();
$table->string('paymethod');
$table->string('amount');
$table->string('cryptowlletaddr');
$table->string('OTP');
$table->timestamps();
});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

Here is my crypto_payments model
use Victorybiz\LaravelCryptoPaymentGateway\Models\CryptoPaymentModel;

$cryptoPayment = CryptoPaymentModel::find($paymentID);

$cryptoPayment = CryptoPaymentModel::where('paymentID', $paymentID);

$processedCryptoPayment = CryptoPaymentModel::where('processed', true);

$amountpaid= CryptoPaymentModel::find(1)->sum('amount');

And here is my sendEmail
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class sendEmail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('view.name');
}
}

I followed the steps from this link Send OTP in the email using Laravel API - Sky Tech Bot and working with laravel framework 9 and use php version of 8.1 I could not even get the otp token to be generated in my users table and the email was never send and i dont even know how to correctly write the controller to verify the otp token generated and the otp input from form. If there is an easier way to achieve plz great minds help me out!
 

New Threads

Top Bottom