Exemplo n.º 1
0
 /**
  * Static Functions
  */
 public static function processExternal($provider, $user_profile, User $user = null)
 {
     $external = self::getRepository()->findOneBy(array('provider' => $provider, 'external_id' => $user_profile->identifier));
     // Locate a user account to associate.
     if ($user instanceof User) {
         // No additional processing.
     } elseif ($external instanceof self && $external->user instanceof User) {
         $user = $external->user;
     } elseif (!empty($user_profile->email)) {
         $user = User::getRepository()->findOneBy(array('email' => $user_profile->email));
         if (!$user instanceof User) {
             $user = new User();
             $user->email = $user_profile->email;
             $user->name = $user_profile->displayName;
             $user->avatar_url = $user_profile->photoURL;
             $user->generateRandomPassword();
             $user->save();
         }
     } else {
         // Not enough information to auto-create account; throw exception.
         throw new \PVL\Exception\AccountNotLinked();
     }
     // Create new external record (if none exists)
     if (!$external instanceof self) {
         // Create new external account and associate with the specified user.
         $external = new self();
         $external->provider = $provider;
         $external->external_id = $user_profile->identifier;
     }
     $external->user = $user;
     $external->name = $user_profile->displayName;
     $external->avatar_url = $user_profile->photoURL;
     $external->save();
     return $user;
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 /**
  * 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!');
 }
Exemplo n.º 4
0
 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');
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
// Force S3 enabled in development mode.
define('DF_UPLOAD_URL', 'dev.pvlive.me');
$s3_client = \PVL\Service\AmazonS3::initClient();
$s3_bucket = \PVL\Service\AmazonS3::getBucket();
if (!$s3_client) {
    die('Amazon S3 could not be initialized! Halting remote import.');
}
// Trigger download of the entire bucket to the local static folder.
$s3_client->downloadBucket(DF_INCLUDE_STATIC, $s3_bucket);
// Clean up S3 bucket.
$remote_url = $remote_base . '/dev/cleanup?key=' . $api_key;
// Prepare and execute mysqlimport command.
$db_path_full = DF_INCLUDE_STATIC . DIRECTORY_SEPARATOR . $db_path;
$db_config = $config->db->toArray();
$command_flags = array('-h ' . $db_config['host'], '-u ' . $db_config['user'], '-p' . $db_config['password'], $db_config['dbname']);
$command = 'mysql ' . implode(' ', $command_flags) . ' < ' . $db_path_full;
system($command);
@unlink($db_path_full);
@rmdir(dirname($db_path_full));
// Create initial user account.
$user = new User();
$user->email = '*****@*****.**';
$user->setAuthPassword('password');
$user->name = 'Administrator';
$role = Role::find(1);
if ($role instanceof Role) {
    $user->roles->add($role);
    $user->save();
}
echo 'Database and Amazon S3 import complete.' . PHP_EOL;
exit;