/** * 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'); } } }
public function indexAction() { if ($this->request->getQuery('zone')) { $zone = Zones::findFirst($this->request->getQuery('zone')); } if ($this->request->getQuery('advertiser')) { $advertiser = Users::findFirst($this->request->getQuery('advertiser')); } $this->view->banners = $this->find(); $this->view->title = Functions::mb_ucfirst(trim(($this->request->getQuery('archived') == '1' ? " архивные" : '') . ($this->request->getQuery('filter') == 'deactivated' ? " деактивированные" : ($this->request->getQuery('filter') == 'finished' ? " выполненные" : '')) . " баннеры")) . ($this->request->getQuery('archive') == '1' ? " в архиве" : '') . (isset($advertiser) && $advertiser ? " рекламодателя \"{$advertiser->getUsername()}\"" : '') . (isset($zone) && $zone ? " в зоне \"{$zone->name}\"" : ''); \Phalcon\Tag::prependTitle("Баннеры"); }
/** * This action authenticate and logs an user into the application * */ 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: AND active = 'Y'", 'bind' => array('email' => $email, 'password' => sha1($password)))); if ($user != false) { $this->_registerSession($user); $this->flash->success('Welcome ' . $user->name); return $this->forward('invoices/index'); } $this->flash->error('Wrong email/password'); } return $this->forward('session/index'); }
public function startAction() { if ($this->request->isPost()) { $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $password = sha1($password); $user = Users::findFirst(['conditions' => 'email = ?0 AND password = ?1 AND active= ?2 ', 'bind' => [$email, $password, 'Y']]); if ($user != false) { $this->auth->login($user->toArray()); return $this->goToMain(); } $this->flash->error('Не верный email или password'); } return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index')); }
public function profileAction() { $id = $this->dispatcher->getParam('id'); $user = Users::findFirst($id); if ($user && $id) { if ($this->request->isPost()) { $action = $this->request->getPost('action'); if ($action == "change_info") { if ($user->update($this->request->getPost(), array('fname', 'lname', 'thname'))) { $this->auth->refresh_user(); $this->flashSession->success("Информация о рекламодателе обновлена"); } else { foreach ($user->getMessages() as $message) { $this->flashSession->error($message->getMessage()); } } } elseif ($action == "change_email") { if ($user->update($this->request->getPost(), array('email'))) { $this->auth->refresh_user(); $this->flashSession->success("E-mail рекламодателя изменён"); } else { foreach ($user->getMessages() as $message) { $this->flashSession->error($message->getMessage()); } } } elseif ($action == "change_password") { if ($this->request->getPost('password') === $this->request->getPost('password_confirm')) { if ($user->update(array('password' => $this->auth->hash($this->request->getPost('password'))))) { $this->auth->refresh_user(); $this->flashSession->success('Пароль рекламодателя успешно изменён'); } else { foreach ($user->getMessages() as $message) { $this->flashSession->error($message->getMessage()); } } } else { $this->flashSession->error('Пароль и повтор пароля должны совпадать.'); } } } $this->view->user = $user; $this->view->title = $user->getUsername() . " - Управление"; \Phalcon\Tag::prependTitle($user->getUsername() . " - Управление"); } else { $this->dispatcher->forward(array("namespace" => 'App\\Controllers', "controller" => "error", "action" => "notFound")); } }
public function getUserFromDb() { $id = $this->auth->getUserId(); return Users::findFirst(['conditions' => 'id = ?0', 'bind' => [$id]]); }
public function testRefunds() { $user = Users::findFirst(); // Create Invoice $user->createAsStripeCustomer($this->getTestToken()); $invoice = $user->invoiceFor('Phalcon PHP Cashier', 1000); // Create the refund $refund = $user->refund($invoice->charge); // Refund Tests $this->assertEquals(1000, $refund->amount); }
/** * Attempt to log in a user by using an ORM object and plain-text password. * * @param string $email email to log in * @param string $password password to check against * @param boolean $remember enable autologin * @return boolean */ public function login($user, $password, $remember = false) { if (!is_object($user)) { $email = $user; // email not specified if (!$email) { return null; } // Load the user $user = Users::findFirst(array('email=:email:', 'bind' => array(':email' => $email))); } if ($user) { // Create a hashed password if (is_string($password)) { $password = $this->hash($password); } // If user have login role and the passwords match, perform a login if ($user->password === $password) { if ($remember === true) { // Create a new autologin token $token = new Tokens(); $token->user_id = $user->id; $token->user_agent = sha1($this->request->getUserAgent()); $token->token = $this->create_token(); $token->created = time(); $token->expires = time() + $this->_config['lifetime']; if ($token->create() === true) { // Set the autologin cookie $this->cookies->set('authautologin', $token->token, time() + $this->_config['lifetime']); } } // Finish the login $this->complete_login($user); // Regenerate session_id // session_regenerate_id(); // Store user in session $this->session->set($this->_config['session_key'], serialize($user)); // Store user's roles in session if ($this->_config['session_role']) { $this->session->set($this->_config['session_role'], $user->type); } return true; } else { // Login failed return false; } } // No user found return null; }