本文整理汇总了PHP中Model\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model\User
的用法示例。
在下文中一共展示了User::findOne方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* Logging in and out
*/
public function login($email, $password)
{
$user = User::findOne(array('email' => $email));
if (!$user) {
return array('error' => 404, 'message' => 'No such user');
}
if ($user->password !== $this->password($password)) {
return array('error' => 401, 'message' => 'Invalid Password');
}
$this->login_apply((string) $user->id, $user->token);
return array('message' => 'Login Success');
}
示例2: assertCliUser
/**
* Create CLI User (Requires API Key Access)
*/
public function assertCliUser()
{
$this->user = User::findOne(array('email' => 'cli@hoardhq.com'));
if (!$this->user) {
$this->user = User::create(array('email' => 'cli@hoardhq.com'));
$this->user->createApiKey();
}
$apikeys = array_keys($this->user->apikeys);
$this->apikey = isset($apikeys[0]) ? $apikeys[0] : false;
if (!$this->apikey) {
$this->user->createApiKey();
$this->assertCliUser();
}
}