اذهب إلى المحتوى

السؤال

نشر (معدل)

السلام عليكم ورحمة الله وبركاته 

استخدم في عملية تسجيل دخول لارافيل جيت ستريم 

لكن مستخدم في حالة سجل دخول يدهب لصفحة تالية لكن من خلال سهم في متصفح يستطيع رجوع لصفحة تسجيل دخول كيف امنعه في حالة كان auth  الا اذا عمل تسجيل خروج 

تم التعديل في بواسطة محمد عاطف25
تعديل عنوان السؤال

Recommended Posts

  • 0
نشر

وعليكم السلام ورحمة الله تعالى وبركاته،

على الأرجح فإنّ المتصفح يعرض الصفحة من ذاكرته المؤقتة أي دون أن يرسل طلبا حقيقيا إلى الخادم، وهذا يعني أن ال middleware لا يستدعى أصلا عند الضغط على زر الرجوع فالصفحة تظهر مباشرة من المتصفح لا من Laravel لحل المشكلة انتقل إلى ملف routes/web.php وتأكد أن مسار تسجيل الدخول مرتبط ب middleware الخاص ب guest على النحو الآتي:

Route::get('/login', function () {
    return view('auth.login');
})->middleware('guest');

وهذا ال guest middleware هو في حقيقته RedirectIfAuthenticated الموجود في app/Http/Middleware/RedirectIfAuthenticated.php وعمله أن يتحقق من حالة المصادقة فإن كان المستخدم مسجّلا دخوله أعاد توجيهه فورا إلى الصفحة الرئيسية ولأن Jetstream يتولى تسجيل هذه المسارات تلقائيا فقد تحتاج إلى نشر إعداداته عبر الأمر التالي للتحقق من أن الربط موجود فعلا:

php artisan vendor:publish --tag=jetstream-routes
  • 0
نشر

وعليكم السلام ورحمة الله،

المشكلة الحقيقية هنا مزدوجة فمن جهة يقوم المتصفح بتخزين صفحة تسجيل الدخول في ذاكرته المؤقتة ويعرضها فوريا عند الضغط على زر الرجوع دون إرسال أي طلب إلى الخادم، مما يعني أن middleware الخاص ب RedirectIfAuthenticated لا يستدعى أصلا في هذه الحالة والحل الأمثل هو إنشاء middleware مخصص يضيف ترويسات HTTP تمنع المتصفح من تخزين الصفحات المحمية،ثم تطبيقه على مسارات المصادقة أولا نقوم بإنشاء ال middleware من خلال الأمر:

php artisan make:middleware PreventBackHistory

ونضع فيه مثلا هذه الشيفرة:

<?php

namespace App\Http\Middleware;

use Closure;

class PreventBackHistory
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        return $response->header('Cache-Control', 'nocache, no-store, max-age=0, must-revalidate')
                        ->header('Pragma', 'no-cache')
                        ->header('Expires', 'Sun, 02 Jan 1990 00:00:00 GMT');
    }
}

ثم تقوم بتسجيله في app/Http/Kernel.php كالتالي:

protected $routeMiddleware = [
    // ...
    'prevent-back-history' => \App\Http\Middleware\PreventBackHistory::class,
];

ثم تطبيقه على المسارات في routes/web.php:

Route::group(['middleware' => ['auth', 'prevent-back-history']], function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    // بقية المسارات المحمية
});

وهكذا حتى لو حاول المستخدم الضغط على زر الرجوع، سيجد المتصفح هذه الترويسات التي تمنعه من عرض النسخة المخزنة، فيرسل طلبا حقيقيا إلى الخادم، وعندها يتدخل RedirectIfAuthenticated ويعيد توجيه المستخدم المُسجَل دخوله تلقائيا إلى لوحة التحكم.

  • 0
نشر

وعليكم السلام ورحمة الله وبركاته . 

