精华内容
下载资源
问答
  • Laravel子域重定向登录

    2016-11-05 05:40:42
    <p>I am creating a laravel project that has the following links... <p>main.dev (This is for login, registration, and help sections for the user) <p>athlete.main.dev (This is for athletes to be ...
  • // 管理员登录 Route::get('/',function(){ return Redirect::to('admin/login'); }); Route::get('login','UserController@adminLogin'); } 目的是无论用户输入”admin”,还是”admin/login”都能跳转到登录...
  • <p>I have a login form in home, and I'm simply try to redirect the user to login page if the data is wrong. Here what I tried so far: <pre><code><?...use Illuminate\Support\Facades\Auth;...
  • <p>I have a basic login system setup, but I would like the user to be sent to there dashboard page if they try to access the "login" page or "create account" page. <p>How do I go about doing this...
  • Laravel 4登录重定向

    2013-08-30 13:37:01
    <p>I do not want to show login page after login in laravel 4. If a logged in user want to visit login page it should redirect to homepage('/'). I am using Sentry for authentication. <p>filter.php</p>...
  • 发现问题最近在做项目发现一个奇怪的现象,我的路由配置里有如下配置:Route::group...'adminauth'),function(){// 管理员登录Route::get('/',function(){return Redirect::to('admin/login');});Route::get('login'...

    发现问题

    最近在做项目发现一个奇怪的现象,我的路由配置里有如下配置:

    Route::group(array('prefix'=>'admin','before'=>'adminauth'),function(){

    // 管理员登录

    Route::get('/',function(){

    return Redirect::to('admin/login');

    });

    Route::get('login','UserController@adminLogin');

    }

    目的是无论用户输入”admin”,还是”admin/login”都能跳转到登录界面。然而现实情况是输入”admin”之后,浏览器会无限重定向,firebug记录如下:

    GET /public/admin/ 301 Moved Permanently

    GET admin 301 Moved Permanently

    GET admin 301 Moved Permanently

    GET /public/admin/ 301 Moved Permanently

    GET admin 301 Moved Permanently

    GET /public/admin/ 301 Moved Permanently

    GET admin 301 Moved Permanently

    ....

    经过一番搜索后试验,终于得出结论,问题有两点:

    1.public目录下正好有个admin目录,存放后台相关js和css

    2.laravel自带的.htaccess的这样一条规则:

    RewriteEngine On

    # Redirect Trailing Slashes...

    RewriteRule ^(.*)/$ /public/$1 [L,R=301] #注意这条

    # Handle Front Controller...

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^ index.php [L]

    解释一下原理:

    访问public/admin目录时,apache会自动转成”public/admin/”的形式,而这种形式正好符合重写的规则,又被重写回”public/admin”的形式。因为public/admin目录确实存在,所以请求根本不会到达index.php。

    所以故事就是这样,因为301那条规则的存在,无限重定向产生了。

    解决方案:

    1.不要把public目录下已有的目录名做为路由地址

    2.301规则前加一条”RewriteCond %{REQUEST_FILENAME} !-d”,但是这样会使该目录被直接访问。建议生产环境中关掉apache的autoindex模块(呃,我发现我用的wamp关掉这个模块apache就启动不了了- -!)。

    补充:

    经过一些实验,建议将.htaccess文件改成如下:

    RewriteEngine On

    # Redirect Trailing Slashes...

    RewriteCond %{REQUEST_FILENAME} !-d #防止真实目录导致循环重定向

    RewriteRule ^(.*)/$ /public/$1 [L,R=301]

    # Handle Front Controller...

    #RewriteCond %{REQUEST_FILENAME} !-d #防止用户直接打开真实目录

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^ index.php [L]

    总结

    以上就是关于Laravel Route重定向的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

    展开全文
  • <p>I'm having an issue now after installing <a href="https://github.com/elic-dev/laravel-math-captcha" rel="nofollow noreferrer">laravel-math-captcha</a> though it was working fine for 2 days with ...
  • <p>I'm trying to show a page from myController after successful to login. <pre><code>$email = $req->input('username'); $pass = $req->input('password');...$login = DB::table('for_login')->...
  • <p>In my Laravel application there is the default login page aswell as a login form inside a dropdown. As I have it set up now, after a successfull login a user is redirected to the index page, ...
  • I removed it because it kept saying the following message the same as this question <a href="https://stackoverflow.com/questions/37462365/laravel-cache-store-does-not-support-tagging">Laravel cache ...
  • <p>I am using Laravel 5.5 and PHP 7.1 I am using the standard built-in Auth and middleware, I have not customized anything. <p>I am wanting to create a route in the api....
  • <p>I'm new to Laravel 5.2 . I have been trying to create a login Page using Session and i wanted to redirect to another page when user login is successfull ...I validate users in Controller create ...
  • 百度里没有能找出相关laravel操作函数方法,有朋友提出了一个可行方案,如下 按上述思路,可以在laravel框架web.php中定义一个新的Route,用于跳转页面,...alert('请先登录');parent.location.href='/login';...

    百度里没有能找出相关laravel操作函数方法,有朋友提出了一个可行方案,如下

     

    按上述思路,可以在laravel框架web.php中定义一个新的Route,用于跳转页面,如下:

    Route::get('/relogin',function (){
        echo "<script>alert('请先登录');parent.location.href='/login';</script>";
    });

     

    展开全文
  • <p>I am Creating Student Portal For My university. <p>There are multiply users in This portal e.g student , teacher , staff , & administration. <p>I have Successfully Created Custom login ...
  • API 认证(Passport)简介Laravel 通过传统的登录表单已经让用户认证变得很简单,但是 API 认证怎么实现?API 通常使用令牌(token)进行认证并且在请求之间不维护会话(Session)状态。Laravel 官方扩展包 Laravel ...

    API 认证(Passport)简介

    Laravel 通过传统的登录表单已经让用户认证变得很简单,但是 API 认证怎么实现?API 通常使用令牌(token)进行认证并且在请求之间不维护会话(Session)状态。Laravel 官方扩展包 Laravel Passport 让 API 认证变得轻而易举,但是官方的文档看起来还是很复杂,对此牛哥在上面花费了大量的时间去研究学习,最终摸索出最简单实用的方式来实现。下面来演示这种'简单'的api接口认证方式,希望对你有所帮助。


    开发环境:

    • system:centos7
    • laravel:8.0
    • php:7.4
    • mysql:5.7
    • nginx:1.15
    • postman:7.34

    安装passport

    执行命令(首先确保你已经下载并安装好laravel框架)
    composer require laravel/passport
    php artisan migrate
    php artisan passport:install

    修改配置

    在配置文件config/auth.php中,需要设置api认证 guard 的driver选项为passport
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    
        'api' => [
            'driver' => 'passport',//修改这里即可
            'provider' => 'users',
        ],
    ],
    User模型文件app/Models/User.php中添加HasApiTokens trait,就可以使用trait提供的createToken方法了。
    namespace AppModels;
    
    use IlluminateContractsAuthMustVerifyEmail;
    use IlluminateDatabaseEloquentFactoriesHasFactory;
    use IlluminateFoundationAuthUser as Authenticatable;
    use IlluminateNotificationsNotifiable;
    use LaravelPassportHasApiTokens;
    
    class User extends Authenticatable
    {
        use HasFactory, Notifiable, HasApiTokens; //添加HasApiTokens
        ...
    }
    

    代码演示

    在routes/api.php中添加测试路由
    Route::namespace('Api')->group(function () {
        //V1接口
        Route::namespace('V1')->prefix('v1')->group(function () {
            //无需登录验证
            Route::get('test/test', 'TestController@test');
            Route::post('test/login', 'TestController@login');
    
            //需要登录验证
            Route::middleware('auth:api')->group(function () {
                Route::get('test/user', 'TestController@user');
            });
        });
    
        //V2接口
        Route::namespace('V2')->prefix('v2')->group(function () {
            //无需登录验证
            Route::get('test/test', 'TestController@test');
    
            //需要登录验证
            Route::middleware('auth:api')->group(function () {
                Route::get('test/user', 'TestController@user');
            });
        });
    });
    添加测试控制器文件 app/Http/Controllers/Api/V1/TestController.php
    <?php
    
    namespace AppHttpControllersApiV1;
    
    use AppModelsUser;
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesRedis;
    use IlluminateSupportFacadesAuth;
    use AppHttpControllersApiController;
    
    class TestController extends ApiController
    {
        public function login(Request $request)
        {
            $name = $request->input('name', '');
            /** @var User $user */
            //这里只是简单使用用户名查询验证,实际可以使用用户名加密码,或者微信登录验证
            $user = User::where('name', $name)->first();
            if ($user) {
                //数据验证成功后,发放access_token
                $accessToken = $user->createToken($name)->accessToken;
                return response()->json([
                   'code' => 200,
                   'data' => [
                       'access_token' => $accessToken,
                       'userInfo' => $user,
                   ]
                ]);
            }
            return response()->json([
                'code' => -201,
                'msg' => '登录失败!'
            ]);
        }
    
        public function user()
        {
            $user = Auth::guard('api')->user();
            return $user;
        }
    }
    mysql的users表添加测试用户数据

    0be0ad99ec74175188e5f999692c2d2e.png
    POST请求接口获取access_token

    cb590408b41aa04720c4ac3b6741713a.png
    携带access_token请求需要auth:api中间件验证的接口 header参数:Authorization:Bearer <access_token>

    977291b6eb33c0a1af7433e9a060a595.png
    去掉 Authorization请求,返回未授权,表明接口验证成功

    4d30b843cf7d2ed0eb5173bd2ba75d0e.png

    到此auth:api验证演示完成,如有疑问或建议,欢迎留言讨论,谢谢观看!

    展开全文
  • 因此,如果需要定制功能的话,需要重写trait。对于简单的网站来说,默认...$redirectTo配置,如果在登录状态,重定向的页面protected $redirectTo = '/home';validator方法和create方法定义了验证和提交的字段 /** ...

    53737e723b6fa861a4fbae41223a6b0e.png

    一、注册模块路由

    eccccefee3b611cac355e01b7bc2f8dc.png

    二、控制器解析

    控制器仅仅实现配置的功能,大部分的逻辑使用trait引入。因此,如果需要定制功能的话,需要重写trait。对于简单的网站来说,默认的功能已经足够了。

    $redirectTo配置,如果在登录状态,重定向的页面

    protected $redirectTo = '/home';

    validator方法和create方法定义了验证和提交的字段

            /**
             * Get a validator for an incoming registration request.
             *
             * @param  array  $data
             * @return IlluminateContractsValidationValidator
             */
            protected function validator(array $data)
            {
                return Validator::make($data, [
                    'name' => ['required', 'string', 'max:255'],
                    'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
                    'password' => ['required', 'string', 'min:6', 'confirmed'],
                ]);
            }
         
            /**
             * Create a new user instance after a valid registration.
             *
             * @param  array  $data
             * @return AppUser
             */
            protected function create(array $data)
            {
                return User::create([
                    'name' => $data['name'],
                    'email' => $data['email'],
                    'password' => Hash::make($data['password']),
                ]);
            }
    

    三、扩展开发:自定义注册字段

    在实际业务中,我们可能需要更多的字段,那么如何扩展呢?

    我这里调整一下,email字段改为非必填(如果填了需要验证合法性和唯一性),新增加一个phone字段非必填(如果填了需要验证合法性和唯一性)

    需要改动的地方:

    1)auth/register.blade.php模板,需要增加phone字段,并将email,phone表单中的require去掉。

    2)RegisterController我们需要改动validator和create方法

            /**
             * Get a validator for an incoming registration request.
             *
             * @param  array  $data
             * @return IlluminateContractsValidationValidator
             */
            protected function validator(array $data)
            {
                return Validator::make($data, [
                    'name' => ['required', 'string', 'min:6', 'max:64'],
                    'email' => ['nullable', 'string', 'email', 'max:64', 'unique:users'],
                    'phone' => ['nullable', 'string', 'regex:/^[0-9]{11}$/', 'unique:users'],//这里偷懒了
                    'password' => ['required', 'string', 'min:6', 'confirmed'],
                ]);
            }
         
            /**
             * Create a new user instance after a valid registration.
             *
             * @param  array  $data
             * @return AppUser
             */
            protected function create(array $data)
            {
                return User::create([
                    'name' => $data['name'],
                    'email' => $data['email'],
                    'phone' => $data['phone'],
                    'password' => Hash::make($data['password']),
                ]);
            }
    

    完成之后,发现phone的值没有写入到数据库中,我们需要修改AppUser类,在$fillable配置中添加phone这个字段

            protected $fillable = [
                'name', 'email', 'phone', 'password',
            ];
    

    3)注册完成后,跳转到登录页,不要自动登录

    注册这个行为,是IlluminateFoundationAuthRegistersUsers::register方法实现的。这个是laravel实现的包,我们在开发中不应该改动包里面的代码。RegistersUsers是一个trait,我们可以在RegisterController把这个方法覆盖掉。

            /**
             * Handle a registration request for the application.
             *
             * @param  IlluminateHttpRequest  $request
             * @return IlluminateHttpResponse
             */
            public function register(Request $request)
            {
                $this->validator($request->all())->validate();
                event(new Registered($user = $this->create($request->all())));
                //$this->guard()->login($user);
                return $this->registered($request, $user)
                ?: redirect($this->redirectPath());
            }
    

    以上就是php-laravel框架用户验证(Auth)模块解析(二)注册模块的详细内容,觉得对你有帮助记得点个关注!!

    小编结合以上知识体系整理了一套BAT面试真题+架构技术资料,退可提升软硬实力,进可收获高薪好offer。资料内容涵盖BAT架构技术与面试真题,减少你到处搜索资料的时间,成体系的实战技术知识,让你面试、进阶都更加容易。

    领取方式:对面试文档总结感兴趣的帮可以点下面链接进入石墨文档了解大型互联网企业面试答案获取详情!

    PHP进阶学习笔记、面试;文档、视频资源免费获取shimo.im
    5e2a3525c06803dbef701a1330548755.png

    198a28645de92aecf8ed60639bd1eb31.png
    展开全文
  • <p>Hi there I am trying to redirect any user who tries to login who has a ban_status ! = 0 <p>I am wondering what the best way for me to do this, I was thinking just to log them out and redirect ...
  • 刚开始接触laravel会遇到这样一个问题,我们在判断用户未登录时跳转至登录页面一般都是建一个控制器基类,在基类的构造函数里面进行判断,如果未登录重定向登录页 我用tp比较多,在tp控制器的构造函数里面可以...
  • 我正在尝试在Laravel 7中实现一个基于角色的简单身份验证系统,其中在用户表上有一个名为'role'的整数类型的附加字段,该字段可以具有两个值-普通用户为0,管理员为5。任何登录的用户都应该能够访问“ / railway”...
  • 我遇到的问题是,当用户登录时,他们会被重定向回主页,而不是他们之前所在的页面.我还没有从开箱即用的设置中更改登录方法.任何人都可以建议一种简单的方法来设置重定向网址.我的想法是能够在表单中设置它会很好.解决...
  • config/admin.php 'auth'=>[ ... 'excepts'=>[ 'auth/login', ] ], 然后就正常了
  • <p>I'm used to working on laravel 5.4 and above, i just got this project with a problem in authentification that is rather weird. Locally, the authentification works just fine but when i try to log ...
  • <p>How can admin and user be redirected in laravel 5.6.12? I cannot find unauthenticated function in app/Exceptions/Handler.php file.. </p> </div>
  • Laravel设置登陆后的重定向地址

    千次阅读 2017-10-19 16:16:14
    在用Laravel 5的时候发现个问题,我需要定制我的登陆页面还有登录后的跳转链接,找了很多方法都没成功。然后去查看源代码:D:\phpStudy\...
  • <p>For a web project that requires a login/register system and lot of CRUD operations, I choose to learn Laravel. I have some experience from school with MVC .NET and Spring and while there are a lot ...
  • <a href="https://stackoverflow.com/questions/31793034/laravel-5-redirecting-to-home-after-login">Laravel-5 redirecting to /home after login</a></p> <p>and in AuthController I have set <pre><code>...
  • <p>I'm using laravel5.2.31. I wanna make login cope and when User after login success, redirect to '/'. And I can register cope but I can't login cope and cannot redirect to '/'. I made auth by <code>...
  • <p>How should i redirect user to login page after a failed login? i tried in <code>AuthController</code> : <pre><code> protected $redirectTo ='/login';... this is one of laravel core files. </div>
  • <p>Can you help me in multi auth of laravel? Now i use one table (users) with two guard web and admin, but the same model related (<code>User) <pre><code>Schema::create('users', function (Blueprint $...

空空如也

空空如也

1 2 3 4 5 6
收藏数 114
精华内容 45
关键字:

laravel登录重定向