Update user registration email format, remove unused SMS helper function, and adjust database migration for user meta column

This commit is contained in:
2025-09-22 16:50:01 +05:00
parent f14defeebd
commit baf23d4124
12 changed files with 264 additions and 30 deletions

BIN
app/.DS_Store vendored

Binary file not shown.

View File

@@ -40,7 +40,7 @@ class Register extends BaseRegister
protected function mutateFormDataBeforeRegister(array $data): array
{
$data['phone_number'] = str_replace(' ', '', $data['phone_number']);
$data['email'] = $data['phone_number'] . '@telekechi.com';
$data['email'] = $data['phone_number'].'@telekechi.com';
return $data;
}

View File

@@ -6,10 +6,8 @@ use App\Modules\ModuleContract;
use App\Modules\ModuleRepository;
use App\Modules\TurkmenNumberFormatter\Repositories\TurkmenNumberFormatter;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
/**
@@ -108,29 +106,3 @@ function moneyFormatInTurkmenLetter(int|float|string $money): string
{
return TurkmenNumberFormatter::format(floatval($money));
}
/**
* Send a sms
*/
function sendSMS(string|int $phone, string|int $message): mixed
{
$response = Http::retry(
times: 3,
sleepMilliseconds: 50,
throw: false,
when: function (Exception $exception, PendingRequest $request) {
Log::channel('sms_api_error')
->error('Exception: ', [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
]);
return true;
})
->post('http://216.250.14.144:3000/api/data', [
'phone' => '+993'.$phone,
'code' => $message,
]);
return $response->body();
}

BIN
app/Modules/.DS_Store vendored

Binary file not shown.

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Modules\OTPVerification\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class OTPVerificationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request): void
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): void
{
//
}
/**
* Display the specified resource.
*/
public function show(Request $request): void
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request): void
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request): void
{
//
}
}

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('otp_verifications', function (Blueprint $table) {
$table->id();
$table->string('username');
$table->string('code');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('otp_verifications');
}
};

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Modules\OTPVerification\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $username
* @property string $code
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class OTPVerification extends Model
{
/**
* The table associated with the model.
*/
protected $table = 'otp_verifications';
/**
* The attributes that are mass assignable.
*/
protected $fillable = ['username', 'code'];
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Modules\OTPVerification;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class OTPVerificationModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return true;
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Modules\OTPVerification\Repositories;
use App\Modules\OTPVerification\Models\OTPVerification;
use App\Modules\SMS\Repositories\SMSRepository;
class OTPVerificationRepository
{
/**
* Send a sms verification
*/
public static function sendSMSVerification(string|int $phone_number): ?OTPVerification
{
/* for apple testing */
$phone_code = ($phone_number == '61126667') ? 77777 : rand(10000, 99999);
$verification = OTPVerification::where(['username' => $phone_number])->first();
$verification
? $verification->update(['code' => $phone_code])
: OTPVerification::create(['username' => $phone_number, 'code' => $phone_code]);
SMSRepository::sendSMS($phone_number, 'Tassyklaýyş belgi: '.$phone_code);
return $verification;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Modules\SMS\Repositories;
use Exception;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class SMSRepository
{
/**
* Send a sms
*/
public static function sendSMS(string|int $phone, string|int $message): mixed
{
$response = Http::retry(
times: 3,
sleepMilliseconds: 50,
throw: false,
when: function (Exception $exception, PendingRequest $request) {
Log::error('Exception: ', [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
]);
return true;
})
->post('http://216.250.14.144:3000/api/data', [
'phone' => '+993'.$phone,
'code' => $message,
]);
return $response->body();
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Modules\SMS;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class SMSModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return true;
}
}