0
在fuelphp項目中,我有一個正常的後端註冊用戶。在前端,我有一個只有大學用戶可以登錄到後端的登錄名(superadmin也不能從前端登錄)。 我的問題是如果我打開後端,前端,然後刷新後端或前端用戶註銷後端。 我將後端登錄保持爲默認的fuelphp登錄(admin.php)。 code:如何維護前端登錄和後端登錄fuelphp
public function action_login() {
// Already logged in
Auth::check() and Response::redirect('admin');
$val = Validation::forge();
if (Input::method() == 'POST') {
$val->add('email', 'Email or Username')
->add_rule('required');
$val->add('password', 'Password')
->add_rule('required');
if ($val->run()) {
$auth = Auth::instance();
// check the credentials. This assumes that you have the previous table created
if (Auth::check() or $auth->login(Input::post('email'), Input::post('password'))) {
// credentials ok, go right in
if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
$current_user = Model\Auth_User::find_by_username(Auth::get_screen_name());
} else {
$current_user = Model_User::find_by_username(Auth::get_screen_name());
}
Session::set_flash('success', e('Welcome, ' . $current_user->fullname));
Response::redirect('admin');
} else {
$this->template->set_global('login_error', 'Login failed.');
}
}
}
$this->template->title = 'Login';
$this->template->content = View::forge('admin/login', array('val' => $val), f
alse); } 另外我都保持前端登錄在不同的控制器(的welcome.php)如下
public function action_login_university() {
$val = Validation::forge();
if (Input::method() == 'POST') {
$auth = Auth::instance();
// check the credentials. This assumes that you have the previous table created
//if (Auth::check() and $auth->login(Input::post('email'), Input::post('password'))) {
if ($auth->login(Input::post('email'), Input::post('password'))) {
// credentials ok, go right in
if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
$current_user = Model\Auth_User::find_by_username(Auth::get_screen_name());
} else {
$current_user = Model_User::find_by_username(Auth::get_screen_name());
}
$group_id = $current_user->group_id;
$data['uname'] = Input::post('email');
$data['psword'] = Input::post('password');
$data['gid'] = $group_id;
if($current_user->group_id == '8') {
$data['msg'] = 'success';
$data['url'] = Input::post('admin_url');
} else {
$data['msg'] = 'error';
$data['url'] = Input::post('current_url');
}
} else {
$data['msg'] = 'error';
$data['url'] = Input::post('current_url');
}
echo json_encode($data);
die;
}
}
我已經通過在前端AJAX完成登錄。 任何幫助/建議welcome.Thanks提前。
使用兩個differrent驗證實例。 Auth靜態方法在默認實例上操作,作爲方便的快捷方式,但您可以創建多個auth實例,每個auth實例都有自己的配置。在這種情況下,您將使用 '$ authinstance-> check();'而不是'Auth :: check();' – WanWizard