/** * Handle the registration process includign the form salt check. * * @param string $username * @param string $password * @param string $repeatPassword * @param string $email * @param string $salt * * @return void */ protected function register($username, $password, $repeatPassword, $email, $salt) { if (!$salt || $salt != $_SESSION['formSalts']['register']) { return; } if (!$username || !$password || !$repeatPassword || !$email) { $this->template->assign('error', 'registerEmpty'); return; } if ($password !== $repeatPassword) { $this->template->assign('error', 'passwordsDontMatch'); return; } if (\SmartWork\User::checkUsername($username)) { $this->template->assign('error', 'usernameAlreadyInUse'); return; } if (\SmartWork\User::checkEmail($email)) { $this->template->assign('error', 'emailAlreadyInUse'); return; } if (\SmartWork\User::createUser($username, $password, $email)) { $this->template->assign('message', 'registrationSuccessful'); } else { $this->template->assign('error', 'registrationUnsuccessful'); } }
/** * Change the users password. * * @param string $password * @param string $repeatPassword * * @return void */ protected function changePassword($password, $repeatPassword) { if (!$password || !$repeatPassword) { $this->template->assign('errorPassword', 'emptyPasswordOptions'); return; } if ($password !== $repeatPassword) { $this->template->assign('errorPassword', 'passwordsDontMatch'); return; } $this->user->setPassword($password); $this->template->assign('messagePassword', 'passwordSuccess'); }
/** * Show the lost password form and init the lost password process. * * @return void */ public function process() { if (!$_POST['lostPassword'] || $_POST['lostPassword'] != $_SESSION['formSalts']['lostPassword']) { return; } if (!$_POST['email']) { $this->template->assign('error', 'emptyEmail'); return; } $user = \SmartWork\User::getUserByMail($_POST['email']); if ($user) { $user->lostPassword(); $this->template->assign('message', 'lostPasswordMailSent'); } else { $this->template->assign('error', 'lostPasswordNoUserFound'); } }
/** * Import a character from the Helden Software xml export. * * @return \Model\Character */ public function import() { $simplexml = simplexml_load_string($this->xml); /* @var $characterXml \SimpleXMLElement */ $characterXml = $simplexml->held; $characterAttributes = $characterXml->attributes(); $character = array('user' => \SmartWork\User::getUserById($_SESSION['userId']), 'key' => $characterAttributes['key'], 'lastUpdate' => \DateTime::createFromFormat('U', intval(floatval($characterAttributes['stand']) / 1000)), 'name' => $characterAttributes['name'], 'bowMaking' => 0, 'precisionMechanics' => 0, 'blacksmith' => 0, 'woodworking' => 0, 'leatherworking' => 0, 'tailoring' => 0); /* @var $talents \SimpleXMLElement */ $talents = $characterXml->talentliste; /* @var $talent \SimpleXMLElement */ foreach ($talents->talent as $talent) { $talentAttributes = $talent->attributes(); if (array_key_exists(strval($talentAttributes['name']), $this->talentMapping)) { $character[$this->talentMapping[strval($talentAttributes['name'])]] = intval($talentAttributes['value']); } } return \Model\Character::create($character); }
/** * Login process with check for the form salt, existing users and a password check. * * @param string $username * @param string $password * @param string $salt * * @return void */ protected function logIn($username, $password, $salt) { if (!$salt || $salt != $_SESSION['formSalts']['login']) { return; } if (!$username && !$password) { $this->template->assign('error', 'emptyLogin'); return; } $user = \SmartWork\User::getUser($username, $password); if ($user) { $_SESSION['userId'] = $user->getUserId(); $translator = \SmartWork\Translator::getInstance(); $translator->setCurrentLanguage($user->getLanguageId()); redirect('index.php?page=Index'); } else { $this->template->assign('error', 'invalidLogin'); } }
/** * Set the admin status of the given user to $status. * * @param integer $userId * @param boolean $status * * @return void */ protected function changeAdminStatus($userId, $status) { $user = \SmartWork\User::getUserById($userId); $user->setAdmin($status); }