本文整理汇总了PHP中App\Model\User::login方法的典型用法代码示例。如果您正苦于以下问题:PHP User::login方法的具体用法?PHP User::login怎么用?PHP User::login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Model\User
的用法示例。
在下文中一共展示了User::login方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLogin
public function postLogin()
{
$this->validate(request(), [
'username' => 'required',
'password' => 'required',
]);
if (User::login(request())) {
return redirect()->intended('/');
} else {
return back()->withErrors('用户名或密码错误');
}
}
示例2: loginAction
public function loginAction()
{
if (!$this->isPostRequest()) {
return $this->redirect('home');
} else {
$pd = $this->getPostData();
$pass = md5($pd['password']);
$u = User::login($pd['email'], $pass);
$_SESSION['logged']['id'] = $u['id'];
$_SESSION['logged']['name'] = $u['name'];
$_SESSION['logged']['email'] = $u['email'];
$_SESSION['logged']['power'] = $u['power'];
return $this->redirectOldLink();
}
}
示例3: login
/**
* Login action method
*
* @return void
*/
public function login()
{
$this->prepareView('login.phtml');
$this->view->title = 'Please Login';
$this->view->form = new Form\Login($this->application->config()['forms']['App\\Form\\Login']);
if ($this->request->isPost()) {
$auth = new Auth\Auth(new Auth\Adapter\Table('App\\Table\\Users', Auth\Auth::ENCRYPT_BCRYPT));
$this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($this->request->getPost(), $auth);
$user = new Model\User();
$session = new Model\Session();
if ($this->view->form->isValid() && $session->validate($auth->adapter()->getUser(), $this->application->config())) {
$user->login($auth->adapter()->getUser(), $this->sess, $this->application->config());
$this->redirect('/');
} else {
if (null !== $auth->adapter()->getUser() && null !== $auth->adapter()->getUser()->id) {
$user->failed($auth->adapter()->getUser());
if ($this->view->form->isValid()) {
$this->sess->setRequestValue('failed', true);
$this->redirect('/login');
}
}
}
}
$this->send();
}