public function indexAction() { // Initialize the form. $form = new \FA\Form($this->current_module_config->forms->settings_account->toArray()); // Set form defaults based on current user database records. $form->setDefaults(array_merge($this->user->toArray(FALSE, TRUE), array('birthday' => $this->user->getBirthday()), $this->user->getVariables())); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); // Check for new password. if (!empty($data['new_password'])) { if (strcmp($data['new_password'], $data['new_password_confirm'])) { $form->addError('new_password_confirm', 'The two passwords did not match.'); } if (strlen($data['new_password']) < 6) { $form->addError('new_password', 'Passwords must be at least 6 characters long.'); } // Add the password to the information to be changed if valid. $data['user']['password'] = $data['new_password']; } if (!$form->hasErrors()) { // Load data directly into DB models using the fromArray helpers. $this->user->fromArray($data['user']); $this->user->setVariables($data['vars']); $this->em->persist($this->user); // Push any model changes to the DB. $this->em->flush(); $this->alert('<b>Settings updated!</b><br>Your changes have been saved.', 'green'); return $this->redirectHere(); } } $this->view->form = $form; }
public function indexAction() { $form = new \FA\Form($this->current_module_config->forms->recover); if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); $data['email'] = mb_strtolower($data['email'], 'UTF-8'); $user = User::getRepository()->findOneBy(array('username' => $data['username'], 'email' => $data['email'])); if ($user instanceof User) { $user->lostpw = \FA\Legacy\Utilities::uuid(); $user->save(); \FA\Messenger::send(array('to' => $user->email, 'subject' => 'Password Recovery Code', 'template' => 'account_recover', 'vars' => array('id' => $user->id, 'code' => $user->lostpw))); $this->alert('<b>A password recovery link has been sent to your e-mail address.</b><br>Click the link in the e-mail to reset your password.', 'green'); return $this->redirectHome(); } else { $form->addError('username', 'We could not locate an account with this username and e-mail address in our system. Please try again!'); } } $this->view->setVar('title', 'Forgot My Password'); return $this->renderForm($form); }
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); }