Ejemplo n.º 1
0
 function init()
 {
     parent::init();
     $oContentField = new AnwContentFieldSettings_select(self::FIELD_LANG_DEFAULT);
     $asEnumValues = array();
     $asLangs = AnwComponent::globalCfgLangs();
     foreach ($asLangs as $sLang) {
         $sLangName = $sLang . " - " . Anwi18n::langName($sLang);
         $asEnumValues[$sLang] = $sLangName;
     }
     $oContentField->setEnumValues($asEnumValues);
     $this->addContentField($oContentField);
     $oContentField = new AnwContentFieldSettings_string(self::FIELD_LANGS);
     $oContentField->addAllowedPattern("!^.{" . Anwi18n::MINLEN_LANG . "," . Anwi18n::MAXLEN_LANG . "}\$!");
     $oContentMultiplicity = new AnwContentMultiplicity_multiple();
     $oContentField->setMultiplicity($oContentMultiplicity);
     $this->addContentField($oContentField);
     $oContentField = new AnwContentFieldSettings_select(self::FIELD_TIMEZONE_DEFAULT);
     $anEnumValues = array();
     $anTimezones = AnwUsers::getTimezones();
     foreach ($anTimezones as $nTimezone) {
         $sTimezoneName = Anwi18n::timezoneName($nTimezone);
         $anEnumValues[$nTimezone] = $sTimezoneName;
     }
     $oContentField->setEnumValues($anEnumValues);
     $this->addContentField($oContentField);
 }
Ejemplo n.º 2
0
 static function login($sLogin, $sPassword, $bResume)
 {
     //authenticate
     $oUser = AnwUsers::authenticate($sLogin, $sPassword);
     //user is authenticated, open the session
     self::getSession()->login($oUser, $bResume);
     AnwSessions::login($oUser, $bResume);
     AnwPlugins::hook("user_loggedin", $oUser, $sPassword, $bResume);
 }
Ejemplo n.º 3
0
 function run()
 {
     if (!self::globalCfgUsersRegisterEnabled()) {
         AnwUtils::redirect();
     }
     $this->setTitle($this->t_('title'));
     $sError = false;
     $sLogin = "";
     $sDisplayName = "";
     $sEmail = "";
     if (AnwEnv::_POST("submit")) {
         $sLogin = AnwEnv::_POST("login", "");
         $sDisplayName = AnwEnv::_POST("displayname", "");
         $sEmail = AnwEnv::_POST("email", "");
         $sPassword = AnwEnv::_POST("password", "");
         //try to register
         try {
             $this->checkCaptcha();
             $sLang = AnwCurrentSession::getLang();
             $nTimezone = AnwCurrentSession::getTimezone();
             $oUser = AnwUsers::createUser($sLogin, $sDisplayName, $sEmail, $sLang, $nTimezone, $sPassword);
             AnwCurrentSession::login($sLogin, $sPassword, false);
             //open a public time-limited session
             $this->redirectInfo(false, $this->t_("t_created"), $this->t_("p_created"));
         } catch (AnwLoginAlreadyTakenException $e) {
             $sError = $this->g_("err_loginalreadytaken");
         } catch (AnwBadLoginException $e) {
             $sError = $this->g_("err_badlogin");
         } catch (AnwDisplayNameAlreadyTakenException $e) {
             $sError = $this->g_("err_displaynamealreadytaken");
         } catch (AnwBadDisplayNameException $e) {
             $sError = $this->g_("err_baddisplayname");
         } catch (AnwEmailAlreadyTakenException $e) {
             $sError = $this->g_("err_emailalreadytaken");
         } catch (AnwBadEmailException $e) {
             $sError = $this->g_("err_bademail");
         } catch (AnwBadPasswordException $e) {
             $sError = $this->g_("err_badpassword");
         } catch (AnwBadCaptchaException $e) {
             $sError = $this->g_("err_badcaptcha");
         }
     }
     //display register form
     $this->out .= $this->tpl()->registerForm(AnwUtils::alink("register"), $sLogin, $sDisplayName, $sEmail, $sError);
 }
