/** * Changes a password from a given key * * @access public * @param string $key Recovery key * @return mixed True on success or Jaws_Error on failure */ function ChangePassword($key) { $jUser = new Jaws_User(); $user = $jUser->GetUserByPasswordVerifyKey($key); if (Jaws_Error::IsError($user) || empty($user)) { return false; } // generate new password $password = Jaws_Utils::RandomText(8); $res = $jUser->UpdateUser($user['id'], array('username' => $user['username'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $password)); if (Jaws_Error::IsError($res)) { return $res; } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('NewPassword.txt'); $tpl->SetBlock('NewPassword'); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $user['nickname'])); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('nickname', $user['nickname']); $tpl->SetVariable('password', $password); $tpl->SetVariable('message', _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $user['username'])); $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD')); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('NewPassword'); $message = $tpl->Get(); $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT'); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user['email']); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($message)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL')); } return true; }
/** * Activates the user * * @access public * @return string Appropriate notice or error message */ function ReplaceUserEmail() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(403); } $this->gadget->CheckPermission('EditUserEmail'); $key = jaws()->request->fetch('key', 'get'); $jUser = new Jaws_User(); $user = $jUser->GetUserByEmailVerifyKey($key); if (Jaws_Error::IsError($user) || empty($user)) { return _t('USERS_ACTIVATION_KEY_NOT_VALID'); } $result = $jUser->UpdateUser($user['id'], array('username' => $user['username'], 'nickname' => $user['nickname'], 'email' => $user['new_email'], 'new_email' => '', 'status' => 1)); if (Jaws_Error::IsError($result)) { return $result; } return _t('USERS_EMAIL_REPLACEMENT_REPLACED'); }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $request = Jaws_Request::getInstance(); $post = $request->fetch(array('username', 'email', 'nickname', 'password'), 'post'); if (isset($_SESSION['install']['data']['CreateUser'])) { $post = $_SESSION['install']['data']['CreateUser'] + $post; } if ($_SESSION['secure']) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $JCrypt = Jaws_Crypt::getInstance(array('pvt_key' => $_SESSION['pvt_key'], 'pub_key' => $_SESSION['pub_key'])); if (!Jaws_Error::isError($JCrypt)) { $post['password'] = $JCrypt->decrypt($post['password']); } else { return $JCrypt; } } $_SESSION['install']['CreateUser'] = array('username' => $post['username'], 'email' => $post['email'], 'nickname' => $post['nickname']); require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['install']['Database']); #if (Jaws_Error::IsError($objDatabase)) { # return new Jaws_Error("There was a problem connecting to the database, please check the details and try again.", 0, JAWS_ERROR_WARNING); #} require_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); $GLOBALS['app']->loadPreferences(array('language' => $_SESSION['install']['language']), false); Jaws_Translate::getInstance()->LoadTranslation('Install', JAWS_COMPONENT_INSTALL); require_once JAWS_PATH . 'include/Jaws/User.php'; $userModel = new Jaws_User(); $userInfo = $userModel->GetUser($post['username']); if (!Jaws_Error::IsError($userInfo)) { //username exists if (isset($userInfo['username'])) { _log(JAWS_LOG_DEBUG, "Update existing user"); $res = $userModel->UpdateUser($userInfo['id'], array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'])); } else { _log(JAWS_LOG_DEBUG, "Adding first/new admin user to Jaws"); $res = $userModel->AddUser(array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'], 'superadmin' => true)); } } else { $res = $userInfo; } if (Jaws_Error::IsError($res)) { _log(JAWS_LOG_DEBUG, "There was a problem while creating your user:"); _log(JAWS_LOG_DEBUG, $res->GetMessage()); return new Jaws_Error(_t('INSTALL_USER_RESPONSE_CREATE_FAILED'), 0, JAWS_ERROR_ERROR); } return true; }