dqwr32867 2015-09-03 04:22
浏览 11

Auth不在其他模块laravel 4 creolab中工作

hi i create a project in hmvc architecture with creolab module in laravel 4 here
let say i divided my project into 3 module like example there

--module--
auth
shop
content

the scenario here user must login in auth modul first
after that they be able to access 2 module left (Shop & content)

when i try to auth protecting route in module shop or content like this example

Authenticating Group */
Route::group(array('before' => 'auth'), function() {
   Route::get('shop',  array(
    'as' => 'shop',      
    'uses' => 'App\Modules\Shop\Controllers\ShopController@getShop'
  ));
});

i can't access it although i already success login in modul Auth
i already confirm it i success login with return string like this

i think the problem is here
in my module account, my accountController contain script like this

public function postLogin() {
    $validator = Validator::make(Input::all(), array(
        'username' => 'required',
        'password' => 'required'
    ));

    if($validator->fails()) {
        return  Redirect::route('login.post')
                ->withErrors($validator);
    } else {
        $auth = Auth::attempt(array(
            'username' => Input::get('username'),
            'password' => Input::get('password')
        ));

        if($auth) {
            return "login success";
            // return Redirect::intended('shop');
        }
        else {
            return  Redirect::route('login')
                    ->with('global', 'Email or Password Not Match');
        }
    }
}

when i return simple string (disable redirect) i got login successin screen
that indicate i already success login, but when i active redirect to another module, i got push back to login page

i check auth state with this simple script in login page like this

@if (Auth::check())
   {{ login }}
@else
   {{ "not login "}}
@endif

and got not login text
can someone help me?


@update

public function postLogin() {
    $validator = Validator::make(Input::all(), array(
        'username' => 'required',
        'password' => 'required'
    ));

    if($validator->fails()) {
        return  Redirect::route('login.post')
                ->withErrors($validator);
    } else {
        $auth = Auth::attempt(array(
            'username' => Input::get('username'),
            'password' => Input::get('password')
        ));

        if($auth) {
            return Redirect::intended('shop');
        }
        else {
            return  Redirect::route('login')
                    ->with('global', 'Email or Password Not Match');
        }
    }
}

@2nd Update route in shop module

<?php

/* Authenticating Group */
Route::group(array('before' => 'auth'), function() {

  Route::get('shop',  array(
    'as' => 'shop',      
    'uses' => 'App\Modules\Shop\Controllers\ShopController@getShop'
  ));

  Route::post('shop',  array(
    'as' => 'shop.post',      
    'uses' => 'App\Modules\Shop\Controllers\ShopController@postShop'
  ));

  Route::post('shop-delete',  array(
    'as' => 'shop.delete',      
    'uses' => 'App\Modules\Shop\Controllers\ShopController@postShopDelete'
  ));

});

@update my authentication filters.php

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/

Route::filter('auth', function()
{
   if (Auth::guest())
   {
      if (Request::ajax())
      {
        return Response::make('Unauthorized', 401);
      }
      else
      {
        return Redirect::guest('login');
      }
  }
});
  • 写回答

1条回答 默认 最新

  • doqo89924 2015-09-03 04:25
    关注

    Try this if it works.

        if(Auth::attempt(['usernae' => Input::get('username'), 'password' => Input::get('password')]))
        {
           return 'login success';
        }else{
            return 'login failed';
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?