Ejemplo n.º 4
0
 private function updateSettings()
 {
     //update prefs
     $asErrorsPrefs = array();
     try {
         $sLang = AnwEnv::_POST("lang", "");
         AnwCurrentSession::setLang($sLang);
         $nTimezone = AnwEnv::_POST("timezone", 0);
         AnwCurrentSession::setTimezone($nTimezone);
     } catch (AnwBadLangException $e) {
         $asErrorsPrefs[] = $this->g_("err_badlang");
     } catch (AnwBadTimezoneException $e) {
         $asErrorsPrefs[] = $this->g_("err_badtimezone");
     } catch (AnwException $e) {
         $asErrorsPrefs[] = $this->g_("err_unkn");
     }
     $asErrorsAccount = array();
     if (AnwCurrentSession::isLoggedIn() && AnwUsers::isDriverInternal()) {
         //update account
         try {
             //displayname change requested ?
             if (self::globalCfgUsersChangeDisplayname()) {
                 $sDisplayname = AnwEnv::_POST("displayname", "");
                 if (AnwCurrentSession::getUser()->getDisplayName() != $sDisplayname) {
                     AnwCurrentSession::getUser()->changeDisplayName($sDisplayname);
                 }
             }
             //email change requested ?
             $sEmail = AnwEnv::_POST("email", "");
             if (AnwCurrentSession::getUser()->getEmail() != $sEmail) {
                 AnwCurrentSession::getUser()->changeEmail($sEmail);
             }
             //password change requested ?
             $sNewPassword = AnwEnv::_POST("newpassword");
             $sNewPasswordRepeat = AnwEnv::_POST("newpassword_repeat");
             $sCurrentPassword = AnwEnv::_POST("currentpassword", "");
             if ($sNewPassword) {
                 if ($sNewPassword == $sNewPasswordRepeat) {
                     try {
                         //authenticate with current password
                         AnwCurrentSession::getUser()->authenticate($sCurrentPassword);
                         //authentication ok, change the password
                         try {
                             AnwCurrentSession::getUser()->changePassword($sNewPassword);
                         } catch (AnwBadPasswordException $e) {
                             $asErrorsAccount[] = $this->t_("err_badnewpassword");
                         }
                     } catch (AnwBadPasswordException $e) {
                         $asErrorsAccount[] = $this->g_("err_incorrectpassword");
                     } catch (AnwAuthException $e) {
                         $asErrorsAccount[] = $this->g_("err_incorrectpassword");
                     }
                 } else {
                     $asErrorsAccount[] = $this->g_("err_passwordsmatch");
                 }
             }
         } catch (AnwDisplayNameAlreadyTakenException $e) {
             $asErrorsAccount[] = $this->g_("err_displaynamealreadytaken");
         } catch (AnwBadDisplayNameException $e) {
             $asErrorsAccount[] = $this->g_("err_baddisplayname");
         } catch (AnwEmailAlreadyTakenException $e) {
             $asErrorsAccount[] = $this->g_("err_emailalreadytaken");
         } catch (AnwBadEmailException $e) {
             $asErrorsAccount[] = $this->g_("err_bademail");
         } catch (AnwException $e) {
             $asErrorsAccount[] = $this->g_("err_unkn");
         }
     }
     if (count($asErrorsPrefs) > 0 || count($asErrorsAccount) > 0) {
         $this->formSettings(false, $asErrorsPrefs, $asErrorsAccount);
     } else {
         AnwUtils::redirect($this->linkMe(array("done" => 1)));
     }
 }
