本文整理汇总了PHP中Users::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findFirst方法的具体用法?PHP Users::findFirst怎么用?PHP Users::findFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Users
的用法示例。
在下文中一共展示了Users::findFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startAction
/**
* This action authenticate and logs a user into the application
*/
public function startAction()
{
if ($this->request->isPost()) {
// Get the data from the user
$email = $this->request->getPost('email');
$password = $this->request->getPost('password');
$tokenKey = $this->request->getPost("token_key");
$token = $this->request->getPost("token");
if ($this->security->checkToken($tokenKey, $token)) {
// Find the user in the database
$first_user = Users::findFirst(array("(email = :email: OR username = :email:) AND status = '1'", 'bind' => array('email' => $email)));
// validation password
if ($first_user) {
$user = $this->security->checkHash($password, $first_user->password);
}
if ($user != false) {
$this->_registerSession($first_user);
$this->flash->success('Welcome ' . $first_user->name);
// Forward to the 'invoices' controller if the user is valid
return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
}
}
$this->flash->error('Wrong email/password');
}
// Forward to the login form again
return $this->dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
}
示例2: profileAction
/**
* Edit the active user profile
*
*/
public function profileAction()
{
//Get session info
$auth = Session::get('auth');
//Query the active user
$user = Users::findFirst($auth['id']);
if ($user == false) {
$this->_forward('index/index');
}
if (!$this->request->isPost()) {
Tag::setDefault('name', $user->name);
Tag::setDefault('email', $user->email);
} else {
$name = $this->request->getPost('name', 'string');
$email = $this->request->getPost('email', 'email');
$name = strip_tags($name);
$user->name = $name;
$user->email = $email;
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
Flash::error((string) $message, 'alert alert-error');
}
} else {
Flash::success('Your profile information was updated successfully', 'alert alert-success');
}
}
}
示例3: user
public function user()
{
if (null == $this->user) {
$this->user = Users::findFirst($this->user_id);
}
return $this->user;
}
示例4: profileAction
public function profileAction()
{
$auth = $this->session->get('auth');
$user = Users::findFirst($auth['id']);
if ($user == false) {
$this->_forward('index/index');
}
$request = $this->request;
if (!$request->isPost()) {
Tag::setDefault('name', $user->name);
Tag::setDefault('email', $user->email);
} else {
$name = $request->getPost('name', 'string');
$email = $request->getPost('email', 'email');
$name = strip_tags($name);
$user->name = $name;
$user->email = $email;
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->flash->success('更新成功');
}
}
}
示例5: loginAction
/**
* Handles login with either POST variables or remember me cookie values.
* If success redirects to dashboard (IndexController), unsuccesfull forward to index/loginform
*/
public function loginAction()
{
$rememberMe = false;
if ($this->request->isPost()) {
$username = trim($this->request->getPost('username'));
$password = trim($this->request->getPost('password'));
$rememberMe = $this->request->getPost('rememberme');
} else {
if ($this->cookies->has('username') && $this->cookies->has('password')) {
$username = trim($this->cookies->get('username')->getValue());
$password = trim($this->cookies->get('password')->getValue());
}
}
$user = Users::findFirst(array("username = :username:", 'bind' => array('username' => $username)));
if ($user && $this->security->checkHash($password, $user->password)) {
$this->_registerSession($user);
$response = new Response();
if ($rememberMe) {
$response->setCookies($this->cookies->set('username', $username, strtotime('+1 year')));
$response->setCookies($this->cookies->set('password', $password, strtotime('+1 year')));
}
$user->last_login = date('Y-m-d H:i:s');
$user->save();
return $response->redirect('');
} else {
$this->loginFailed = true;
}
return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
}
示例6: profileAction
/**
* Edit the active user profile
*
*/
public function profileAction()
{
//Get session info
$auth = $this->session->get('auth');
//Query the active user
$user = Users::findFirst($auth['id']);
if ($user == false) {
return $this->_forward('index/index');
}
if (!$this->request->isPost()) {
$this->tag->setDefault('name', $user->name);
$this->tag->setDefault('email', $user->email);
} else {
$name = $this->request->getPost('name', array('string', 'striptags'));
$email = $this->request->getPost('email', 'email');
$user->name = $name;
$user->email = $email;
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->flash->success('Your profile information was updated successfully');
}
}
}
示例7: submitAction
public function submitAction()
{
// Disable view
$this->view->disable();
// Check and get POSTED data
if ($this->request->isPost() && !empty($login_name = $this->request->getPost("username")) && !empty($password = $this->request->getPost("password"))) {
$user = Users::findFirst(array("login_name = :login_name: AND active = true", "bind" => array("login_name" => $login_name)));
if (empty($user)) {
echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username tidak dikenal"));
return;
} else {
if ($user->isBanned()) {
echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username ini tidak dapat digunakan kembali"));
return;
} else {
if ($user->isSuspended()) {
echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Untuk sementara, username ini tidak dapat digunakan"));
return;
}
}
}
if (!$this->security->checkHash($password, $user->getPassword())) {
echo json_encode(array("success" => false, "errorType" => "password", "errorMessage" => "Password yang anda masukkan salah"));
return;
}
$this->session->set("auth", array("user" => $user, "role" => Roles::findFirstByIdRole($user->getIdRole())));
echo json_encode(array("success" => true));
}
}
示例8: startAction
/**
* This action authenticate and logs a user into the application
*/
public function startAction()
{
//die("session start action");
if ($this->request->isPost()) {
// Get the data from the user
$nom = $this->request->getPost('name');
$password = $this->request->getPost('password');
//var_dump($nom . $password);die();
// Find the user in the database
$conditions = 'nom = :nom: AND mdp = :password:';
$user = Users::findFirst(array($conditions, 'bind' => array('nom' => $nom, 'password' => $password)));
//var_dump($nom ."=>". $password);die("line 48");
//var_dump($user);die("line 49");
if ($user != false) {
//die("coucou " . $nom);
$this->_registerSession($user);
$this->flash->success('Welcome ' . $user->nom);
// Forward to the 'invoices' controller if the user is valid
return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'listMembers'));
}
$this->flash->error('Wrong username/password');
}
// Forward to the login form again
return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
}
示例9: indexAction
function indexAction()
{
$uid = $this->session->get('user');
$user = Users::findFirst("id = '{$uid}'");
$userLeagues = $user->userLeagues;
$this->view->userLeagues = $userLeagues;
echo $this->view->render('leagues', 'index');
}
示例10: getTarget
/**
* 获取标签目标信息
* @return unknown
*/
public function getTarget()
{
if ($this->type == 1) {
$target = Articles::findFirst($this->target_id);
} elseif ($this->type == 2) {
$target = Users::findFirst($this->target_id);
}
return $target;
}
示例11: access
public static function access()
{
$key = isset($_POST['key']) ? $_POST['key'] : die('Не передан обязательный параметр key');
$user = Users::findFirst(array("key = :key:", 'bind' => array('key' => $key)));
if ($user != false) {
return true;
} else {
die('Неверный api_key');
}
}
示例12: auth
/**
* Auth the actor role
*
* @param \Phalcon\Mvc\Micro $app
* @return void
*/
function auth($app)
{
$token = $app->request->get('token', 'string');
/* @var Users $admin */
$admin = Users::findFirst("id = " . ADMIN_USER_ID);
if (!$admin || !$admin instanceof Users || $admin->token !== $token) {
echo -999;
die;
}
}
示例13: getUserAction
public function getUserAction()
{
$userId = $this->request->get('userId', 'int');
$users = new Users();
$user = $users->findFirst('id = ' . $userId)->toArray();
if ($user) {
$user['registered'] = date('d.m.Y H:i:s', $user['registered']);
}
$this->response->setContentType('application/json', 'utf-8');
$this->response->setJsonContent($user);
return $this->response;
}
示例14: loginAction
public function loginAction()
{
$login = $this->request->getPost('login');
$password = $this->request->getPost('password');
$user = Users::findFirst(array("login = ?0", "bind" => array($login)));
if ($user) {
if ($this->security->checkHash($password, $user->password)) {
//The password is valid
}
}
//The validation failed
}
示例15: startAction
public function startAction()
{
if ($this->request->isPost()) {
$email = $this->request->getPost('email');
$password = $this->request->getPost('password');
$user = Users::findFirst(array("(email=:email: or username=:email:) and password=:password:", 'bind' => array('email' => $email, 'password' => sha1($password))));
if ($user != false) {
$this->_registerSession($user);
$this->flash->success('Welcome' . $user->name);
return $this->forward('invoices/index');
}
}
}