install
This commit is contained in:
78
app/Modules/BaseAuth/BaseAuthModule.php
Normal file
78
app/Modules/BaseAuth/BaseAuthModule.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class BaseAuthModule 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 false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer requirements
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::PACKAGE,
|
||||
name: 'laravel/ui',
|
||||
message: 'Required for authentication scaffolding.',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*/
|
||||
public function getComposerSuggestions(): array
|
||||
{
|
||||
return [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::MODULE,
|
||||
name: 'BaseLocale',
|
||||
message: 'Good for multiple language support.',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Modules/BaseAuth/Configs/base-auth-config.php
Normal file
22
app/Modules/BaseAuth/Configs/base-auth-config.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// Redirect path after login, register, reset password, etc.
|
||||
'redirect_path' => filament_path(),
|
||||
|
||||
// Default username, send from request and for validation, also db column
|
||||
'default_username' => 'username',
|
||||
|
||||
// If multiple usernames are supported for login, will be searched by user columns
|
||||
'multiple_usernames' => true,
|
||||
'usernames' => [
|
||||
'username',
|
||||
'phone',
|
||||
],
|
||||
|
||||
// If auth events should be stored
|
||||
'store_auth_events' => true,
|
||||
|
||||
// If sms verification is enabled, will be sent to the user
|
||||
'sms_verification' => true,
|
||||
];
|
||||
184
app/Modules/BaseAuth/Controllers/LoginController.php
Normal file
184
app/Modules/BaseAuth/Controllers/LoginController.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\BaseLocale\Middleware\SetLocale;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
use AuthenticatesUsers, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* Middleware
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$middleware = [];
|
||||
|
||||
if (module('BaseLocale')->isEnabled()) {
|
||||
array_push($middleware, SetLocale::class);
|
||||
}
|
||||
|
||||
$this->middleware($middleware)->except('logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the login username to be used by the controller, also send via request.
|
||||
*/
|
||||
public function username(): string
|
||||
{
|
||||
return config()->string('module.base-auth.default_username');
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports multiple usernames
|
||||
*/
|
||||
public function supportsMultipleUsernames(): bool
|
||||
{
|
||||
return config()->boolean('module.base-auth.multiple_usernames');
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports multiple usernames
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function usernames(): array
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
$usernames = config()->array('module.base-auth.usernames');
|
||||
|
||||
return $usernames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application's login form.
|
||||
*/
|
||||
public function showLoginForm(): View
|
||||
{
|
||||
return view('module.base-auth::pages.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has been authenticated.
|
||||
*/
|
||||
protected function authenticated(Request $request, User $user): JsonResponse|RedirectResponse
|
||||
{
|
||||
$redirect = redirect()->intended($this->redirectPath());
|
||||
|
||||
return $request->wantsJson()
|
||||
? new JsonResponse([
|
||||
'redirect' => $redirect->getTargetUrl(),
|
||||
], 200)
|
||||
: $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out of the application.
|
||||
*/
|
||||
public function logout(Request $request): RedirectResponse
|
||||
{
|
||||
$this->guard()->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
return redirect()->intended($this->redirectPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the post register / login redirect path.
|
||||
*/
|
||||
public function redirectPath(): string
|
||||
{
|
||||
return config()->string('module.base-auth.redirect_path');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the user login request.
|
||||
*
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
protected function validateLogin(Request $request): void
|
||||
{
|
||||
$request->validate([
|
||||
$this->username() => ['required', 'string', 'max:250'],
|
||||
'password' => ['required', 'string', 'max:250'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a login request to the application.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$this->validateLogin($request);
|
||||
|
||||
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||
// the login attempts for this application. We'll key this by the username and
|
||||
// the IP address of the client making these requests into this application.
|
||||
if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) {
|
||||
$this->fireLockoutEvent($request);
|
||||
|
||||
return $this->sendLockoutResponse($request);
|
||||
}
|
||||
|
||||
$user = User::query()
|
||||
->when($this->supportsMultipleUsernames(), function ($query) use ($request) {
|
||||
foreach ($this->usernames() as $username) {
|
||||
$query->orWhere($username, $request->username);
|
||||
}
|
||||
}, function ($query) use ($request) {
|
||||
$query->where($this->username(), $request->username);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (! $user) {
|
||||
return $this->sendFailedLoginResponse($request);
|
||||
}
|
||||
|
||||
if (Hash::check($request->string('password'), $user->password)) {
|
||||
Auth::login($user);
|
||||
|
||||
if ($request->hasSession()) {
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
}
|
||||
|
||||
return $this->sendLoginResponse($request);
|
||||
}
|
||||
|
||||
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||
// to login and redirect the user back to the login form. Of course, when this
|
||||
// user surpasses their maximum number of attempts they will get locked out.
|
||||
$this->incrementLoginAttempts($request);
|
||||
|
||||
return $this->sendFailedLoginResponse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the response after the user was authenticated.
|
||||
*/
|
||||
protected function sendLoginResponse(Request $request): RedirectResponse|JsonResponse
|
||||
{
|
||||
$request->session()->regenerate();
|
||||
|
||||
$this->clearLoginAttempts($request);
|
||||
|
||||
return $this->authenticated($request, $this->guard()->user()); // @phpstan-ignore-line
|
||||
}
|
||||
}
|
||||
173
app/Modules/BaseAuth/Controllers/RegisterController.php
Normal file
173
app/Modules/BaseAuth/Controllers/RegisterController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\System\Verification;
|
||||
use App\Models\User;
|
||||
use App\Modules\BaseAuth\Models\AuthEvent;
|
||||
use App\Modules\BaseLocale\Middleware\SetLocale;
|
||||
use App\Modules\OtpVerification\Rules\OtpVerificationRule;
|
||||
use App\Modules\PhoneNumberVerification\Rules\PhoneNumberVerificationRule;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Middleware
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$middleware = [];
|
||||
|
||||
if (module('BaseLocale')->isEnabled()) {
|
||||
array_push($middleware, SetLocale::class);
|
||||
}
|
||||
|
||||
$this->middleware($middleware)->except('logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show registration page
|
||||
*/
|
||||
public function showNovaRegisterpageForm(): View
|
||||
{
|
||||
return view('module.base-auth::pages.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
if ($request->has('phone')) {
|
||||
$request->merge([
|
||||
'phone' => unMaskTurkmenNumber($request->string('phone')),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->validator($request->all())->validate();
|
||||
|
||||
event(new Registered($user = $this->create($request->all())));
|
||||
|
||||
Auth::guard()->login($user);
|
||||
|
||||
if (config('module.base-auth.store_auth_events')) {
|
||||
storeAuthEvent(AuthEvent::REGISTER, $request);
|
||||
}
|
||||
|
||||
if (config('module.base-auth.sms_verification')) {
|
||||
sendSMSVerification((string) $user->phone);
|
||||
|
||||
return response()->json([
|
||||
'url' => route('sms-verification'),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'url' => config('module.base-auth.redirect_path'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array<string, int|string> $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'phone' => ['required', new PhoneNumberVerificationRule, 'unique:users,phone'],
|
||||
'username' => ['required', 'string', 'alpha_dash:ascii', 'max:255', 'unique:users,username'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array<string, int|string> $data
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
$user = User::create([
|
||||
'name' => $data['name'],
|
||||
'phone' => $data['phone'],
|
||||
'username' => $data['username'],
|
||||
'password' => Hash::make((string) $data['password']),
|
||||
'must_fill_profile' => true,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sms verification
|
||||
*/
|
||||
public function smsVerification(): View
|
||||
{
|
||||
return view('module.base-auth::pages.sms-verification', ['phone' => Auth::user()?->phone]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change users phone number
|
||||
*/
|
||||
public function changePhone(Request $request): JsonResponse
|
||||
{
|
||||
if ($request->has('phone')) {
|
||||
$request->merge(['phone' => unMaskTurkmenNumber($request->string('phone'))]);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'phone' => ['required', new PhoneNumberVerificationRule, 'unique:users,phone'],
|
||||
]);
|
||||
|
||||
/** @var User */
|
||||
$user = Auth::user();
|
||||
|
||||
$user->update([
|
||||
'phone' => $request->phone,
|
||||
]);
|
||||
|
||||
storeAuthEvent(AuthEvent::PHONE_CHANGED, $request);
|
||||
|
||||
sendSMSVerification((string) $user->phone);
|
||||
|
||||
return response()->json([
|
||||
'url' => route('sms-verification'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify sms code
|
||||
*/
|
||||
public function verifySmsCode(Request $request): RedirectResponse
|
||||
{
|
||||
/** @var User */
|
||||
$user = Auth::user();
|
||||
|
||||
$request->validate([
|
||||
'code' => ['bail', 'required', 'integer', new OtpVerificationRule($user->phone)],
|
||||
]);
|
||||
|
||||
$user->update([
|
||||
'phone_verified_at' => now(),
|
||||
]);
|
||||
|
||||
storeAuthEvent(AuthEvent::PHONE_VERIFICATION, $request);
|
||||
|
||||
return redirect(config()->string('module.base-auth.redirect_path'));
|
||||
}
|
||||
}
|
||||
110
app/Modules/BaseAuth/Controllers/ResetPasswordController.php
Normal file
110
app/Modules/BaseAuth/Controllers/ResetPasswordController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\System\Verification;
|
||||
use App\Models\User;
|
||||
use App\Modules\BaseAuth\Models\AuthEvent;
|
||||
use App\Modules\OtpVerification\Models\OtpVerification;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Reset password page
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('module.base-auth::pages.reset-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new password
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => ['required', 'string', 'max:250', 'exists:users,username'],
|
||||
'verification' => ['nullable', 'integer', Rule::requiredIf(fn () => $request->filled('step-verification'))],
|
||||
'step-sms' => ['nullable'],
|
||||
'step-verification' => ['nullable'],
|
||||
'step-password' => ['nullable'],
|
||||
'password' => ['bail', 'nullable', 'string', 'min:8', 'confirmed', Rule::requiredIf(fn () => $request->filled('step-password'))],
|
||||
]);
|
||||
|
||||
/** @var User */
|
||||
$user = User::where('username', $request->username)->first();
|
||||
|
||||
if ($request->filled('step-sms') && $request->isNotFilled('step-verification') && $request->isNotFilled('step-password')) {
|
||||
return $this->sendVerification($request, $user);
|
||||
}
|
||||
|
||||
if ($request->filled('step-verification') && $request->isNotFilled('step-password')) {
|
||||
return $this->verify($request, $user);
|
||||
}
|
||||
|
||||
if ($request->filled('step-password')) {
|
||||
return $this->updatePassword($request, $user);
|
||||
}
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send verification code
|
||||
*/
|
||||
public function sendVerification(Request $request, User $user): JsonResponse
|
||||
{
|
||||
sendSMSVerification((string) $user->phone);
|
||||
|
||||
return response()->json([
|
||||
'step' => 1,
|
||||
'message' => __('We send you a verification code to').' ****'.substr((string) $user->phone, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify phone number
|
||||
*/
|
||||
public function verify(Request $request, User $user): JsonResponse
|
||||
{
|
||||
$verification = OtpVerification::where('username', $user->phone)
|
||||
->where('code', $request->verification)
|
||||
->first();
|
||||
|
||||
if (! $verification) {
|
||||
return response()->json([
|
||||
'errors' => [
|
||||
'verification' => [
|
||||
__('Incorrect verification code'),
|
||||
],
|
||||
],
|
||||
'message' => __('Incorrect verification code'),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'step' => 2,
|
||||
'message' => __("Now you can set your password, but please make sure that you don't forget it!"),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update password
|
||||
*/
|
||||
public function updatePassword(Request $request, User $user): JsonResponse
|
||||
{
|
||||
$user->update(['password' => bcrypt($request->string('password'))]);
|
||||
|
||||
storeAuthEvent(AuthEvent::PASSWORD_RESET, request());
|
||||
|
||||
return response()->json([
|
||||
'step' => 3,
|
||||
'message' => __('Your password has been updated'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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('auth_events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name')->index();
|
||||
$table->string('request_method')->index();
|
||||
$table->string('ip')->nullable()->index();
|
||||
$table->string('user_agent')->nullable()->index();
|
||||
$table->string('target_url')->nullable()->index();
|
||||
$table->json('options')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('auth_events');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfUserPhoneIsUnVerfied
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (Auth::check() && is_null($request->user()?->phone_verified_at)) {
|
||||
return redirect()->route('sms-verification');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfUserPhoneIsVerfied
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (Auth::check() && ! is_null($request->user()?->phone_verified_at)) {
|
||||
return redirect()->route(config()->string('module.base-auth.redirect_path'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
111
app/Modules/BaseAuth/Models/AuthEvent.php
Normal file
111
app/Modules/BaseAuth/Models/AuthEvent.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\BaseAuth\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $request_method
|
||||
* @property string|null $ip
|
||||
* @property string|null $user_agent
|
||||
* @property string|null $target_url
|
||||
* @property string|null $options
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*/
|
||||
class AuthEvent extends Model
|
||||
{
|
||||
protected $table = 'auth_events';
|
||||
|
||||
/**
|
||||
* When user registers to application
|
||||
*/
|
||||
public const REGISTER = 'REGISTER';
|
||||
|
||||
/**
|
||||
* When user logs into application
|
||||
*/
|
||||
public const LOGIN = 'LOGIN';
|
||||
|
||||
/**
|
||||
* When user verifies phone number
|
||||
*/
|
||||
public const PHONE_VERIFICATION = 'PHONE_VERIFICATION';
|
||||
|
||||
/**
|
||||
* When user verifies phone number
|
||||
*/
|
||||
public const PHONE_CHANGED = 'PHONE_CHANGED';
|
||||
|
||||
/**
|
||||
* When user logs out of application
|
||||
*/
|
||||
public const LOGOUT = 'LOGOUT';
|
||||
|
||||
/**
|
||||
* When user resets password
|
||||
*/
|
||||
public const PASSWORD_RESET = 'PASSWORD_RESET';
|
||||
|
||||
/**
|
||||
* When user resets password
|
||||
*/
|
||||
public const FAILED = 'FAILED';
|
||||
|
||||
/**
|
||||
* When user resets password
|
||||
*/
|
||||
public const ATTEMPTING = 'ATTEMPTING';
|
||||
|
||||
/**
|
||||
* When user resets password
|
||||
*/
|
||||
public const LOCKOUT = 'LOCKOUT';
|
||||
|
||||
/**
|
||||
* Laravel's default events
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function laravelDefaultEvents(): array
|
||||
{
|
||||
return [
|
||||
'Illuminate\\Auth\\Events\\Attempting' => self::ATTEMPTING,
|
||||
'Illuminate\\Auth\\Events\\Failed' => self::FAILED,
|
||||
'Illuminate\\Auth\\Events\\Lockout' => self::LOCKOUT,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest the event
|
||||
*/
|
||||
public static function guessEvent(string|object $event): string
|
||||
{
|
||||
if (is_object($event)) {
|
||||
$event = get_class($event);
|
||||
}
|
||||
|
||||
return self::laravelDefaultEvents()[$event] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Log type
|
||||
*/
|
||||
public static function logType(string $name): string
|
||||
{
|
||||
return match ($name) {
|
||||
self::REGISTER => 'notice',
|
||||
self::LOGIN => 'notice',
|
||||
self::PHONE_VERIFICATION => 'info',
|
||||
self::LOGOUT => 'notice',
|
||||
self::PASSWORD_RESET => 'info',
|
||||
self::FAILED => 'warning',
|
||||
self::ATTEMPTING => 'alert',
|
||||
self::LOCKOUT => 'alert',
|
||||
default => 'info',
|
||||
};
|
||||
}
|
||||
}
|
||||
16
app/Modules/BaseAuth/Resources/Lang/en/base.php
Normal file
16
app/Modules/BaseAuth/Resources/Lang/en/base.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'online_panel' => 'Online panel',
|
||||
'login' => 'Login',
|
||||
'register' => 'Register',
|
||||
'reset_password' => 'Reset password',
|
||||
'help' => 'Help',
|
||||
'privacy_policy' => 'Privacy policy',
|
||||
'phone' => 'Phone',
|
||||
'username' => 'Username',
|
||||
'or' => 'or',
|
||||
'continue' => 'Continue',
|
||||
'successfully_logged_in' => 'Successfully logged in',
|
||||
'press_continue' => 'Press continue',
|
||||
];
|
||||
5
app/Modules/BaseAuth/Resources/Lang/ru/base.php
Normal file
5
app/Modules/BaseAuth/Resources/Lang/ru/base.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
32
app/Modules/BaseAuth/Resources/Lang/tk/base.php
Normal file
32
app/Modules/BaseAuth/Resources/Lang/tk/base.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'online_panel' => 'Onlaýn kabulhana',
|
||||
'login' => 'Giriş',
|
||||
'register' => 'Agza bolmak',
|
||||
'reset_password' => 'Açar sözüni ýatdan çykardyňyzmy?',
|
||||
'help' => 'Kömek',
|
||||
'privacy_policy' => 'Gizlinlik syýasaty',
|
||||
'phone' => 'Telefon',
|
||||
'username' => 'ulanyjy ady',
|
||||
'password' => 'Açar sözi',
|
||||
'or' => 'ýada',
|
||||
'continue' => 'Dowam etmek',
|
||||
'successfully_logged_in' => 'Üstünlik bilen girdiňiz',
|
||||
'press_continue' => 'Dowam etmek düwme basyň',
|
||||
'please_wait_while_we_redirect_you_to_your_personal_account' => 'Şahsy hasabyňyza geçýänçä garaşyň',
|
||||
'forgot_your_password' => 'Açar sözüni unutdyňyzmy?',
|
||||
'successfully_registered' => 'Üstünlikli hasaba alyndyňyz',
|
||||
'please_now_verify_your_phone_number_to_continue' => 'Dowam etmek üçin telefon belgiňizi tassyklaň',
|
||||
'go_to_login_page' => 'Giriş sahypasyyna geçiň',
|
||||
'full_name' => 'Adyňyz',
|
||||
'confirm_password' => 'Açar sözi tassyklaňyz',
|
||||
'verify_phone_number' => 'Telefon beligiňizi tassyklaň',
|
||||
'verification_code' => 'Tassyklaýyş belgi',
|
||||
'submit' => 'Tassyklamak',
|
||||
'verification_code_has_been_send_to_number' => 'Tassyklaýyş belgi telefon belgisine ugradyldy',
|
||||
'change_number' => 'Üýtget',
|
||||
'change_phone_label' => 'Telefon belgini üýtgetmek',
|
||||
'go_back' => 'Yza',
|
||||
'successfully_changed_phone' => 'Telefon belgiňiz üýtgedildi',
|
||||
];
|
||||
@@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ app()->getLocale() }}" dir="ltr" class="h-full font-sans antialiased">
|
||||
<head>
|
||||
<meta name="theme-color" content="#fff">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width"/>
|
||||
<meta name="locale" content="tk"/>
|
||||
<meta name="robots" content="noindex">
|
||||
|
||||
<link rel="shortcut icon" href="/favicon.png" type="image/png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
|
||||
|
||||
<!-- Styles -->
|
||||
<link rel="stylesheet" href="/assets/css/auth-layout.css">
|
||||
<link rel="stylesheet" href="/assets/css/auth.css">
|
||||
<link rel="stylesheet" href="/assets/css/cookieconsent.css">
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div class="bg-white flex justify-between px-4 py-1 absolute w-full shadow-none shadow-lg">
|
||||
<div class="px-8 text-sm p-1 rounded uppercase font-bold padding-none">
|
||||
<a href="#" class="d-none-copyright"> “Türkmenbaşy” PTB © </a>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<a href="tel:+99312444234" class="mr-6 text-sm text-gray-900">(+99312) 44-42-34</a>
|
||||
<a href="#" class="mr-6 text-sm text-gray-900 uppercase">{{ __('module.base-auth::base.help') }}</a>
|
||||
|
||||
<div class="flex text-sm text-gray-90a0 space-x-1 uppercase">
|
||||
@if (module('BaseLocale')->isEnabled())
|
||||
@foreach(baseLocales() as $localeKey => $localeDisplayName)
|
||||
<a
|
||||
href="{{ route('module.base-locale.set-locale', ['locale' => $localeKey]) }}"
|
||||
class="{{ app()->getLocale() === $localeKey ? 'font-bold' : '' }}"
|
||||
>
|
||||
{{ $localeKey }}
|
||||
|
||||
@unless($loop->last)
|
||||
|
|
||||
@endif
|
||||
</a>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="login-section d-center items-center h-screen">
|
||||
<div class="d-none h-full max-w-4xl">
|
||||
<img src="/assets/images/bank-img.PNG" class="h-full object-cover">
|
||||
</div>
|
||||
|
||||
<div class="relative">
|
||||
@yield('content')
|
||||
|
||||
<div class="text-center relative" style="top: 4em;">
|
||||
<a href="/privacy-policy.pdf" class="text-gray-500 font-bold text-underline" target="_blank">
|
||||
{{ __('module.base-auth::base.privacy_policy') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/inputmask.min.js"></script>
|
||||
<script src="/assets/js/sweetalert2.js"></script>
|
||||
|
||||
<script src="/assets/js/cookieconsent.js"></script>
|
||||
<script src="/assets/js/fn.js"></script>
|
||||
<script src="/assets/js/app.js"></script>
|
||||
|
||||
@stack('js')
|
||||
</body>
|
||||
</html>
|
||||
|
||||
88
app/Modules/BaseAuth/Resources/Views/pages/login.blade.php
Normal file
88
app/Modules/BaseAuth/Resources/Views/pages/login.blade.php
Normal file
@@ -0,0 +1,88 @@
|
||||
@extends('module.base-auth::layouts.auth-layout')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
async function login(event) {
|
||||
const response = await postData(event.target.action, getFormData(event))
|
||||
|
||||
console.log(response)
|
||||
|
||||
if (response.errors) {
|
||||
loopObject(response.errors, item => addValidationClasses(item))
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
removeValidationClasess()
|
||||
|
||||
await Swal.fire({
|
||||
title: '{{ __('module.base-auth::base.successfully_logged_in') }}',
|
||||
text: '{{ __('module.base-auth::base.press_continue') }}',
|
||||
confirmButtonText: '{{ __('module.base-auth::base.continue') }}',
|
||||
icon: 'success',
|
||||
showDenyButton: false,
|
||||
showCancelButton: false,
|
||||
})
|
||||
|
||||
window.location.href = '{{ route('login') }}'
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('login') }}"
|
||||
onsubmit="event.preventDefault();login(event)"
|
||||
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto"
|
||||
>
|
||||
@csrf
|
||||
<h2 class="text-2xl text-center font-normal mb-6 uppercase">{{ __('module.base-auth::base.online_panel') }}</h2>
|
||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
||||
</svg>
|
||||
<div class="mb-6">
|
||||
<label class="block mb-2" for="username">
|
||||
{{ __('module.base-auth::base.phone') }} {{ __('module.base-auth::base.or') }} <span class="lowecase">{{ __('module.base-auth::base.username') }}</span>
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="username"
|
||||
type="text"
|
||||
name="username"
|
||||
placeholder="+99365999990 {{ __('or') }} {{ __('module.base-auth::base.username') }}"
|
||||
autofocus=""
|
||||
value="{{ old('username') }}"
|
||||
>
|
||||
|
||||
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<label class="block mb-2" for="password">
|
||||
{{ __('module.base-auth::base.password') }}
|
||||
</label>
|
||||
<input
|
||||
class="form-control form-input form-input-bordered w-full"
|
||||
id="password"
|
||||
type="password"
|
||||
name="password"
|
||||
>
|
||||
|
||||
<span id="password-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
|
||||
</div>
|
||||
<div class="flex mb-6">
|
||||
<div class="ml-auto">
|
||||
<a href="{{ route('reset-password') }}" class="text-gray-500 font-bold no-underline">
|
||||
{{ __('module.base-auth::base.forgot_your_password') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
|
||||
<span class=""><span>{{ __('module.base-auth::base.login') }}</span></span>
|
||||
</button>
|
||||
<a href="{{ route('register') }}" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
|
||||
<span class=""><span>{{ __('module.base-auth::base.register') }}</span></span>
|
||||
</a>
|
||||
</form>
|
||||
@stop
|
||||
124
app/Modules/BaseAuth/Resources/Views/pages/register.blade.php
Normal file
124
app/Modules/BaseAuth/Resources/Views/pages/register.blade.php
Normal file
@@ -0,0 +1,124 @@
|
||||
@extends('module.base-auth::layouts.auth-layout')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
async function register(event) {
|
||||
const response = await postData(event.target.action, getFormData(event))
|
||||
|
||||
if (response.errors) {
|
||||
loopObject(response.errors, item => addValidationClasses(item))
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
removeValidationClasess()
|
||||
|
||||
console.log(response)
|
||||
|
||||
await Swal.fire({
|
||||
title: '{{ __('module.base-auth::base.successfully_registered') }}',
|
||||
text: '{{ __('module.base-auth::base.please_now_verify_your_phone_number_to_continue') }}',
|
||||
icon: 'success',
|
||||
showDenyButton: false,
|
||||
showCancelButton: false,
|
||||
})
|
||||
|
||||
window.location.href = response.url;
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<form
|
||||
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto mt-1"
|
||||
method="POST"
|
||||
action="{{ route('register') }}"
|
||||
onsubmit="event.preventDefault();register(event)"
|
||||
>
|
||||
@csrf
|
||||
<h2 class="text-2xl text-center font-normal mb-6">{{ __('module.base-auth::base.online_panel') }}</h2>
|
||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
||||
</svg>
|
||||
<div class="mb-1">
|
||||
<label class="block mb-1" for="name">
|
||||
{{ __('module.base-auth::base.full_name') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="name"
|
||||
type="text"
|
||||
name="name"
|
||||
autofocus=""
|
||||
value="{{ old('name') }}"
|
||||
>
|
||||
|
||||
<span id="name-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<label class="block mb-1" for="phone">
|
||||
{{ __('module.base-auth::base.phone') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="phone"
|
||||
type="text"
|
||||
name="phone"
|
||||
autofocus=""
|
||||
value="{{ old('phone') }}"
|
||||
>
|
||||
|
||||
<span id="phone-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<label class="block mb-1" for="username">
|
||||
{{ ucfirst(__('module.base-auth::base.username')) }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="username"
|
||||
type="text"
|
||||
name="username"
|
||||
autofocus=""
|
||||
value="{{ old('username') }}"
|
||||
>
|
||||
|
||||
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<label class="block mb-1" for="password">
|
||||
{{ __('module.base-auth::base.password') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="password"
|
||||
type="password"
|
||||
name="password"
|
||||
>
|
||||
|
||||
<span id="password-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<label class="block mb-1" for="password_confirmation">
|
||||
{{ __('module.base-auth::base.confirm_password') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full"
|
||||
id="password_confirmation"
|
||||
type="password"
|
||||
name="password_confirmation"
|
||||
>
|
||||
|
||||
<span id="password_confirmation-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<div class="mb-6"></div>
|
||||
<button
|
||||
class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center"
|
||||
type="submit"
|
||||
>
|
||||
<span class=""><span>{{ __('module.base-auth::base.register') }}</span></span>
|
||||
</button>
|
||||
|
||||
<a
|
||||
href="{{ route('login') }}"
|
||||
class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center"
|
||||
>
|
||||
<span class=""><span>{{ __('module.base-auth::base.go_to_login_page') }}</span></span>
|
||||
</a>
|
||||
</form>
|
||||
@stop
|
||||
@@ -0,0 +1,104 @@
|
||||
@extends('module.base-auth::layouts.auth-layout')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
async function resetPassword(event) {
|
||||
const response = await postData(event.target.action, getFormData(event))
|
||||
|
||||
if (response.errors) {
|
||||
loopObject(response.errors, item => addValidationClasses(item))
|
||||
} else {
|
||||
removeValidationClasess()
|
||||
|
||||
if (response.step === 1) {
|
||||
showVerificationCodeBox()
|
||||
|
||||
Swal.fire({
|
||||
title: '{{ __('Verification code') }}',
|
||||
text: response.message,
|
||||
icon: 'info'
|
||||
})
|
||||
}
|
||||
|
||||
if (response.step === 2) {
|
||||
showPasswordBox()
|
||||
|
||||
Swal.fire({
|
||||
title: '{{ __('Reset Password') }}',
|
||||
text: response.message,
|
||||
icon: 'warning'
|
||||
})
|
||||
}
|
||||
|
||||
if (response.step === 3) {
|
||||
await Swal.fire({
|
||||
title: response.message,
|
||||
showDenyButton: false,
|
||||
showCancelButton: false,
|
||||
})
|
||||
|
||||
window.location.href = '{{ route('login') }}'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('reset-password') }}"
|
||||
onsubmit="event.preventDefault();resetPassword(event)"
|
||||
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto"
|
||||
>
|
||||
@csrf
|
||||
|
||||
<h2 class="text-2xl text-center font-normal mb-6">{{ __('Enter your username to continue') }}</h2>
|
||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
||||
</svg>
|
||||
|
||||
<div id="username-box" class="mb-6">
|
||||
<label class="block mb-2" for="username">
|
||||
{{ __('Username') }}
|
||||
</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
name="username"
|
||||
class="form-control form-input form-input-bordered w-full"
|
||||
autofocus=""
|
||||
>
|
||||
<input type="hidden" name="step-sms" value="1">
|
||||
|
||||
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 hidden" id="verification-code-box">
|
||||
<label class="block mb-2" for="verification">
|
||||
{{ __('Verification code') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="hidden" id="reset-password-container">
|
||||
<div class="mb-6" id="password-box">
|
||||
<label class="block mb-2" for="password">
|
||||
{{ __('Password') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mb-6" id="password-confirm-box">
|
||||
<label class="block mb-2" for="password_confirmation">
|
||||
{{ __('Confirm Password') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
|
||||
<span class=""><span>{{ __('Submit') }}</span></span>
|
||||
</button>
|
||||
<a href="{{ route('register') }}" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
|
||||
<span class=""><span>{{ __('Go to login page') }}</span></span>
|
||||
</a>
|
||||
</form>
|
||||
@stop
|
||||
@@ -0,0 +1,145 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="tk" dir="ltr" class="h-full font-sans antialiased">
|
||||
<head>
|
||||
<meta name="theme-color" content="#fff">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width"/>
|
||||
<meta name="locale" content="tk"/>
|
||||
<meta name="robots" content="noindex">
|
||||
|
||||
<!-- Styles -->
|
||||
<link rel="stylesheet" href="/assets/css/auth-layout.css">
|
||||
<style>
|
||||
.bg-secondary-500 {
|
||||
background-color: rgb(186,230,253);
|
||||
}
|
||||
.hover:bg-secondary-400 {
|
||||
background-color: rgba(24, 182, 155, 0.5);
|
||||
}
|
||||
.underline {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.d-none {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="min-w-site text-sm font-medium min-h-full text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-900">
|
||||
<div class="py-6 px-1 md:px-2 lg:px-6">
|
||||
<div class="mx-auto py-8 max-w-sm flex justify-center">
|
||||
<span class="uppercase text-4xl">{{ __('module.base-auth::base.online_panel') }}</span>
|
||||
</div>
|
||||
<div class="bg-white dark:bg-gray-800 shadow rounded-lg p-8 max-w-[25rem] mx-auto">
|
||||
|
||||
<h2 class="text-2xl text-center font-normal mb-6">{{ __('module.base-auth::base.verify_phone_number') }}</h2>
|
||||
|
||||
<div class="flex justify-center items-center mb-6">
|
||||
<h2 class="text-lg text-center font-normal mr-4">+993 {{ $phone }}</h2>
|
||||
|
||||
<span href="#" class="underline cursor-pointer" onclick="showChangePhone()" id="change-phone-button">
|
||||
{{ __('module.base-auth::base.change_number') }}
|
||||
</span>
|
||||
|
||||
<span href="#" class="underline cursor-pointer d-none" onclick="goBack()" id="go-back-button">
|
||||
{{ __('module.base-auth::base.go_back') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{{-- Border line --}}
|
||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
||||
</svg>
|
||||
|
||||
{{-- Change phone form --}}
|
||||
<form method="POST" action="{{ route('change-phone') }}" id="change-phone-form" class="d-none" onsubmit="event.preventDefault();changePhone(event)">
|
||||
@csrf
|
||||
<div class="mb-6">
|
||||
<label class="block mb-2" for="phone">
|
||||
{{ __('module.base-auth::base.change_phone_label') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full" id="phone" type="text" name="phone" required="">
|
||||
|
||||
<span id="phone-error-box" class="text-red-500 text-italic error-box"></span>
|
||||
</div>
|
||||
<button type="submit" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
|
||||
<span class=""><span>{{ __('module.base-auth::base.change_number') }}</span></span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{{-- Verification form --}}
|
||||
<form method="POST" action="{{ route('sms-verification') }}" id="verification-form">
|
||||
@csrf
|
||||
<div class="mb-6">
|
||||
<label class="block mb-2" for="code">
|
||||
{{ __('module.base-auth::base.verification_code') }}
|
||||
</label>
|
||||
<input class="form-control form-input form-input-bordered w-full" id="code" type="number" name="code" required="">
|
||||
|
||||
@if($errors->any())
|
||||
@foreach($errors->all() as $error)
|
||||
<p class="mt-2 text-red-500">{{ $error }}</p>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
<button type="submit" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
|
||||
<span class=""><span>{{ __('module.base-auth::base.submit') }}</span></span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/inputmask.min.js"></script>
|
||||
<script src="/assets/js/sweetalert2.js"></script>
|
||||
<script src="/assets/js/fn.js"></script>
|
||||
<script>
|
||||
|
||||
let phoneField = $_ID('phone')
|
||||
let changePhoneform = $_ID('change-phone-form')
|
||||
let verificationForm = $_ID('verification-form')
|
||||
let changePhoneButton = $_ID('change-phone-button')
|
||||
let goBackButton = $_ID('go-back-button')
|
||||
|
||||
ready(() => {
|
||||
new Inputmask("+(\\9\\93)-99-99-99-99").mask(phoneField);
|
||||
})
|
||||
|
||||
async function goBack() {
|
||||
hide(changePhoneform)
|
||||
show(changePhoneButton)
|
||||
|
||||
hide(goBackButton)
|
||||
show(verificationForm)
|
||||
}
|
||||
|
||||
function showChangePhone() {
|
||||
show(changePhoneform)
|
||||
hide(changePhoneButton)
|
||||
|
||||
show(goBackButton)
|
||||
hide(verificationForm)
|
||||
}
|
||||
|
||||
async function changePhone(event) {
|
||||
const response = await postData(event.target.action, getFormData(event))
|
||||
|
||||
if (response.errors) {
|
||||
loopObject(response.errors, item => addValidationClasses(item))
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
removeValidationClasess()
|
||||
|
||||
await Swal.fire({
|
||||
title: '{{ __('module.base-auth::base.successfully_changed_phone') }}',
|
||||
text: '{{ __('module.base-auth::base.please_now_verify_your_phone_number_to_continue') }}',
|
||||
icon: 'success',
|
||||
showDenyButton: false,
|
||||
showCancelButton: false,
|
||||
})
|
||||
|
||||
window.location.href = response.url;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
28
app/Modules/BaseAuth/Routes/base-auth-routes.php
Normal file
28
app/Modules/BaseAuth/Routes/base-auth-routes.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\BaseAuth\Controllers\LoginController;
|
||||
use App\Modules\BaseAuth\Controllers\RegisterController;
|
||||
use App\Modules\BaseAuth\Controllers\ResetPasswordController;
|
||||
use App\Modules\BaseAuth\Middleware\RedirectIfUserPhoneIsVerfied;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['web', 'guest'])->group(function () {
|
||||
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
|
||||
Route::post('/login', [LoginController::class, 'login']);
|
||||
|
||||
Route::get('/register', [RegisterController::class, 'showNovaRegisterpageForm'])->name('register');
|
||||
Route::post('/register', [RegisterController::class, 'register']);
|
||||
|
||||
Route::get('reset-password', [ResetPasswordController::class, 'index'])->name('reset-password');
|
||||
Route::post('reset-password', [ResetPasswordController::class, 'store']);
|
||||
});
|
||||
|
||||
Route::middleware(['web', 'auth', RedirectIfUserPhoneIsVerfied::class])->group(function () {
|
||||
Route::post('change-phone', [RegisterController::class, 'changePhone'])->name('change-phone');
|
||||
|
||||
Route::get('sms-verification', [RegisterController::class, 'smsVerification'])
|
||||
->name('sms-verification');
|
||||
|
||||
Route::post('sms-verification', [RegisterController::class, 'verifySmsCode']);
|
||||
|
||||
});
|
||||
48
app/Modules/BaseAuth/base-auth-helpers.php
Normal file
48
app/Modules/BaseAuth/base-auth-helpers.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\BaseAuth\Models\AuthEvent;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Store auth event
|
||||
*/
|
||||
function storeAuthEvent(string $name, Request $request): void
|
||||
{
|
||||
try {
|
||||
AuthEvent::create([
|
||||
'name' => $name,
|
||||
'request_method' => $request->method(),
|
||||
'ip' => $request->ip(),
|
||||
'user_agent' => $request->userAgent(),
|
||||
'target_url' => $request->url(),
|
||||
'options' => json_encode($request->all()),
|
||||
]);
|
||||
|
||||
Config::set('logging.channels.auth_activity', [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/auth_activity.log'),
|
||||
'level' => 'debug',
|
||||
]);
|
||||
|
||||
Log::channel('auth_activity')
|
||||
->{AuthEvent::logType($name)}(sprintf(
|
||||
'%s, APP_NAME: %s, REQUEST_TYPE: %s, SOURCE_IP: %s, SOURCE_PORT: %s, SOURCE_URL: %s, DESTINATION_IP: %s, DESTINATION_PORT: %s, DESTINATION_COUNTRY: %s, USER_ID: %s',
|
||||
$name,
|
||||
config()->string('app.name'),
|
||||
$request->method(),
|
||||
$request->ip(),
|
||||
$_SERVER['REMOTE_PORT'], // @phpstan-ignore-line
|
||||
$request->url(),
|
||||
$request->host(),
|
||||
$request->getPort(),
|
||||
(module('IpStack')->isEnabled()) ? getCountryCodeFromIp($request->ip()) : 'TM',
|
||||
$request->user()->id ?? '-',
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
Log::error('could-not-store-auth-event', [
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user