dongzouqie4220 2015-03-17 23:24
浏览 29

尝试在Gra路由中创建身份验证视图,但不在Laravel 4.2中创建POST

Edit:

I found that when the URLs are the same, the POST one isn't being used whatsoever. Filling the form redirects the user to the auth view even though its method is set to POST. It's as if either the form method was set to GET or I defined a Route::any to that URL. I did neither. Double checked.

I still see no reason for that to be happening.


Main Question:

So, I have a view inside my app that needs to be accessible only to user who have a specific password (NOT their passwords as users) and a specific e-mail. To accomplish that, I put a form inside another view (accessible to everyone) and created a POST route as follows:

teamv5.blade.php

         <form action="{{ URL::route('team-update-v5-post', array('v5',$team_v5->teamname)) }}" method='post'>
                <p>Team password: {{ $team_v5->teamname }}</p>
                <input type='password' name='password'>
                <input type='hidden' name='email' value="{{ Sentry::getUser()->email }}">
                <input type='submit' value='Edit'>
                {{ Form::token(); }}
        </form>

Routes.php

 Route::post('/sentry/team/{v}/{teamname}/edit', array(
        'as'    => 'team-update-v5-post',
        'uses'  => 'TeamController@postUpdateV5'
 ));

 Route::get('/sentry/team/{v}/{teamname}/edit', array(
        'as'    => 'team-update-v5',
        'uses'  => 'TeamController@getUpdateV5'
  ));

So if the password is correct and the user's e-mail is the one authorized to access that view, it works and the information passes to the controller.

Now, problem is: I don't want anyone besides that specific user with that specific password to see the view, so I created a GET route for anyone that tries to simply type the URL in the browser. That route is supposed to make a authentication view that prompts the user to fill in the necessary info. Here is the controller:

TeamController.php

    public function getUpdateV5 ($v,$teamname) {

            return View::make('team.auth')
                    ->with('v',$v)
                    ->with('teamname',$teamname);
    }

    public function postUpdateV5($v,$teamname) {

            $validator = Validator::make(Input::all(), array(
                            'password'      => 'required|min:6',
                            'email'         => 'required|email',
            ));

            if($validator->fails()) {

                    return Redirect::route('team-update-v5',array('v5',$teamname))
                            ->withErrors($validator);
            } else {
                    $team_v5 = DB::table('teams_v5')->where('teamname',$teamname)->first();
                    $captain_v5 = Sentry::findUserById($team_v5->captain_id);

                    if(Hash::check(Input::get('password'), $team_v5->password)) {
                            return View::make('team.updatev5')
                                    ->with('team_v5', $team_v5)
                                    ->with('captain_v5',$captain_v5)
                     } else {

                            return Redirect::route('profile-team',array($v,$teamname))
                                    ->with('global','Incorrect password!');
                    }
            }
    }

At the end, what happens is:

  1. If I write the same URL for the GET and POST routes, the GET one works but after filling that first form in teamv5.blade.php, the user gets redirected to the auth view and is prompted to type the info again (not nice).
  2. If I write different URLs or simply comment out the GET route, the POST one works perfectly but when I try to reload the page or access it via URL, I get the HTTP METHOD NOT ALLOWED error (because, of course, no GET route is written for that URL).

I want the user to be able to access it both ways, if possible. I know I made it long, sorry. Any help would be greatly appreciated.

Thanks in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 touchsocket udp组播
    • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
    • ¥15 VS2012中查询语句无法填入解析,数值传不进去
    • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
    • ¥15 怎么让ai定时给我发信息 c#或者python
    • ¥15 scrapy的Error
    • ¥15 RBF-VSG姚凤军论文复现问题
    • ¥30 开发一个APP商城在制作tabbar的时候运行不了代码没有检查出错误,但是显示不出tabbar,以下为运行结果,如何解决?
    • ¥15 多网卡服务器中winform如何绑定指定网卡
    • ¥15 关于#python#pandas#的问题,想要实现:多个TXT导入Excel,进行分列,不同txt之间都从第一行开始,请各位专家解答!