Esempio n. 1
0
 public function updateUser(User $user)
 {
     $updateArray = array('username' => $user->getUsername() ?: null, 'role' => $user->getRole() ?: null, 'salt' => $user->getSalt() ?: null, 'password' => $user->getPassword() ?: null, 'fullName' => $user->getFullName() ?: null, 'gender' => $user->getGender() ?: null, 'birthdate' => $user->getBirthdate() ?: null, 'email' => $user->getEmail() ?: null, 'mobile' => $user->getMobile() ?: null, 'cityId' => (int) $user->getCityId() ?: null, 'districtId' => (int) $user->getDistrictId() ?: null, 'address' => $user->getAddress() ?: null, 'rememberMe' => $user->getRememberMe() ?: null, 'lastAccess' => $user->getLastAccess() ?: null, 'activeKey' => $user->getActiveKey() ?: null, 'resetKey' => $user->getResetKey() ?: null, 'active' => $user->getActive(), 'registeredDate' => $user->getRegisteredDate() ?: null, 'facebook' => $user->getFacebook() ?: null, 'description' => $user->getDescription() ?: null, 'locked' => $user->getLocked() ?: null);
     $updateArray = array_filter($updateArray, 'strlen');
     $updateArray = array_filter($updateArray);
     $update = $this->getDbSql()->update(self::TABLE_NAME);
     if ($user->getId()) {
         $update->where(array('id' => $user->getId()));
     }
     $update->set($updateArray);
     $query = $this->getDbSql()->buildSqlString($update);
     $result = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     return $result;
 }
Esempio n. 2
0
 /**
  * @param \User\Model\User $user
  */
 public function resetPassword(\User\Model\User $user)
 {
     $sl = $this->getServiceLocator();
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $sl->get('User\\Model\\UserMapper');
     $translator = $this->getServiceLocator()->get('translator');
     //==============================
     $message = new Message();
     $message->addTo($user->getEmail());
     $message->addFrom(self::DEFAULT_EMAIL_SENDER, $_SERVER['HTTP_HOST']);
     $message->setSubject('Welcome to ' . $_SERVER['HTTP_HOST']);
     $link = $_SERVER['HTTP_HOST'] . '/user/user/resetpassword?email=' . $user->getEmail() . '&resetKey=' . $user->getResetKey();
     $body = sprintf($translator->translate("Xin chào %s"), $user->getFullName());
     $body .= "<br/><br/>";
     $body .= "Hệ thống đã nhận được yêu cầu đổi mật khẩu của bạn. Xin vui lòng nhấn vào đường link phía dưới để thay đổi mật khẩu.";
     $body .= '<a href="' . $link . '">' . $link . '</a>';
     $body .= "<br/><br/>";
     $body .= 'Xin cảm ơn!';
     $body .= "<br/>";
     $body .= "<a href='http://erp.nhanh.vn'>http://erp.nhanh.vn</a>";
     $html = new MimePart($body);
     $html->type = 'text/html';
     $content = new MimeMessage();
     $content->setParts(array($html));
     $message->setBody($content);
     $smtp = new Smtp();
     $config = $sl->get('Config');
     $smtp->setOptions(new SmtpOptions($config['smtpOptions']));
     $smtp->send($message);
 }