Beispiel #1
0
 public function action_create($id = null)
 {
     if (Input::method() == 'POST') {
         $users = Model_User::factory(array('username' => Input::post('username'), 'password' => Input::post('password'), 'email' => Input::post('email'), 'profile_fields' => Input::post('profile_fields'), 'group' => Input::post('group'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash')));
         if ($users and $users->save()) {
             Session::set_flash('notice', 'Added users #' . $users->id . '.');
             Response::redirect('users');
         } else {
             Session::set_flash('notice', 'Could not save users.');
         }
     }
     $this->template->title = "Users";
     $this->template->content = View::factory('users/create');
 }
 public function up()
 {
     \DBUtil::create_table('users', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'username' => array('constraint' => 255, 'type' => 'varchar'), 'password' => array('constraint' => 255, 'type' => 'varchar'), 'email' => array('constraint' => 255, 'type' => 'varchar'), 'profile_fields' => array('type' => 'text'), 'group' => array('constraint' => 11, 'type' => 'int'), 'last_login' => array('constraint' => 20, 'type' => 'int'), 'login_hash' => array('constraint' => 255, 'type' => 'varchar')), array('id'));
     // add an admin account
     $admin_username = "******";
     $admin_password = "******";
     $admin_pass_hash = \Auth::instance()->hash_password($admin_password);
     $admin_email = "*****@*****.**";
     $users = \Model_User::factory(array('username' => $admin_username, 'password' => $admin_pass_hash, 'email' => $admin_email, 'profile_fields' => '', 'group' => '', 'last_login' => '', 'login_hash' => ''));
     if ($users and $users->save()) {
         \Cli::write("added admin account");
     } else {
         \Cli::write("failed to add admin account");
     }
 }
 /**
  * User view
  */
 public function action_view($user = NULL)
 {
     // Temporary ALWAYS redirect
     $this->request->redirect('forum');
     if (empty($user)) {
         $this->template->content = $content = View::factory('user/list');
         $content->users = Sprig::factory('user')->select_list();
     } else {
         $user = Model_User::factory($user)->load();
         $this->template->title = html::chars($user->username) . 's profil hos Änglarna Stockholm';
         $this->template->content = $content = View::factory('user/view');
         $content->user = (object) $user->as_array();
         unset($content->user->password);
         // Set flag to show edit controls
         $content->owner = FALSE;
         if ($this->auth->logged_in()) {
             $content->owner = $user->id = $this->auth->get_user()->id;
         }
     }
 }
Beispiel #4
0
 /**
  * Load one user light array
  *
  * @static
  * @param   mixed  $id  User model, user array, user id, username
  * @return  array|null
  */
 public static function find_user_light($id = null)
 {
     $ckey = 'user_light_';
     if ($id instanceof Model_User) {
         // Got user model, no need to load, just fill caches
         /** @var  Model_User  $id */
         return $id->light_array();
     } else {
         if (is_array($id)) {
             // Got user array, don't fill caches as we're not 100% sure it's valid
             return $id;
         } else {
             if (is_int($id) || is_numeric($id)) {
                 // Got id
                 $id = (int) $id;
             } else {
                 if (is_string($id)) {
                     // Got user name, find id
                     $id = Model_User::user_id($id);
                 } else {
                     return null;
                 }
             }
         }
     }
     if ($id === 0) {
         return null;
     }
     // Try static cache
     $user = Anqh::cache_get($ckey . $id);
     if (!is_array($user)) {
         // Load from DB
         $user = Model_User::factory($id)->light_array();
         Anqh::cache_set($ckey . $id, $user, Date::DAY);
     }
     return $user;
 }
Beispiel #5
0
 /**
  * Convert a unique identifier string to a user object
  * 
  * @param mixed $user
  * @return Model_User
  */
 protected function _get_object($user)
 {
     if (!is_object($user)) {
         // Load the user using special factory method
         $user = Model_User::factory($user)->load();
     }
     return $user;
 }
Beispiel #6
0
 protected function _get_object($user)
 {
     if (!is_object($user)) {
         // Load the user
         $user = Model_User::factory($user)->load();
     }
     return $user;
 }