public static function getNewsByID($IDNews) { $Blog = parent::getNewsByID($IDNews); $TheBlog = new self(); $TheBlog->copy($Blog); $Author = new App_Model_User(); $Author->copy($Blog->Author); $TheBlog->Author = $Author; return $TheBlog; }
public function registerAction() { $exists = App_Model_User::getCount(['email' => $this->getParam('email')]); if ($exists) { throw new App_Exception_UserAlreadyExists(); } $user = new App_Model_User(['email' => $this->getParam('email'), 'password' => $this->getParam('password'), 'registered' => time()]); $user->addToken(); $user->save(); }
public function getReceiver() { if (!isset($this->_receiver)) { parent::getReceiver(); foreach ($this->_receiver as &$R) { $TheReceiver = new App_Model_User(); $R = $TheReceiver->copy($R); } } return $this->_receiver; }
public function fetchAll() { $resultSet = $this->getDbTable()->fetchAll(); $entries = array(); foreach ($resultSet as $row) { $entry = new App_Model_User(); $entry->setCredibility($row->credibility)->setIsActive($row->is_active)->setRoleId($row->role_id)->setEmail($row->email)->setUsername($row->username)->setToken($row->token)->setId($row->id); $entries[] = $entry; } return $entries; }
public function indexAction() { $config = Zend_Registry::get('config')['sender']; do { $message = App_Model_Queue::pop(App_Model_Queue::SMS); if ($message) { $user = App_Model_User::fetchOne(['id' => (string) $message->user]); $settings = $user->data['sms']; $settings['uri'] = $config['sms']['uri']; \Smsc\Smsc::setConfig($settings); $sms = new \Smsc\Smsc(); $this->writeLine("------------------------------------------------"); $this->writeLine("------------------------------------------------"); $this->writeLine("sending message: " . $message->content); $this->writeLine("to: " . implode(', ', array_values($message->receivers))); $this->writeLine("from: " . $user->data['sms']['sender']); $sms->setReceivers($message->receivers); $sms->setMessage($message->content); $this->writeLine("Start sending..."); try { $sms->send(); } catch (Exception $e) { $this->writeLine($e->getMessage()); } $this->writeLine('>>>> Done'); sleep(1); } } while (true); }
public function indexAction() { do { $message = App_Model_Queue::pop(App_Model_Queue::EMAIL); if ($message) { $user = App_Model_User::fetchOne(['id' => (string) $message->user]); $config = $user->data['mail']; Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($config['server'], ['auth' => $config['auth'], 'username' => $config['username'], 'password' => $config['password'], 'port' => $config['port'], 'ssl' => $config['ssl']])); $mail = new Zend_Mail('UTF-8'); foreach ($message->receivers as $receiver) { $mail->addTo($receiver['email'], $receiver['name']); } $this->writeLine("------------------------------------------------"); $this->writeLine("to: " . print_r($message->receivers, true)); $this->writeLine("from: " . implode(', ', [$user->data['mail']['username'], $user->data['mail']['name']])); $this->writeLine("Subject: " . $message->subject); $mail->setSubject($message->subject); $mail->setBodyHtml($message->content); $mail->setFrom($user->data['mail']['username'], $user->data['mail']['name']); $this->writeLine("Start sending..."); try { $mail->send(); } catch (Exception $e) { $this->writeLine($e->getMessage()); } $this->writeLine('>>>> Done'); sleep(1); } } while (true); }
/** * @before _secured, _admin */ public function index() { $view = $this->getActionView(); $latestnews = App_Model_News::all(array('active = ?' => true), array('author', 'title', 'shortBody', 'created'), array('created' => 'DESC'), 8); $latestgallery = App_Model_Gallery::all(array('active = ?' => true), array('title', 'created', 'isPublic'), array('created' => 'DESC'), 10); $latestmembers = App_Model_User::all(array('active = ?' => true, 'role = ?' => 'role_member'), array('firstname', 'lastname', 'imgThumb', 'created'), array('created' => 'DESC'), 10); $latestdogs = App_Model_Dog::fetchAllLimit(); $view->set('latestnews', $latestnews)->set('latestgallery', $latestgallery)->set('latestmembers', $latestmembers)->set('latestdogs', $latestdogs); }
/** * Authorize user by token * * @throws App_Exception_Forbidden */ public function init() { parent::init(); $this->user = App_Model_User::fetchOne(['tokens' => ['$in' => [$this->getRequest()->getHeader('x-auth')]]]); if (!$this->user) { throw new App_Exception_Forbidden(); } $config = Zend_Registry::get('config'); App_Service_Storage::setConfig($config['storage']); App_Service_Storage::setUser($this->user); }
public function indexAction() { $this->view->form = new Avatar_Form_Modifica(); if ($this->getRequest()->isPost()) { if ($this->view->form->isValid($this->getRequest()->getPost())) { App_Model_User::editUser($this->view->form->getValue('id'), $this->view->form->getValue('nascita'), $this->view->form->getValue('luogo'), $this->view->form->getValue('descrizione1'), $this->view->form->getValue('descrizione2'), $this->view->form->getValue('descrizione3')); } } else { $this->view->form->populate($this->view->pg->toForm()); } }
/** * @throws Exception */ public function init() { parent::init(); $token = $this->getRequest()->getHeader('x-auth'); if ($token) { $this->user = App_Model_User::fetchOne(['tokens' => ['$in' => [$token]]]); if ($this->user) { return; } } throw new Exception('Not authorized', 403); }
/** * Action called to post values of a new user. */ public function postnewAction() { // TODO prevent CSRF $this->secure('admin'); $user = new App_Model_User(); $user->setUsername($_POST['username']); $user->setPassword($_POST['password']); $user->setFirstname($_POST['firstname']); $user->setLastname($_POST['lastname']); $user->setIsAdmin($_POST['is_admin'] == 'on'); $user->setEmail($_POST['email']); if (0 === count($user->isValid())) { $user->save(); return redirect_to('/admin/users'); } else { $errors = ''; foreach ($user->isValid() as $error) { $errors .= $error . "<br />"; } flash_now('error', $errors); return $this->createAction(); } }
public function createAction() { if (!$this->getUser()->getIsSuperAdmin()) { $this->addFlashMessageNotice('Only super admins may create new users'); $this->_redirect($this->getUrl(array(), 'admin_view_users')); } $this->view->page_heading = 'Create New User'; $form = new Admin_Form_CreateUser(); $this->view->form = $form; if (!$this->getRequest()->isPost()) { return; } $is_form_valid = $form->isValid($this->getRequest()->getPost()); if ($form->password->getValue() != $form->password_confirm->getValue()) { $form->password_confirm->addError('This does not match the other password given'); $is_form_valid = false; } if ($is_form_valid) { $user = new App_Model_User(); $user->setEmail($form->email->getValue()); $user->setPassword($form->password->getValue()); $user->setIsSuperAdmin(false); try { $this->getDb()->persist($user); $this->getDb()->flush(); $this->addFlashMessageSuccess('New user has been created successfully'); $this->_redirect($this->getUrl(array(), 'admin_view_users')); } catch (PDOException $e) { $dbException = new App_Model_DBExceptionDecorator($e); if ($dbException->isDuplicateKeyViolation()) { $form->email->addError('A user with that email address already exists'); } else { throw $e; } } } }
/** * */ public function members() { $view = $this->getActionView(); $layoutView = $this->getLayoutView(); $content = $this->getCache()->get('clenove'); if (NULL !== $content) { $members = $content; } else { $members = App_Model_User::fetchMembersWithDogs(); $this->getCache()->set('clenove', $members); } $canonical = 'http://' . $this->getServerHost() . '/clenove'; $layoutView->set('canonical', $canonical)->set('metatitle', 'ZKO - Členové'); $view->set('members', $members); }
public function registerAction() { $this->view->form = new App_Form_Login_Register(); if ($this->getRequest()->isPost()) { if ($this->view->form->isValid($this->getRequest()->getPost())) { if (App_Model_User::addUser($this->view->form->getValue('nome'), $this->view->form->getValue('cognome'), $this->view->form->getValue('nascita'), $this->view->form->getValue('email'), $this->view->form->getValue('password'))) { $this->_helper->redirector('registerOk'); } else { $this->_helper->redirector('registerKo'); } } else { $this->_helper->redirector('registerKo'); } } }
/** * list all announcements */ protected function listAnnouncements() { //echo "in list123<br>"; try { $obj = new App_Model_User(); $result = $obj->listUser(); $my_result1 = array(); $obj->success = "1"; for ($i = 0; $i <= 1; $i++) { // echo "in for $i::".$result[$i]['email']."<br>"; $my_result1[$i]['id'] = $result[$i]['id']; $my_result1[$i]['email'] = $result[$i]['email']; } } catch (exception $e) { echo $e->getMessage(); } /*$data = array ( 'Data'=> array ( 'id' => '1', 'title' => 'Rashmi' ), array ( 'id' => '2', 'title' => 'Abhiram' ), array ( 'id' => '3', 'title' => 'Ved' ) );*/ print_r($my_result1); echo "<br>"; echo "<br>"; return $my_result1; }
public function listaAction() { if ($this->getRequest()->isPost()) { if ($this->getRequest()->getPost('search')) { $Utenti = App_Model_User::searchUser($this->getRequest()->getPost('search')); $this->view->clearVars(); file_put_contents(PUBLIC_PATH . '/log.log', print_r($Utenti, true)); $this->view->utenti = array(); foreach ($Utenti as $Utente) { $this->view->utenti[] = array($Utente->IDUser, (string) $Utente, null, (string) $Utente); } echo json_encode($this->view->utenti); exit; } } }
public static function getUsersOnline($Age = 1) { $TheOnline = new self(); $Onlines = $TheOnline->fetchAll("Date + INTERVAL {$Age} MINUTE > NOW()", "IDLocation"); $Ret = array(); foreach ($Onlines as $Online) { $TheOnline = new self(); $TheOnline->copyFromDb($Online); $TheOnline->User = App_Model_User::getUserById($Online->IDUser); if ($TheOnline->IDLocation) { $TheOnline->Location = Mappa_Model_Luogo::get($Online->IDLocation); } $Ret[] = $TheOnline; } return $Ret; }
public function preDispatch() { list($IDUser, $Name) = explode(' ', $this->_getParam('pg'), 2); if ('index' != $this->getRequest()->getActionName() && 'permalink' != $this->getRequest()->getActionName()) { return; } if (!isset($Name)) { if (!Zend_Auth::getInstance()->hasIdentity()) { $this->_helper->_redirector('auth', 'error', 'default'); } $this->_forward($IDUser); return; } try { $this->view->pg = App_Model_User::getUserById($IDUser); $this->view->title = $this->view->pg->Name . ' ' . $this->view->pg->Surname; $this->view->titleImg = $this->view->normalize($this->view->title); $this->view->headTitle()->append($this->view->title); } catch (Exception $e) { $this->view->pg = $Name; $this->getRequest()->setActionName('notFound'); } }
public function __toString() { $date = new Zend_Date($this->Date); $author = App_Model_User::getUserById($this->IDUser); return str_replace(array('%date%', '%author%', '%tag%', '%text%'), array($date->toString('H:m:s'), $author, $this->Tag, $this->Text), $this->_template[$this->Type]); }
/** * Sign Out Users */ public function signoutUser($data) { $obj_user = array(); $obj_create = new App_Model_Objcreation(); $obj_chkapi = new App_Model_Chkapi(); $validation_result = $obj_chkapi->chkAPI($data); if ($validation_result == 1) { try { $obj = new App_Model_User(); $result = $obj->SingOutUserModel($data); if ($result) { $obj_user = new stdClass(); $obj_user->success = "true"; $obj_user->userid = $data['UserID']; $obj_user->SignOut = 1; $obj_user->UsersessionID = $data['SessionID']; } else { $msg = "User already signed out"; $obj_user = $obj_create->createObjfalse(3, $msg); } //end of else } catch (exception $e) { $msg = $e->getMessage(); $obj_user = $obj_create->createObjfalse(3, $msg); } //end of try } else { $obj_user = $obj_create->createObjfalse(2); } return $obj_user; }
/** * Function for user to log-in forcefully i.e without providing user-credentials * * @param integer $userId * @return boolean * @throws Exception\UserNotExists */ public function forceLogin($userId) { $user = \App_Model_User::first(array('id = ?' => (int) $userId)); if ($user === null) { throw new Exception\UserNotExists('User not found'); } $this->setUser($user); return true; }
public function deleteAction() { $id = $this->getRequest()->getParam('id'); $this->view->title = "Delete User "; $this->view->headTitle($this->view->title); if ($this->getRequest()->isPost()) { $del = $this->getRequest()->getPost('del'); if ($del == 'Yes') { $id = $this->getRequest()->getPost('id'); $tbl = new App_Model_User(); $mapper = new App_Model_UserMapper(); $row = $tbl->find($id); $mapper->delete($tbl); } $this->_helper->redirector('index'); } else { $tbl = new App_Model_User(); $this->view->id = $id; } }
/** * Method generates 40-chars lenght salt for salting passwords * * @return string */ public static function createSalt() { $newSalt = Rand::randStr(40); $user = \App_Model_User::first(array('salt = ?' => $newSalt)); if ($user === null) { return $newSalt; } else { for ($i = 0; $i < 100; $i++) { $newSalt = Rand::randStr(40); $user = \App_Model_User::first(array('salt = ?' => $newSalt)); if ($i == 99) { throw new Exception('Salt could not be created'); } if ($user === null) { return $newSalt; } else { continue; } } } }
/** * @before _secured, _admin */ public function deleteUserMainPhoto($id) { $this->willRenderActionView = false; $this->willRenderLayoutView = false; if ($this->checkCSRFToken()) { $user = App_Model_User::first(array('id = ?' => (int) $id)); if ($user === null) { echo self::ERROR_MESSAGE_2; } else { $unlinkMainImg = $user->getUnlinkPath(); $unlinkThumbImg = $user->getUnlinkThumbPath(); $user->imgMain = ''; $user->imgThumb = ''; if ($user->validate()) { $user->save(); @unlink($unlinkMainImg); @unlink($unlinkThumbImg); Event::fire('admin.log', array('success', 'User id: ' . $user->getId())); echo 'success'; } else { Event::fire('admin.log', array('fail', 'User id: ' . $user->getId())); echo self::ERROR_MESSAGE_1; } } } else { echo self::ERROR_MESSAGE_1; } }
/** * Main authentication method which is used for user authentication * based on two credentials such as username and password. These login * credentials are set in database. * * @param string $name Username or email * @param string $pass Password */ public function authenticate($name, $pass) { $errMessage = sprintf('%s and/or password are incorrect', ucfirst($this->_name)); $errMessageNotActive = 'Account is not active'; $user = \App_Model_User::first(array("{$this->_name} = ?" => $name)); if ($user === null) { throw new Exception\UserNotExists($errMessage); } $passVerify = PasswordManager::validatePassword($pass, $user->getPassword(), $user->getSalt()); if ($passVerify === true) { if ($user instanceof AdvancedUser) { if (!$user->isActive()) { throw new Exception\UserInactive($errMessageNotActive); } elseif ($user->isAccountExpired()) { throw new Exception\UserExpired($errMessage); } elseif ($user->isPasswordExpired()) { throw new Exception\UserPassExpired($errMessage); } else { $user->setLastLogin(); $user->setTotalLoginAttempts(0); $user->setLastLoginAttempt(0); $user->setFirstLoginAttempt(0); $user->save(); $user->password = null; $user->salt = null; return $user; } } elseif ($user instanceof BasicUser) { if (!$user->isActive()) { throw new Exception\UserInactive($errMessageNotActive); } else { $user->setLastLogin(); $user->setTotalLoginAttempts(0); $user->setLastLoginAttempt(0); $user->setFirstLoginAttempt(0); $user->save(); $user->password = null; $user->salt = null; return $user; } } else { throw new Exception\Implementation(sprintf('%s is not implementing BasicUser', get_class($user))); } } else { if ($this->_bruteForceDetection === true) { if ($this->isBruteForce($user)) { $identifier = $this->_name; Core::getLogger()->log(sprintf('Brute Force Attack Detected for account %s', $user->{$identifier})); throw new Exception\BruteForceAttack('WARNING: Brute Force Attack Detected. We Recommend you use captcha.'); } else { throw new Exception\WrongPassword($errMessage); } } else { throw new Exception\WrongPassword($errMessage); } } }
/** * @before _secured, _admin */ public function edit($id) { $view = $this->getActionView(); $dog = App_Model_Dog::fetchDogById((int) $id); if ($dog === null) { $view->warningMessage(self::ERROR_MESSAGE_2); $this->_willRenderActionView = false; self::redirect('/admin/dog/'); } $dogExams = $dog->exams; $dogExamIds = array(); if (!empty($dogExams)) { foreach ($dogExams as $dogExam) { $dogExamIds[] = $dogExam->examId; } } $exams = App_Model_Exam::all(array('active = ?' => true)); $users = App_Model_User::all(array('role = ?' => 'role_member'), array('id', 'firstname', 'lastname')); $view->set('dog', $dog)->set('exams', $exams)->set('dogexamids', $dogExamIds)->set('users', $users); if (RequestMethods::post('submitEditDog')) { if ($this->checkCSRFToken() !== true) { self::redirect('/admin/dog/'); } $errors = array(); $cfg = Registry::get('configuration'); $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight)); $imgMain = $imgThumb = ''; if ($dog->imgMain == '') { $photoNameRaw = RequestMethods::post('user') . '-' . RequestMethods::post('dogname'); $photoName = $this->_createUrlKey($photoNameRaw); $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'dog', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($fileErrors)) { $errors['croppedimage'] = $fileErrors; } if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $imgMain = trim($file->getFilename(), '.'); $imgThumb = trim($file->getThumbname(), '.'); break; } } } } else { $imgMain = $dog->imgMain; $imgThumb = $dog->imgThumb; } if ((int) RequestMethods::post('isactive') == 1) { App_Model_Dog::updateAll(array('isActive = ?' => true, 'userId = ?' => (int) RequestMethods::post('user')), array('isActive' => 0)); } $dog->userId = RequestMethods::post('user'); $dog->isActive = RequestMethods::post('isactive', 0); $dog->dogName = RequestMethods::post('dogname'); $dog->race = RequestMethods::post('dograce'); $dog->dob = RequestMethods::post('dogdob'); $dog->information = RequestMethods::post('doginfo'); $dog->active = RequestMethods::post('active'); $dog->imgMain = $imgMain; $dog->imgThumb = $imgThumb; if (empty($errors) && $dog->validate()) { $dog->save(); $examsArr = (array) RequestMethods::post('chexam'); if ($examsArr[0] != '') { $deleteStatus = App_Model_DogExam::deleteAll(array('dogId = ?' => (int) $dog->getId())); if ($deleteStatus != -1) { foreach ($examsArr as $exam) { $de = new App_Model_DogExam(array('dogId' => (int) $dog->getId(), 'examId' => (int) $exam)); $de->save(); Event::fire('admin.log', array('success', 'Dog id: ' . $dog->getId() . ' has exam ' . $exam)); } } else { $errors['exams'] = array('Nastala chyba při ukládání zkoušek'); } } if (RequestMethods::post('uploadmorephotos') == '1') { $fileErrors = $fileManager->newUpload()->uploadImage('secondfile', 'dog', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($fileErrors)) { $errors['secondfile'] = $fileErrors; } if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $info = $file->getOriginalInfo(); $photo = new App_Model_Photo(array('galleryId' => 2, 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize())); if ($photo->validate()) { $photoId = $photo->save(); $dp = new App_Model_DogPhoto(array('dogId' => $dog->getId(), 'photoId' => $photoId)); $dp->save(); Event::fire('admin.log', array('success', 'Photo id: ' . $photoId)); } else { Event::fire('admin.log', array('fail')); $errors['secondfile'][] = $photo->getErrors(); } } } } if (empty($errors)) { Event::fire('admin.log', array('success', 'Dog Id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/dog/'); } else { Event::fire('admin.log', array('fail')); $view->set('errors', $errors)->set('dog', $dog); } } else { Event::fire('admin.log', array('success', 'Dog Id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/dog/'); } } else { Event::fire('admin.log', array('fail', 'Dog Id: ' . $dog->getId())); $view->set('errors', $errors + $dog->getErrors())->set('dog', $dog); } } }