Ejemplo n.º 5
0
 function output($bEmergencyError = false)
 {
     AnwDebug::startbench("output", true);
     //render head
     $this->renderHeadForOutput();
     //global actions
     /*$asAllGlobalActions = array("lastchanges", "sitemap", "untranslated", "management");
     		$asAvailableGlobalActions = array();
     		foreach ($asAllGlobalActions as $sAction)
     		{
     			if (AnwCurrentSession::isActionGlobalAllowed($sAction))
     			{
     				$asAvailableGlobalActions[] = array(
     					'action' => $sAction,
     					'link' => AnwUtils::alink($sAction),
     					'translation' => self::g_("action_".$sAction)
     				);
     			}
     		}*/
     if (!$bEmergencyError) {
         //session nav
         if (AnwCurrentSession::isLoggedIn()) {
             $sLinkProfile = AnwUsers::isDriverInternal() ? AnwUtils::alink("profile") : AnwUsers::getLinkProfile(AnwCurrentSession::getUser());
             $sLinkSettings = AnwUtils::aLink("settings");
             $sLinkLogout = AnwSessions::isDriverInternal() ? AnwUtils::alink("logout") : AnwSessions::getLogoutLink();
             $sessionnav = $this->tpl()->sessionNavLoggedin(AnwCurrentSession::getUser()->getDisplayName(), $sLinkProfile, $sLinkSettings, $sLinkLogout);
         } else {
             $sLinkSettings = AnwUtils::aLink("settings");
             $sLinkLogin = AnwSessions::isDriverInternal() ? AnwUtils::alink("login") : AnwSessions::getLoginLink();
             if (self::globalCfgUsersRegisterEnabled()) {
                 $sLinkRegister = AnwUsers::isDriverInternal() ? AnwUtils::alink("register") : AnwUsers::getRegisterLink();
             } else {
                 $sLinkRegister = false;
             }
             $sessionnav = $this->tpl()->sessionNavGuest($sLinkSettings, $sLinkLogin, $sLinkRegister);
         }
         $aoAllowedGlobalNavEntries = $this->getGlobalNavEntriesAllowed();
         if (count($aoAllowedGlobalNavEntries) > 0) {
             $globalnav = $this->tpl()->globalNav($aoAllowedGlobalNavEntries);
         } else {
             $globalnav = "";
         }
     } else {
         $sessionnav = "";
         $globalnav = "";
     }
     $this->out = $this->tpl()->globalBody($sessionnav, $globalnav, $this->out);
     $this->out = $this->tpl()->globalHtml(self::g_("local_html_lang", array(), self::getActionLang()), self::g_("local_html_dir", array(), self::getActionLang()), $this->title, $this->head, $this->out);
     AnwDebug::stopbench("output");
     $this->printOutput();
 }
Ejemplo n.º 6
0
    private function selectTimezone($nSelectedTimezone)
    {
        $HTML = "";
        $anTimezones = AnwUsers::getTimezones();
        foreach ($anTimezones as $nTimezone) {
            $sSelected = $nSelectedTimezone == $nTimezone ? ' selected="selected"' : '';
            $sTimezoneName = Anwi18n::timezoneName($nTimezone);
            $sTimezoneTime = Anwi18n::dateTime(time(), false, $nTimezone);
            $HTML .= <<<EOF

\t\t\t\t<option value="{$nTimezone}"{$sSelected}>({$sTimezoneName}) {$sTimezoneTime}</option>
EOF;
        }
        return $HTML;
    }
Ejemplo n.º 7
0
 static function rebuildSession($oUser, $bResume, $sLang, $nTimezone, $sId, $nTimeStart, $nTimeSeen, $nTimeAuth = 0)
 {
     $oSession = new AnwSession();
     $oSession->oUser = $oUser;
     $oSession->bResume = $bResume;
     if (!Anwi18n::isValidLang($sLang)) {
         $sLang = AnwComponent::globalCfgLangDefault();
     }
     $oSession->sLang = $sLang;
     if ($oUser->exists()) {
         $oSession->bLoggedIn = true;
     } else {
         $oSession->bLoggedIn = false;
     }
     $oSession->sId = $sId;
     if (!AnwUsers::isValidTimezone($nTimezone)) {
         $nTimezone = AnwComponent::globalCfgTimezoneDefault();
     }
     $oSession->nTimezone = $nTimezone;
     $oSession->nTimeStart = $nTimeStart;
     $oSession->nTimeSeen = $nTimeSeen;
     $oSession->nTimeAuth = $nTimeAuth;
     return $oSession;
 }
Ejemplo n.º 8
0
 function loadInfo()
 {
     if ($this->bInfoLoaded) {
         return;
     }
     try {
         $this->debug("Loading user info...");
         $oUser = AnwUsers::getUser($this->nId);
         $this->sLogin = $oUser->getLogin();
         parent::loadInfoFromUser($oUser);
     } catch (AnwUserNotFoundException $e) {
         $this->bExists = false;
     }
     $this->bInfoLoaded = true;
 }
