public function register() { $action = Request::get(1, VAR_URI); $min_year = date('Y') - 110; $max_year = date('Y') - 8; $countries = CmsTools::getCountries(); $options = $this->getFieldValidation($countries, $min_year, $max_year); $this->enableClientFormValidation($options); $this->breadcrumb->add('Registrieren'); $this->header(); if (Me::get()->loggedIn()) { CmsPage::error('Sie sind bereits registriert!'); } else { // Don't validate the captcha via ajax as the session would end if (Config::get('captcha.enable')) { Core::loadClass('Core.Security.ReCaptcha'); $options['recaptcha_response_field'] = array(Validator::MESSAGE => 'Der Sicherheitscode wurde nicht korrekt eingegeben.', Validator::CALLBACK => 'cb_captcha_check'); } $error = array(); $data = array_fill_keys(array_keys($options), ''); if ($action == 'send') { extract(Validator::checkRequest($options)); if (count($error) > 0) { CmsPage::error($error); } else { // Insert data $dt = new DT(); $dt->setDate($data['birthyear'], $data['birthmonth'], $data['birthday']); $data['birth'] = $dt->dbDate(); $data['pw1'] = Hash::generate($data['pw1']); $data['group_id'] = UserPages::DEFAULT_MEMBER_GID; $data['regdate'] = time(); if (Config::get('security.validate_registered_email') == 1) { $data['active'] = 0; $data['verification'] = Hash::getRandom(); } else { $data['active'] = 1; $data['verification'] = ''; } $db = Database::getObject(); $db->query("\n\t\t\t\t\t\tINSERT INTO <p>user\n\t\t\t\t\t\t(forename, surname, pw, group_id, email, gender, birth, city, country, regdate, active, verification)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(<forename>, <surname>, <pw1>, <group_id:int>, <email>, <gender>, <birth>, <city>, <country>, <regdate:int>, <active:int>, <verification>)\n\t\t\t\t\t", $data); $mid = $db->insertID(); $tpl = Response::getObject()->getTemplate('Cms/mails/register' . iif(!$data['active'], '_confirm')); $tpl->assign('mid', $mid, false); $tpl->assign('name', UserUtils::getSalutation($data['gender'], $data['forename'], $data['surname']), false); $tpl->assign('data', $data, false); CmsTools::sendMail($data['email'], 'Betätigung der Anmeldung bei ' . Config::get('general.title'), $tpl->parse()); CmsPage::ok("Sie haben sich erfolgreich registriert." . iif(!$data['active'], ' Bitte aktivieren Sie Ihren Account, in dem Sie auf den Link klicken, der Ihnen an Ihre E-Mail-Adresse geschickt wurde.'), URI::build('Cms/user/login')); } } if ($action != 'send' || count($error) > 0) { $tpl = Response::getObject()->appendTemplate('Cms/user/register'); $tpl->assign('data', $data); $tpl->assign('r_birthday', range(1, 31)); $tpl->assign('r_birthmonth', range(1, 12)); $tpl->assign('r_birthyear', range($min_year, $max_year)); $tpl->assign('countries', $countries); if (Config::get('captcha.enable')) { $tpl->assign('captcha', recaptcha_get_html(Config::get('captcha.public_key')), false); } $tpl->output(); } } $this->footer(); }
public function edit() { $id = Request::get(1, VAR_INT); $action = Request::get(2, VAR_URI); $this->breadcrumb->add('Bearbeiten'); $this->header(); $member = UserUtils::getById($id); if ($member === null) { CmsPage::error('Das angeforderte Mitglied wurde leider nicht gefunden.'); $this->members(); } else { $min_year = date('Y') - 110; $max_year = date('Y') - 8; $countries = CmsTools::getCountries(); $db = Database::getObject(); $db->query("SELECT id, title FROM <p>group WHERE registered = 1 ORDER BY admin ASC, editor ASC, title"); $groups = array(); while ($row = $db->fetchAssoc()) { $groups[$row['id']] = $row['title']; } $options = UserPages::getFieldValidation($countries, $min_year, $max_year); $options['pw1'][Validator::OPTIONAL] = true; $options['email'] = array(Validator::MULTIPLE => array(array(Validator::MESSAGE => 'Die E-Mail-Adresse ist nicht korrekt.', Validator::CALLBACK => Validator::CB_MAIL), array(Validator::MESSAGE => 'Diese E-Mail-Adresse ist bereits registriert.', Validator::CLOSURE => function ($mail) use($id) { $other = UserUtils::getByEmail($mail); return !($other !== null && $id != $other->getId()); }))); if (Me::get()->getId() != $id) { $options['group_id'] = array(Validator::MESSAGE => 'Die Gruppe ist nicht gültig.', Validator::LIST_CS => array_keys($groups)); $options['active'] = array(Validator::OPTIONAL => true, Validator::EQUALS => 1, Validator::VAR_TYPE => VAR_INT); } $error = array(); $data = array(); if ($action == 'send') { extract(Validator::checkRequest($options)); if (count($error) > 0) { CmsPage::error($error); } else { // Update data if (!empty($data['pw1']) && !empty($data['pw2'])) { $data['pw'] = Hash::generate($data['pw1']); } // prepare SQL update $sql = $data; unset($sql['pw1'], $sql['pw2'], $sql['birthday'], $sql['birthmonth'], $sql['birthyear']); if (Me::get()->getId() == $id) { unset($sql['group_id'], $sql['active']); // Don't allow to change own group or active state } $dt = new DT(); $dt->setDate($data['birthyear'], $data['birthmonth'], $data['birthday']); $sql['birth'] = $dt->dbDate(); $update = array(); foreach ($sql as $field => $value) { $update[] = "{$field} = <{$field}>"; } $update = implode(', ', $update); $sql['id'] = $id; $db->query("UPDATE <p>user SET {$update} WHERE id = <id:int>", $sql); // Update global data about me Session::getObject()->refreshMe(); CmsPage::ok("Ihre Angaben wurden erfolgreich gespeichert."); } } $user = $member->getArray(); $user = array_merge($user, $data); $tpl = Response::getObject()->appendTemplate("Cms/admin/members_edit"); $tpl->assign('user', $user); $tpl->assign('r_birthday', range(1, 31)); $tpl->assign('r_birthmonth', range(1, 12)); $tpl->assign('r_birthyear', range($min_year, $max_year)); $tpl->assign('countries', $countries); $tpl->assign('groups', $groups); $tpl->output(); } $this->footer(); }