جشنواره عیدانه راکت | عضویت ویژه راکت برای آخرین بار | افزایش قیمت‌ها از سال جدید | و ...

مشاهده اطلاعات بیشتر...
ثانیه
دقیقه
ساعت
روز
محمد نمازی
6 سال پیش توسط محمد نمازی مطرح شد
1 پاسخ

کاستوم کردن مسیر ویو فرم لاگین

باسلام،
چطور میشه مسیر ویو لاگین و رجیستر رو تغییر داد ؟

کد کنترولر لاگین :

<?php

namespace AppHttpControllersAuth;

use AppEventsUserActivation;
use AppHttpControllersController;
use AppUser;
use CarbonCarbon;
use IlluminateFoundationAuthAuthenticatesUsers;
use IlluminateHttpRequest;
use Socialite;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  IlluminateHttpRequest  $request
     * @return IlluminateHttpRedirectResponse|IlluminateHttpResponse
     */
    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 ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if(auth()->validate($request->only('email' , 'password'))) {
            $user = User::whereEmail($request->input('email'))->first();
            if($user->active == 0 ) {
                $checkActiveCode = $user->activationCode()->where('expire' , '>=' , Carbon::now() )->latest()->first();

                if(count($checkActiveCode) == 1) {
                    if($checkActiveCode->expire > Carbon::now() ) {
                        $this->incrementLoginAttempts($request);
                        return back()->withErrors(['code' => 'ایمیل فعال سازی قبلا به ایمیل شما ارسال شد بعد از 15 دقیقه دوباره برای ارسال ایمیل لاگین کنید']);
                    }
                } else {
                    event(new UserActivation($user));
                }
            }
        }

        if ($this->attemptLogin($request)) {
            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 courses, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }

    public function redirectToProvider()
    {
        return Socialite::driver('google')->redirect();
    }

    public function handleProviderCallback()
    {
        $social_user = Socialite::driver('google')->user();
        $user = User::whereEmail($social_user->getEmail())->first();

        if( ! $user ) {
            $user = User::create([
                'name' => $social_user->getName(),
                'email' => $social_user->getEmail(),
                'password' => bcrypt($social_user->getId())
            ]);
        }

        if($user->active == 0) {
            $user->update([
                'active' => 1
            ]);
        }

        auth()->loginUsingId($user->id);
        return redirect('/');
    }
}

ثبت پرسش جدید
بهرام
تخصص : Laravel Developer
@bahram 6 سال پیش مطرح شد
0

سلام
برای تغییر ویو لاگین وارد trait که use شده یعنی AuthenticatesUsers بشید و در تابع showLoginForm ویو که میخوایید رو نمایش بدید.
واسه رجیستر هم که باید به trait مربوط به خودش یعنی RegistersUsers برید و در تابع showRegistrationForm ویو مورد نظرتون رو قرار بدید.
البته میتونید این تابع ها رو توی همون کنترلرتون بازنویسی کنید.


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام