/** * Execute the extra. */ public function execute() { // get activation key $key = $this->URL->getParameter(0); // load template $this->loadTemplate(); // do we have an activation key? if (isset($key)) { // get profile id $profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key); // have id? if ($profileId != null) { // update status FrontendProfilesModel::update($profileId, array('status' => 'active')); // delete activation key FrontendProfilesModel::deleteSetting($profileId, 'activation_key'); // login profile FrontendProfilesAuthentication::login($profileId); // trigger event FrontendModel::triggerEvent('profiles', 'after_activate', array('id' => $profileId)); // show success message $this->tpl->assign('activationSuccess', true); } else { $this->redirect(FrontendNavigation::getURL(404)); } } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Execute the extra. * * @return void */ public function execute() { // logout if (FrontendProfilesAuthentication::isLoggedIn()) { FrontendProfilesAuthentication::logout(); } // trigger event FrontendModel::triggerEvent('profiles', 'after_logout'); // redirect $this->redirect(SITE_URL); }
/** * Parse */ private function parse() { $this->tpl->assign('isLoggedIn', FrontendProfilesAuthentication::isLoggedIn()); if (FrontendProfilesAuthentication::isLoggedIn()) { // get the profile /** * @var FrontendProfilesProfile */ $profile = FrontendProfilesAuthentication::getProfile(); $this->tpl->assign('profile', $profile->toArray()); } }
/** * Execute the extra. */ public function execute() { // only for guests if (!FrontendProfilesAuthentication::isLoggedIn()) { parent::execute(); $this->loadTemplate(); $this->loadForm(); $this->validateForm(); $this->parse(); } else { $this->redirect(FrontendNavigation::getURLForBlock('profiles', 'settings')); } }
/** * Execute the extra */ public function execute() { // profile not logged in if (!FrontendProfilesAuthentication::isLoggedIn()) { parent::execute(); $this->loadTemplate(); $this->loadForm(); $this->validateForm(); $this->parse(); } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Execute the extra. * * @return void */ public function execute() { // no url parameter if (FrontendProfilesAuthentication::isLoggedIn()) { // call the parent parent::execute(); /* * You could use this as some kind of dashboard where you could show an activity stream, some statistics, ... */ // load template $this->loadTemplate(); } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Execute the extra. */ public function execute() { // only logged in profiles can seer their dashboard if (FrontendProfilesAuthentication::isLoggedIn()) { // call the parent parent::execute(); /* * You could use this as some kind of dashboard where you can show an activity * stream, some statistics, ... */ $this->loadTemplate(); } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtEmail = $this->frm->getField('email'); $txtPassword = $this->frm->getField('password'); $chkRemember = $this->frm->getField('remember'); // required fields $txtEmail->isFilled(FL::getError('EmailIsRequired')); $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // both fields filled in if ($txtEmail->isFilled() && $txtPassword->isFilled()) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // get the status for the given login $loginStatus = FrontendProfilesAuthentication::getLoginStatus($txtEmail->getValue(), $txtPassword->getValue()); // valid login? if ($loginStatus !== FrontendProfilesAuthentication::LOGIN_ACTIVE) { // get the error string to use $errorString = sprintf(FL::getError('Profiles' . SpoonFilter::toCamelCase($loginStatus) . 'Login'), FrontendNavigation::getURLForBlock('profiles', 'resend_activation')); // add the error to stack $this->frm->addError($errorString); // add the error to the template variables $this->tpl->assign('loginError', $errorString); } } } // valid login if ($this->frm->isCorrect()) { // get profile id $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue()); // login FrontendProfilesAuthentication::login($profileId, $chkRemember->getChecked()); // update salt and password for Dieter's security features FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue()); // trigger event FrontendModel::triggerEvent('profiles', 'after_logged_in', array('id' => $profileId)); // querystring $queryString = urldecode(SpoonFilter::getGetValue('queryString', null, SITE_URL)); // redirect $this->redirect($queryString); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtEmail = $this->frm->getField('email'); $txtPassword = $this->frm->getField('password'); // check email if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email already exists? if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) { // set error $txtEmail->setError(FL::getError('EmailExists')); } } } // check password $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // no errors if ($this->frm->isCorrect()) { // generate salt $salt = FrontendProfilesModel::getRandomString(); // init values $values = array(); // values $values['email'] = $txtEmail->getValue(); $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt); $values['status'] = 'inactive'; $values['display_name'] = $txtEmail->getValue(); $values['registered_on'] = FrontendModel::getUTCDate(); /* * Add a profile. * We use a try-catch statement to catch errors when more users sign up simultaneously. */ try { // insert profile $profileId = FrontendProfilesModel::insert($values); // use the profile id as url until we have an actual url FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name']))); // trigger event FrontendModel::triggerEvent('profiles', 'after_register', array('id' => $profileId)); // generate activation key $activationKey = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $salt); // set settings FrontendProfilesModel::setSetting($profileId, 'salt', $salt); FrontendProfilesModel::setSetting($profileId, 'activation_key', $activationKey); // login FrontendProfilesAuthentication::login($profileId); // activation URL $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $activationKey; // send email FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $values['email'], ''); // redirect $this->redirect(SELF . '?sent=true'); } catch (Exception $e) { // when debugging we need to see the exceptions if (SPOON_DEBUG) { throw $e; } // show error $this->tpl->assign('registerHasFormError', true); } } else { $this->tpl->assign('registerHasFormError', true); } } }
/** * Parse the general profiles info into the template. */ public static function parse() { // get the template $tpl = Spoon::get('template'); // logged in if (FrontendProfilesAuthentication::isLoggedIn()) { // get profile $profile = FrontendProfilesAuthentication::getProfile(); // display name set? if ($profile->getDisplayName() != '') { $tpl->assign('profileDisplayName', $profile->getDisplayName()); } else { $tpl->assign('profileDisplayName', $profile->getEmail()); } // show logged in $tpl->assign('isLoggedIn', true); } // ignore these url's in the querystring $ignoreUrls = array(FrontendNavigation::getURLForBlock('profiles', 'login'), FrontendNavigation::getURLForBlock('profiles', 'register'), FrontendNavigation::getURLForBlock('profiles', 'forgot_password')); // querystring $queryString = isset($_GET['queryString']) ? SITE_URL . '/' . urldecode($_GET['queryString']) : SELF; // check all ignore urls foreach ($ignoreUrls as $url) { // querystring contains a boeboe url if (stripos($queryString, $url) !== false) { $queryString = ''; break; } } // no need to add this if its empty $queryString = $queryString != '' ? '?queryString=' . urlencode($queryString) : ''; // useful urls $tpl->assign('loginUrl', FrontendNavigation::getURLForBlock('profiles', 'login') . $queryString); $tpl->assign('registerUrl', FrontendNavigation::getURLForBlock('profiles', 'register')); $tpl->assign('forgotPasswordUrl', FrontendNavigation::getURLForBlock('profiles', 'forgot_password')); }
/** * Login a profile. * * @return bool * @param int $profileId Login the profile with this id in. * @param bool[optional] $remember Should we set a cookie for later? */ public static function login($profileId, $remember = false) { // redefine vars $profileId = (int) $profileId; $remember = (bool) $remember; $secretKey = null; // cleanup old sessions self::cleanupOldSessions(); // set profile_logged_in to true SpoonSession::set('frontend_profile_logged_in', true); // should we remember the user? if ($remember) { // generate secret key $secretKey = FrontendProfilesModel::getEncryptedString(SpoonSession::getSessionId(), FrontendProfilesModel::getRandomString()); // set cookie SpoonCookie::set('frontend_profile_secret_key', $secretKey, 60 * 60 * 24 * 31); } // delete all records for this session to prevent duplicate keys (this should never happen) FrontendModel::getDB(true)->delete('profiles_sessions', 'session_id = ?', SpoonSession::getSessionId()); // insert new session record FrontendModel::getDB(true)->insert('profiles_sessions', array('profile_id' => $profileId, 'session_id' => SpoonSession::getSessionId(), 'secret_key' => $secretKey, 'date' => FrontendModel::getUTCDate())); // update last login FrontendProfilesModel::update($profileId, array('last_login' => FrontendModel::getUTCDate())); // load the profile object self::$profile = new FrontendProfilesProfile($profileId); }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtOldPassword = $this->frm->getField('old_password'); $txtNewPassword = $this->frm->getField('new_password'); // old password filled in? if ($txtOldPassword->isFilled(FL::getError('PasswordIsRequired'))) { // old password correct? if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtOldPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) { // set error $txtOldPassword->addError(FL::getError('InvalidPassword')); } // new password filled in? $txtNewPassword->isFilled(FL::getError('PasswordIsRequired')); } // no errors if ($this->frm->isCorrect()) { // update password FrontendProfilesAuthentication::updatePassword($this->profile->getId(), $txtNewPassword->getValue()); // trigger event FrontendModel::triggerEvent('profiles', 'after_profile_password', array('id' => $this->profile->getId())); // redirect $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'profile_password') . '?saved=true'); } else { $this->tpl->assign('updatePasswordHasFormError', true); } } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtPassword = $this->frm->getField('password'); $txtEmail = $this->frm->getField('email'); // password filled in? if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) { // password correct? if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) { // set error $txtPassword->addError(FL::getError('InvalidPassword')); } // email filled in? if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email already exists? if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) { // set error $txtEmail->setError(FL::getError('EmailExists')); } } } } // no errors if ($this->frm->isCorrect()) { // update email FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue())); // trigger event FrontendModel::triggerEvent('profiles', 'after_change_email', array('id' => $this->profile->getId())); // redirect $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'change_email') . '?sent=true'); } else { $this->tpl->assign('updateEmailHasFormError', true); } } }
/** * Get profile data. */ private function getData() { // get profile $this->profile = FrontendProfilesAuthentication::getProfile(); }
/** * Validate the form. * * @return void */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtPassword = $this->frm->getField('password'); // field is filled in? $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // valid if ($this->frm->isCorrect()) { // get profile id $profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $this->URL->getParameter(0)); // remove key (we can only update the password once with this key) FrontendProfilesModel::deleteSetting($profileId, 'forgot_password_key'); // update password FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue()); // login (check again because we might have logged in in the meanwhile) if (!FrontendProfilesAuthentication::isLoggedIn()) { FrontendProfilesAuthentication::login($profileId); } // trigger event FrontendModel::triggerEvent('profiles', 'after_reset_password', array('id' => $profileId)); // redirect $this->redirect(FrontendNavigation::getURLForBlock('profiles', 'reset_password') . '/' . $this->URL->getParameter(0) . '?saved=true'); } else { $this->tpl->assign('forgotPasswordHasError', true); } } }