public function action_add() { $this->template->title = "Add Dosen"; if (isset($_POST['nip'])) { $dosen = new Model_Dosen(); $user = new Model_User(); $user->username = $_POST['nip']; $user->password = $_POST['password']; $user->save(); // Masukkan role user $user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find()); $user->add('roles', ORM::factory('role')->where('name', '=', 'dosen')->find()); $dosen->nip = $_POST['nip']; $dosen->user_id = $user->id; $dosen->nama = $_POST['nama']; $dosen->tahun_masuk = $_POST['tahun_masuk']; $dosen->tempat_lahir = $_POST['tempat_lahir']; $tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal']; $dosen->tanggal_lahir = $tanggal_lahir; $dosen->jenis_kelamin = $_POST['jenis_kelamin']; $dosen->alamat = $_POST['alamat']; $dosen->no_hp = $_POST['no_hp']; $dosen->telp_rumah = $_POST['telp_rumah']; $dosen->email = $_POST['email']; $dosen->save(); } }
public function action_index() { $count = ORM::factory('User')->count_all(); if ($count === 0) { $this->template->content = View::factory('install/index'); if ($this->request->method() === Request::POST) { if (!Security::check($this->request->param('id'))) { throw new Exception("Bad token!"); } $post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', '8'))->rule('password2x', 'not_empty')->rule('password', 'matches', array(':validation', 'password', 'password2x')); if ($post->check()) { $user = new Model_User(); $post = $this->request->post(); $user->values($post)->save(); $adminRole = ORM::factory('Role')->where('name', '=', 'admin')->find(); $loginRole = ORM::factory('Role')->where('name', '=', 'login')->find(); $user->add('roles', $loginRole); $user->add('roles', $adminRole); $this->redirect('install/successful'); } else { $this->redirect('install/oops'); } } } else { $this->redirect(''); } }
public function action_add() { $this->template->title = "Add Mahasiswa"; if (isset($_POST['nim'])) { $mahasiswa = new Model_Mahasiswa(); $user = new Model_User(); $user->username = $_POST['nim']; // nimnya harus dicek dulu nih $user->password = $_POST['password']; $user->save(); // Masukkan role user $user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find()); $user->add('roles', ORM::factory('role')->where('name', '=', 'mahasiswa')->find()); $mahasiswa->nim = $_POST['nim']; // nimnya harus dicek dulu nih $mahasiswa->user_id = $user->id; $mahasiswa->nama = $_POST['nama']; $mahasiswa->tempat_lahir = $_POST['tempat_lahir']; $tanggal_lahir = $_POST['tahun'] . "-" . $_POST['bulan'] . "-" . $_POST['tanggal']; $mahasiswa->tanggal_lahir = $tanggal_lahir; $mahasiswa->jenis_kelamin = $_POST['jenis_kelamin']; $mahasiswa->email = $_POST['email']; $mahasiswa->alamat = $_POST['alamat']; $mahasiswa->no_hp = $_POST['no_hp']; $mahasiswa->nama_ayah = $_POST['nama_ayah']; $mahasiswa->telp_rumah = $_POST['telp_rumah']; $mahasiswa->tahun_masuk = $_POST['tahun_masuk']; $mahasiswa->status_kelulusan = 2; // belum lulus $mahasiswa->save(); } }
public function action_add() { $this->template->title = "Add User"; if (isset($_POST['username'])) { $user = new Model_User(); $user->username = $_POST['username']; $user->password = $_POST['password']; $user->save(); // Masukkan role user $user->add('roles', ORM::factory('role', $_POST['role'])); $role = new Model_Role($_POST['role']); if ($role->name != 'login') { $user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find()); } } $select_role = array(); $roles = new Model_Role(); $roles = $roles->find_all(); foreach ($roles as $role) { if ($role->name != 'dosen' && $role->name != 'mahasiswa') { $select_role[$role->id] = $role->name; } } $this->template->content->select_role = $select_role; }
/** * 创建用户 * @param array $userInfo 用户信息 * @return boolean */ public function createUser($userInfo) { $this->_modelUser = $this->_getGlobalData('Model_User', 'object'); $this->_modelUser->add($userInfo); $userInfo['Id'] = $this->_modelUser->returnLastInsertId(); $userClass = new Object_UserInfo(); $userClass->registerUserInfo($userInfo); $userClass->setUpdateInfo(1); $userClass = null; $this->_modelUser->createCache(); return true; }
/** * @BeforeSuite */ public static function prepare(SuiteEvent $event) { // Clear the user table. $query = DB::delete('users')->execute(); // Setup the test user for login. $user = new Model_User(); $user->username = '******'; $user->password = '******'; $user->email = '*****@*****.**'; $user->timezone_id = 1; $user->create(); $user->add('roles', Model_Role::LOGIN); }
public function action_index() { $view = View::factory('register'); if ($this->request->method() === Request::POST) { if (!Security::check($this->request->param('id'))) { throw new Exception("Bad token!"); } $post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('username', 'Model_User::is_username_taked')->rule('email', 'not_empty')->rule('email', 'Model_User::unique_email')->rule('email', 'email')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', '8'))->rule('password_again', 'not_empty')->rule('password', 'matches', array(':validation', 'password', 'password_again')); if ($post->check()) { $user = new Model_User(); $post = $this->request->post(); $user->values($post)->save(); // atrod role 'login' $loginRole = ORM::factory('Role')->where('name', '=', 'login')->find(); // pieliek klāt 'login' role litotājam $user->add('roles', $loginRole); $this->template->content = $view->bind('successful', $this->true); } else { $this->template->content = $view->bind('errors', $this->true); } } $this->template->content = $view->render(); }
public function action_adduser() { if (!empty($_SESSION['kids_id'])) { if (empty($_SESSION['kidsData'])) { $_SESSION['kidData'] = Helper_Mmdb::getUserData($_SESSION['kids_id']); } $user = new Model_User(); $userData = array(); $userData['username'] = Model_User::create_unique_display_name(); $userData['password'] = !empty($_SESSION['loginInfo']['password']) ? $_SESSION['loginInfo']['password'] : Model_User::create_unique_display_name(); $userData['password_confirm'] = $userData['password']; $userData['birthdate'] = $_POST['birthdate']; $userData['gender'] = $_POST['gender']; $userData['display_name'] = $_POST['display_name']; $userData['email'] = $_POST['email']; if (empty($_POST['vanity_url'])) { $userData['vanity_url'] = strtolower(preg_replace("/[^A-Za-z0-9 ]/", "-", $userData['display_name'])); } else { $userData['vanity_url'] = $_POST['vanity_url']; } //check vanity for uniqueness $checkVanity = ORM::factory("user")->where("vanity_url", "=", $userData['vanity_url'])->find(); $vanId = 1; while ($checkVanity->loaded()) { $checkVanity = ORM::factory("user")->where("vanity_url", "=", $userData['vanity_url'] . "-{$vanId}")->find(); if (!$checkVanity->loaded()) { $userData['vanity_url'] .= "-{$vanId}"; break; } $vanId++; } /* Load the validation rules, filters etc.*/ $post = $user->validate_create($userData); /* If the post data validates using the rules setup in the user model. */ if ($post->check()) { /* Affects the sanitized vars to the user object. */ $user->values($post); /* Create the account. */ $user->kids_id = $_SESSION['kids_id']; $user->save(); /* Add the login role to the user. */ $login_role = new Model_Role(array('name' => 'login')); $user->add('roles', $login_role); /* Add approval. */ $this->setup_approval($user); /* Sign the user in. */ Auth::instance()->login($post['username'], $post['password']); /* Redirect to the user account. */ Request::instance()->redirect('profile'); } else { /* Get errors for display in view. */ Message::set(Message::ERROR, $post->errors('user')); $this->action_merge(); } } else { Request::instance()->redirect('account/signin'); } }
protected function add_edit(Model_User &$user) { $errors = array(); $roles = ORM::factory('Role')->where('id', '!=', Model_User::LOGIN_ROLE_ID)->order_by('id')->find_all()->as_array('id'); if ($this->request->method() == Request::POST) { $data = $this->request->post(); $_data = $data; // operate on copy: $_data $email = $user->email; // keep email in the case od validation exception to restore this value in $user $external_validation = Validation::factory($_data)->labels(array('repeat_email' => 'Repeat e-mail'))->rules('roles', array(array('each_in_array', array(':value', array_keys($roles)))))->rules('repeat_email', array(array('matches', array(':validation', ':field', 'email')))); if ($user->loaded()) { if (empty($_data['email'])) { // no email while editing means: no changing but ORM model need email value to be not empty $_data['email'] = $user->email; } } else { $_data['password'] = Text::random('alnum', 14); // set random password for new user } try { $user->values($_data)->save($external_validation); } catch (ORM_Validation_Exception $vex) { $errors = $vex->errors('orm'); $user->email = $email; // restore original email value } // Manage roles for user: if (empty($errors)) { $user_roles = (array) Arr::get($data, 'roles', array()); foreach ($roles as $role) { // Adding: if (in_array($role->id, $user_roles) and !$user->has_role($role->id)) { $user->add('roles', $role); } // Removing: if (!in_array($role->id, $user_roles) and $user->has_role($role->id)) { $user->remove('roles', $role); } } if (!empty($data['send_hashlink'])) { $this->send_activation($user); } // finish saving return TRUE; } } else { if ($user->loaded()) { $data = $user->as_array(); $data['email'] = ''; $data['roles'] = array(); foreach ($roles as $role) { if ($user->has_role($role->id)) { $data['roles'][] = $role->id; } } } else { $data = array('send_hashlink' => '1'); } } $this->content = View::factory("users/edit")->bind("user", $user)->bind("roles", $roles)->bind("data", $data)->bind("errors", $errors); }