本文整理匯總了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();
}
}