otp
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\OtpToken;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class OtpController extends Controller
|
||||||
|
{
|
||||||
|
public function createOtp($nokp,Request $request){
|
||||||
|
|
||||||
|
$otp = OtpToken::on('mysql7')->create([
|
||||||
|
'nokp' => $nokp,
|
||||||
|
'expired' => $request->expired,
|
||||||
|
'token' => $request->otptoken,
|
||||||
|
'used'=> 0
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json($otp, 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOtp($nokp){
|
||||||
|
$current = Carbon::now();
|
||||||
|
$current = new Carbon();
|
||||||
|
|
||||||
|
$otp = OtpToken::on('mysql7')->where([['nokp','=',$nokp],['used','=',0],['expired','>=',$current]])->get();
|
||||||
|
|
||||||
|
return response()->json($otp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkToken($otp_token){
|
||||||
|
$current = Carbon::now();
|
||||||
|
$current = new Carbon();
|
||||||
|
|
||||||
|
$otp = OtpToken::on('mysql7')->where([['token','=',$otp_token],['used','=',0],['expired','>=',$current]])->get();
|
||||||
|
|
||||||
|
return response()->json($otp);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class OtpToken extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'otp_token';
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'nokp','token','used','expired'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes excluded from the model's JSON form.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
// protected $hidden = [];
|
||||||
|
}
|
||||||
@@ -113,4 +113,10 @@ $router->group(['prefix'=>'api'], function () use ($router){
|
|||||||
|
|
||||||
$router->get('transaksi_keuntungan/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukan']);
|
$router->get('transaksi_keuntungan/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukan']);
|
||||||
$router->post('transaksi_keuntungan',['uses'=>'TransaksiKeuntunganController@createTransaksiKeuntungan']);
|
$router->post('transaksi_keuntungan',['uses'=>'TransaksiKeuntunganController@createTransaksiKeuntungan']);
|
||||||
|
|
||||||
|
|
||||||
|
//OTP API
|
||||||
|
$router->post('otp/generateotp/{nokp}',['uses'=>'OtpController@createOtp']);
|
||||||
|
$router->get('otp/{nokp}',['uses'=>'OtpController@getOtp']);
|
||||||
|
$router->get('otp/check/{otp_token}',['uses'=>'OtpController@checkToken']);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user