أسهل طريقة هي وضع middleware التي تسمى guest حيث هذا ال middleware يقوم بالتأكد من أن المستخدم غير مسجل الدخول ولو حاولت الذهاب للمسار وانت قيد تسجيل الدخول فلن يتم السماح بالذهاب لهذا المسار.

Route::get('/login', function () {
    // 
})->middleware('guest');

 

  • 0
نشر
بتاريخ 16 ساعة قال محمد عاطف25:

وعليكم السلام ورحمة الله وبركاته . 

أسهل طريقة هي وضع middleware التي تسمى guest حيث هذا ال middleware يقوم بالتأكد من أن المستخدم غير مسجل الدخول ولو حاولت الذهاب للمسار وانت قيد تسجيل الدخول فلن يتم السماح بالذهاب لهذا المسار.

Route::get('/login', function () {
    // 
})->middleware('guest');

 

انا استخدم جيت ستريم اين اجد هدا ملف 

<?php

use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\ConfirmablePasswordController;
use Laravel\Fortify\Http\Controllers\ConfirmedPasswordStatusController;
use Laravel\Fortify\Http\Controllers\ConfirmedTwoFactorAuthenticationController;
use Laravel\Fortify\Http\Controllers\EmailVerificationNotificationController;
use Laravel\Fortify\Http\Controllers\EmailVerificationPromptController;
use Laravel\Fortify\Http\Controllers\NewPasswordController;
use Laravel\Fortify\Http\Controllers\PasswordController;
use Laravel\Fortify\Http\Controllers\PasswordResetLinkController;
use Laravel\Fortify\Http\Controllers\ProfileInformationController;
use Laravel\Fortify\Http\Controllers\RecoveryCodeController;
use Laravel\Fortify\Http\Controllers\RegisteredUserController;
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController;
use Laravel\Fortify\Http\Controllers\TwoFactorQrCodeController;
use Laravel\Fortify\Http\Controllers\TwoFactorSecretKeyController;
use Laravel\Fortify\Http\Controllers\VerifyEmailController;
use Laravel\Fortify\RoutePath;

