public function registerAction() { if (!$_POST) { $this->forceSecure(); } $form = new \DF\Form($this->current_module_config->forms->register); if ($_POST) { if ($form->isValid($_POST)) { $data = $form->getValues(); $existing_user = User::getRepository()->findOneBy(array('email' => $data['email'])); if ($existing_user instanceof User) { $this->alert('A user with that e-mail address already exists!', 'red'); } else { $new_user = new User(); $new_user->fromArray($data); $new_user->save(); $login_credentials = array('username' => $data['email'], 'password' => $data['auth_password']); $login_success = $this->auth->authenticate($login_credentials); $this->alert('<b>Your account has been successfully created.</b><br>You have been automatically logged in to your new account.', 'green'); $default_url = \DF\Url::route(array('module' => 'default')); $this->redirectToStoredReferrer('login', $default_url); return; } } } $this->view->title = 'Create New Account'; $this->renderForm($form); }
/** * dev:deploy */ public function deployAction() { if (FA_APPLICATION_ENV == "production") { die('Not in a development environment!'); } // Create an admin user. $user = new User(); $user->fromArray(array('username' => 'admin', 'password' => 'admin', 'fullname' => 'Local Administrator', 'seeadultart' => Upload::RATING_ADULT, 'birthday' => date('Y-m-d', strtotime('-21 years')), 'regbdate' => date('Y-m-d', strtotime('-21 years')), 'email' => '*****@*****.**', 'regemail' => '*****@*****.**', 'access_level' => User::LEGACY_ACL_ADMINISTRATOR)); $user->save(); $this->printLn('Local administrator account ("admin" / "admin") created!'); }
public function editAction() { $form = new \DF\Form($this->current_module_config->forms->user_edit->form); if ($this->hasParam('id')) { $record = User::find($this->getParam('id')); $record_defaults = $record->toArray(TRUE, TRUE); unset($record_defaults['auth_password']); $form->setDefaults($record_defaults); } if (!empty($_POST) && $form->isValid($_POST)) { $data = $form->getValues(); if (!$record instanceof User) { $record = new User(); } $record->fromArray($data); $record->save(); $this->alert('User updated.', 'green'); $this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'csrf' => NULL)); return; } $this->renderForm($form, 'edit', 'Edit Record'); }
public function verifyAction() { if (!$this->hasParam('code')) { throw new \FA\Exception('No verification code was provided! Your e-mail should have included a verification code.'); } $code = $this->getParam('code'); $rr = RegistrationRequest::validate($code); if (!$rr instanceof RegistrationRequest) { throw new \FA\Exception('Your verification code could not be validated. The code may have expired, or already been used.'); } $form = new \FA\Form($this->current_module_config->forms->register_complete); $form->setDefaults(array('username' => $rr->username, 'email' => $rr->email)); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $bday_timestamp = strtotime($data['birthday'] . ' 00:00:00'); $bday_threshold = strtotime('-13 years'); // Rebuild the birthday into this format (in case it wasn't provided this way by the browser). $data['birthday'] = date('Y-m-d', $bday_timestamp); if ($bday_timestamp == 0) { $form->addError('birthday', 'We could not process your birthday as specified. Please try again.'); } if ($bday_timestamp >= $bday_threshold) { $form->addError('birthday', 'Our site cannot accept users under 13 years of age due to United States federal law, 15 USC 6501-6506.'); } if (!$form->hasErrors()) { $user = new User(); $user->fromArray(array('username' => $rr->username, 'password' => $data['password'], 'birthday' => $data['birthday'], 'fullname' => $data['fullname'], 'email' => $rr->email, 'regemail' => $rr->email, 'regbdate' => str_replace('-', '', $data['birthday']))); $user->save(); $rr->is_used = true; $rr->save(); // Create "skeleton" art folder. $app_cfg = $this->config->application; $user_art_dir = $app_cfg->art_path . '/' . $user->lower; @mkdir($user_art_dir); foreach ($app_cfg->art_folders as $art_folder) { $art_folder_path = $user_art_dir . '/' . $art_folder; @mkdir($art_folder_path); } // Log in the user. $this->auth->setUser($user); $this->alert('<b>Welcome to FurAffinity!</b><br>Your account has been created, and you are now logged in to the web site.', 'green'); return $this->redirectHome(); // return $this->view->pick('register/welcome'); } } $this->view->title = 'Complete New Account Creation'; return $this->renderForm($form); }