Beispiel #1
0
function createUser($password = null, $group = null)
{
    if (!$group) {
        $groupId = 3;
    } else {
        $groupId = $group['id'];
    }
    $user = new User(['name' => 'user-' . mkRandomHash(5) . '-name', 'username' => 'user-' . mkRandomHash(5) . '-username', 'email' => 'user-' . mkRandomHash(5) . '*****@*****.**', 'password' => $password ?: microtime(), 'group_id' => $groupId]);
    $user->save();
    return $user;
}
Beispiel #2
0
 /**
  * Migrate database and create admin account.
  */
 public function installAction()
 {
     // Create database connection and load migrations
     $connection = ConnectionManager::create($_SESSION['db']);
     $this->loadMigrations();
     // Migrate the database.
     $m = new Migrator();
     $m->migrate('up');
     // Create admin account
     $admin = new User($_SESSION['admin'] + ['name' => $_SESSION['admin']['username'], 'group_id' => 1]);
     $admin->save();
     // Set config file contents
     $this->set("config", $this->makeConfig());
     // Insert defaults
     $seeder = new Seeder();
     $seeder->seed();
     // Remove database and account details from the session.
     unset($_SESSION['db'], $_SESSION['admin']);
     $this->title("Complete");
     return $this->render("complete.phtml");
 }
Beispiel #3
0
 /**
  * Validate and create account.
  */
 public function createAction()
 {
     // Validate user
     $user = new User($this->userParams());
     // Check for errors
     if ($user->validate()) {
         $user->save();
         // Is email validation turned on?
         if (setting('email_validation')) {
             // Insert validation row
             $activationCode = random_hash();
             $this->db->insert(PREFIX . 'user_activation_codes', ['user_id' => $user->id, 'activation_code' => $activationCode, 'type' => 'email_validation']);
             // Send notification and render login form
             Notification::accountActivation($user, $activationCode)->send();
             return $this->render("sessions/new.phtml", ['activationRequired' => true]);
         }
         return $this->redirectTo('session_new');
     } else {
         $this->title($this->translate('register'));
         return $this->render('users/new.phtml', ['user' => $user]);
     }
 }
Beispiel #4
0
 /**
  * Creates the anonymous user and returns the ID.
  *
  * @return integer
  */
 protected function createAnonymousUser()
 {
     $password = rand(0, 9999) . time() . microtime();
     // For email validation, emails must match x@y.z
     $host = $_SERVER['HTTP_HOST'] == 'localhost' ? 'lvh.me' : $_SERVER['HTTP_HOST'];
     $user = new User(['name' => "Anonymous", 'username' => "Anonymous", 'password' => $password, 'password_confirmation' => $password, 'email' => "noreply@" . $host, 'group_id' => 3]);
     if (!$user->save()) {
         var_dump($user->errors());
     }
     return $user->id;
 }