Ejemplo n.º 9
0
 private function getCurrentSessionFromDatabase()
 {
     $sCookieSessionId = AnwEnv::_COOKIE(self::COOKIE_SESSION_ID);
     $sCookieSessionCode = AnwEnv::_COOKIE(self::COOKIE_SESSION_CODE);
     if ($sCookieSessionId && $sCookieSessionCode) {
         //first of all, purge the old sessions from database
         $this->purgeExpiredSessionsFromDatabase();
         //we have session info in cookies, check against the database
         self::debug("Session info found in cookies, checking against database...");
         $q = $this->db()->query("SELECT SessionCode, SessionIdentifier, " . "SessionUser, SessionResume, " . "SessionTimeStart, SessionTimeSeen, SessionTimeAuth " . "FROM `#PFX#session` WHERE SessionId=" . $this->db()->strtosql($sCookieSessionId) . " " . "LIMIT 1");
         $oData = $this->db()->fto($q);
         $this->db()->free($q);
         if ($oData) {
             self::debug("Session found in database");
             //check session code
             if ($sCookieSessionCode == $oData->SessionCode) {
                 self::debug("Session code OK");
                 if ($sCookieSessionCode != AnwEnv::_SESSION(self::SESSION_CODE)) {
                     //_SESSION may contain an old session code when running multiple Anwiki instances synchronized together
                     //update _SESSION as session is valid!
                     self::debug("Session code is outdated in the session, resynchronizing it with the cookie...");
                     AnwEnv::putSession(self::SESSION_CODE, $sCookieSessionCode);
                 }
                 //check session identifier
                 if (AnwEnv::calculateSessionIdentifier() == $oData->SessionIdentifier) {
                     self::debug("Session identifier OK");
                     //check that session user still exists
                     $nSessionUserId = $oData->SessionUser;
                     $oSessionUser = AnwUsers::getUser($nSessionUserId);
                     if ($oSessionUser->exists()) {
                         //allright, restore the session
                         $bSessionResume = $oData->SessionResume == '1' ? true : false;
                         $sSessionLang = $oSessionUser->getLang();
                         $nSessionTimezone = $oSessionUser->getTimezone();
                         $nSessionTimeStart = $oData->SessionTimeStart;
                         $nSessionTimeSeen = $oData->SessionTimeSeen;
                         $nSessionTimeAuth = $oData->SessionTimeAuth;
                         $oSession = AnwSession::rebuildSession($oSessionUser, $bSessionResume, $sSessionLang, $nSessionTimezone, $sCookieSessionId, $nSessionTimeStart, $nSessionTimeSeen, $nSessionTimeAuth);
                         return $oSession;
                     } else {
                         self::debug("Session user doesn't exist anymore");
                     }
                 } else {
                     self::debug("Invalid session identifier");
                 }
             } else {
                 self::debug("Invalid session code");
             }
             //here, the sessionid was found but a bad sessioncode, sessionidentifier or user was given
             //we kill the session to prevent hacking attempts
             self::debug("WARNING: sessionid was found, but wrong sessions checks was provided. Kill the session.");
             $this->db()->query("DELETE FROM `#PFX#session` WHERE SessionId=" . $this->db()->strtosql($sCookieSessionId));
         } else {
             self::debug("Session NOT found in database");
         }
     }
     throw new AnwSessionNotFoundException();
 }
Ejemplo n.º 10
0
 /**
  * @throws AnwUnexpectedException
  */
 static function loadDriver()
 {
     AnwDebug::startbench("Users driver init");
     self::$oDriver = AnwUsersDriver::loadComponent(AnwComponent::globalCfgDriverUsers());
     if (self::isDriverInternal()) {
         self::debug("Users Driver loaded : internal");
     } else {
         if (self::isDriverExternal()) {
             self::debug("Users Driver loaded : external");
         } else {
             throw new AnwUnexpectedException("Unknown usersdriver type");
         }
     }
     AnwDebug::stopbench("Users driver init");
 }
Ejemplo n.º 11
0
 function testValue($sValue)
 {
     //check that user exists
     try {
         $oUser = AnwUsers::getUserByLogin($sValue);
         unset($oUser);
     } catch (AnwException $e) {
         $sError = AnwComponent::g_editcontent("err_contentfield_user_notfound");
         throw new AnwInvalidContentFieldValueException($sError);
     }
 }
Ejemplo n.º 12
0
 protected function chooseAndGrant($sLogin, $sPassword)
 {
     try {
         //try to authenticate
         $oUser = AnwUsers::authenticate($sLogin, $sPassword);
         $this->grantUserAdmin($oUser);
         return;
     } catch (AnwAuthException $e) {
         $sError = $this->g_("err_auth");
     } catch (AnwBadLoginException $e) {
         $sError = $this->g_("err_badlogin");
     } catch (AnwBadPasswordException $e) {
         $sError = $this->g_("err_badpassword");
     }
     $this->showChooseGrant("", "", "", $sLogin, "", $sError);
 }