public function mailPrepare($userMail) { $result = array(); //Get user informaton $userTbl = new VC_DbTable_User(); $userInfo = $userTbl->fetchRow("email = '" . addslashes($userMail) . "'"); if ($userInfo) { $config = VC_Config::getConfig(); $fromMail = "*****@*****.**"; $fromName = "Storage Administrator"; if (isset($config['mail']['from_email'])) { $fromMail = $config['mail']['from_email']; $fromName = $config['mail']['from_name']; } else { $log = Zend_Registry::get("VCLog"); $log->error("Could not read from email at " . __FILE__); } $this->setFrom($fromMail, $fromName); $this->addTo($userInfo->email, $userInfo->fullname); $this->assign('full_name', $userInfo->fullname); $this->assign("site_name", $this->siteName); $this->assign("site_link", $this->siteLink); $result['status'] = "ok"; $result['user_info'] = $userInfo; } else { $result['status'] = "failed"; $result['message'] = "Email không tồn tại trong hệ thống, bạn hãy nhập lại."; } return $result; }
public static function getUniqueGuid() { $userTbl = new VC_DbTable_User(); while ($guid = VC_Utils_String::generateCode(10)) { $isExist = $userTbl->fetchRow("guid = '" . $guid . "'"); if (!$isExist) { break; } } return strtoupper($guid); }
public function isValid($value) { $translate = Zend_Registry::get('translate'); $this->_messageTemplates[self::EXIST] = $translate->_('This email really exist, please choose another'); $value = (string) $value; $user_tbl = new VC_DbTable_User(); $row = $user_tbl->fetchRow($user_tbl->select("id")->where("email = ?", $value)); if ($row && sizeof($row)) { //really exist $this->_error(self::EXIST); return false; } return true; }
public function authenticate() { $userTable = new VC_DbTable_User(); $userInfo = $userTable->findUserByUsernameOrEmail($this->username); if ($userInfo) { $identity = new stdClass(); $identity->username = $userInfo->username; $identity->email = $userInfo->email; $identity->userId = $userInfo->id; $identity->role = $userInfo->role; $identity->fullname = $userInfo->fullname; return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity, array()); } return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $this->username); }
public function indexAction() { $reg_success = false; $request = $this->getRequest(); $form = new Default_Form_Register(array('action' => '/register/index', 'method' => 'post')); $errors = array(); // Check if we have a POST request if ($request->isPost()) { $email = $request->getPost("email"); $username = $email; $form_validate = $form->isValid($request->getPost()); if ($form_validate) { $user_tbl = new VC_DbTable_User(); $insertData = array(); $insertData['username'] = $username; $insertData['password_salt'] = VC_Utils_String::generateCode(6); $insertData['password'] = sha1($request->getPost("password") . $insertData['password_salt']); $insertData['email'] = $email; $insertData['fullname'] = $request->getPost("fullname"); $insertData['role'] = "member"; $insertData['created_date'] = date("Y-m-d"); $guid = VC_Business_User::getUniqueGuid(); $insertData['guid'] = $guid; $newUserId = $user_tbl->insert($insertData); //Send mail active $mailUser = new VC_Mail_User(); $mailUser->sendMailActivation($email); $flashMessenger = $this->_helper->getHelper('FlashMessenger'); $flashMessenger->addMessage($this->translate->_("Bạn đã đăng ký thành công, hãy kiểm tra email của bạn và kích hoạt tài khoản")); $this->_redirect("user/active/uid/{$newUserId}"); //$this->_helper->redirector('active/uid/{$newUserId}', 'user'); } else { //$uname_valid_obj->addErrorMessage("CUONG"); //$form->getElement('password')->addErrorMessage('CUONGLIEU'); } } $this->view->form = $form; }
public function activeAction() { $message = ""; $valid = false; $activeCode = $this->_getParam('code'); if ($activeCode) { $userTbl = new VC_DbTable_User(); //Get user information $userInfo = $userTbl->fetchRow("guid = '" . $activeCode . "'"); if ($userInfo) { if ($userInfo->is_active == 0) { $where = "guid = '" . $activeCode . "'"; $status = $userTbl->update(array('is_active' => 1), $where); if ($status) { $message = "Bạn đã kích hoạt tài khoản thành công, hãy đăng nhập để sử dụng hệ thống."; $this->_helper->flashMessenger->addMessage($message); $this->_redirect("/login/index"); } else { } } else { $message = "Tài khoản này đã được kích hoạt trước đó rồi"; } } else { $message = "Tài khoản này không tồn tại trong hệ thống,"; $message .= "<br/>Hãy liên lạc với ban quản trị để xử lý vấn đề này."; } } else { $message = "Thông tin kích hoạt không hợp lệ."; } $messageArr = $this->_helper->flashMessenger->getMessages(); if (sizeof($messageArr) > 0) { $message = $messageArr[0]; } $this->view->valid = $valid; $this->view->message = $message; }
public function processAction() { $request = $this->getRequest(); // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('index'); } // Get our form and validate it $form = $this->getForm(); if (!$form->isValid($request->getPost())) { // Invalid entries $this->view->form = $form; return $this->render('index'); // re-render the login form } $authAdapter = new VC_Auth_UserAdapter($form->getValues()); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if (!$result || !$result->isValid()) { $userTbl = new VC_DbTable_User(); //Get user information $userInfo = $userTbl->fetchRow("email = '" . addslashes($this->_getParam("username")) . "'"); var_dump($userInfo); if ($userInfo && $userInfo->is_active == 0) { $this->_helper->flashMessenger->addMessage("Account not be actived, please active it"); $this->_redirect("user/active/?uid=" . $userInfo->id); } else { $this->view->form = $form; $this->view->message = $this->translate->_("Invalid username or password"); return $this->render('index'); // re-render the login form } } // We're authenticated! Redirect to the home page $this->_helper->redirector('index', 'index'); }