Route::group(['middleware' => config('fortify.middleware', ['web'])], function () {
    $enableViews = config('fortify.views', true);

    // Authentication...
    if ($enableViews) {
        Route::get(RoutePath::for('login', '/signin'), [AuthenticatedSessionController::class, 'create'])
            ->middleware(['guest:'.config('fortify.guard')])
            ->name('login');
    }

    $limiter = config('fortify.limiters.login');
    $twoFactorLimiter = config('fortify.limiters.two-factor');
    $verificationLimiter = config('fortify.limiters.verification', '6,1');

    Route::post(RoutePath::for('login', '/signin'), [AuthenticatedSessionController::class, 'store'])
        ->middleware(array_filter([
            'guest:'.config('fortify.guard'),
            $limiter ? 'throttle:'.$limiter : null,
        ]))->name('login.store');

    Route::post(RoutePath::for('logout', '/logout'), [AuthenticatedSessionController::class, 'destroy'])
        ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
        ->name('logout');

    // Password Reset...
    if (Features::enabled(Features::resetPasswords())) {
        if ($enableViews) {
            Route::get(RoutePath::for('password.request', '/forgot-password'), [PasswordResetLinkController::class, 'create'])
                ->middleware(['guest:'.config('fortify.guard')])
                ->name('password.request');

            Route::get(RoutePath::for('password.reset', '/reset-password/{token}'), [NewPasswordController::class, 'create'])
                ->middleware(['guest:'.config('fortify.guard')])
                ->name('password.reset');
        }

        Route::post(RoutePath::for('password.email', '/forgot-password'), [PasswordResetLinkController::class, 'store'])
            ->middleware(['guest:'.config('fortify.guard')])
            ->name('password.email');

        Route::post(RoutePath::for('password.update', '/reset-password'), [NewPasswordController::class, 'store'])
            ->middleware(['guest:'.config('fortify.guard')])
            ->name('password.update');
    }

    // Registration...
    if (Features::enabled(Features::registration())) {
        if ($enableViews) {
            Route::get(RoutePath::for('register', '/register'), [RegisteredUserController::class, 'create'])
                ->middleware(['guest:'.config('fortify.guard')])
                ->name('register');
        }

        Route::post(RoutePath::for('register', '/register'), [RegisteredUserController::class, 'store'])
            ->middleware(['guest:'.config('fortify.guard')])
            ->name('register.store');
    }

    // Email Verification...
    if (Features::enabled(Features::emailVerification())) {
        if ($enableViews) {
            Route::get(RoutePath::for('verification.notice', '/email/verify'), [EmailVerificationPromptController::class, '__invoke'])
                ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
                ->name('verification.notice');
        }

        Route::get(RoutePath::for('verification.verify', '/email/verify/{id}/{hash}'), [VerifyEmailController::class, '__invoke'])
            ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'signed', 'throttle:'.$verificationLimiter])
            ->name('verification.verify');

        Route::post(RoutePath::for('verification.send', '/email/verification-notification'), [EmailVerificationNotificationController::class, 'store'])
            ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'throttle:'.$verificationLimiter])
            ->name('verification.send');
    }

    // Profile Information...
    if (Features::enabled(Features::updateProfileInformation())) {
        Route::put(RoutePath::for('user-profile-information.update', '/user/profile-information'), [ProfileInformationController::class, 'update'])
            ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
            ->name('user-profile-information.update');
    }

    // Passwords...
    if (Features::enabled(Features::updatePasswords())) {
        Route::put(RoutePath::for('user-password.update', '/user/password'), [PasswordController::class, 'update'])
            ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
            ->name('user-password.update');
    }

    // Password Confirmation...
    if ($enableViews) {
        Route::get(RoutePath::for('password.confirm', '/user/confirm-password'), [ConfirmablePasswordController::class, 'show'])
            ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
            ->name('password.confirm');
    }

    Route::get(RoutePath::for('password.confirmation', '/user/confirmed-password-status'), [ConfirmedPasswordStatusController::class, 'show'])
        ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
        ->name('password.confirmation');

    Route::post(RoutePath::for('password.confirm', '/user/confirm-password'), [ConfirmablePasswordController::class, 'store'])
        ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
        ->name('password.confirm.store');

    // Two Factor Authentication...
    if (Features::enabled(Features::twoFactorAuthentication())) {
        if ($enableViews) {
            Route::get(RoutePath::for('two-factor.login', '/two-factor-challenge'), [TwoFactorAuthenticatedSessionController::class, 'create'])
                ->middleware(['guest:'.config('fortify.guard')])
                ->name('two-factor.login');
        }

        Route::post(RoutePath::for('two-factor.login', '/two-factor-challenge'), [TwoFactorAuthenticatedSessionController::class, 'store'])
            ->middleware(array_filter([
                'guest:'.config('fortify.guard'),
                $twoFactorLimiter ? 'throttle:'.$twoFactorLimiter : null,
            ]))->name('two-factor.login.store');

        $twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
            ? [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'password.confirm']
            : [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')];

        Route::post(RoutePath::for('two-factor.enable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'store'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.enable');

        Route::post(RoutePath::for('two-factor.confirm', '/user/confirmed-two-factor-authentication'), [ConfirmedTwoFactorAuthenticationController::class, 'store'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.confirm');

        Route::delete(RoutePath::for('two-factor.disable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'destroy'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.disable');

        Route::get(RoutePath::for('two-factor.qr-code', '/user/two-factor-qr-code'), [TwoFactorQrCodeController::class, 'show'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.qr-code');

        Route::get(RoutePath::for('two-factor.secret-key', '/user/two-factor-secret-key'), [TwoFactorSecretKeyController::class, 'show'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.secret-key');

        Route::get(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'index'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.recovery-codes');

        Route::post(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'store'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.regenerate-recovery-codes');
    }
});

 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...