本文整理汇总了PHP中Model_User::forge方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_User::forge方法的具体用法?PHP Model_User::forge怎么用?PHP Model_User::forge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_User
的用法示例。
在下文中一共展示了Model_User::forge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create
public function action_create()
{
$val = Model_User::validate('create');
if (Input::method() == 'POST') {
if ($val->run()) {
$user = Model_User::forge(array('username' => \Fuel\Core\Input::post('username'), 'email' => \Fuel\Core\Input::post('email'), 'group' => \Fuel\Core\Input::post('group'), 'password' => \Fuel\Core\Input::post('password'), 'first_name' => \Fuel\Core\Input::post('first_name'), 'last_name' => \Fuel\Core\Input::post('last_name'), 'target_billable' => \Fuel\Core\Input::post('target_billable'), 'target_unbillable' => \Fuel\Core\Input::post('target_unbillable')));
try {
if ($user and Auth\Auth::create_user($user->username, $user->password, $user->email, $user->group, array('fullname' => ''))) {
Session::set_flash('success', e('Added user #' . $user->id . '.'));
Response::redirect('admin/users');
} else {
Session::set_flash('error', e('Could not save user.'));
}
} catch (\SimpleUserUpdateException $ex) {
// duplicate email address
if ($ex->getCode() == 2) {
Fuel\Core\Session::set_flash('error', 'Email already exists.');
} elseif ($ex->getCode() == 3) {
Fuel\Core\Session::set_flash('error', 'Username already exists.');
} else {
Fuel\Core\Session::set_flash('error', $ex->getMessage());
}
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->set_global('user', new Model_User(array('id' => 0)), false);
$this->template->set_global('val', $val, false);
$this->template->set_global('groups', $this->get_groups_list());
$this->template->title = "Users";
$this->template->content = View::forge('admin/users/create');
}
示例2: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
$val->add_field('password', 'Password', 'required|min_length[8]|max_length[20]');
$val->add_field('password_re', 'Re-type Password', 'required|min_length[8]|max_length[20]');
if ($val->run()) {
if (Input::post('password') != Input::post('password_re')) {
Session::set_flash('error', 'Password is not matched.');
} else {
$user = Model_User::forge(array('username' => Input::post('username'), 'password' => Auth::instance()->hash_password(Input::post('password')), 'group' => Input::post('group'), 'email' => Input::post('email'), 'profile_fields' => Input::post('profile_fields'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash')));
if ($user and $user->save()) {
Session::set_flash('success', 'Added user #' . $user->id . '.');
Response::redirect('user');
} else {
Session::set_flash('error', 'Could not save user.');
}
}
} else {
$msg = '<ul>';
foreach ($val->error() as $field => $error) {
$msg .= '<li>' . $error->get_message() . '</li>';
}
$msg .= '</ul>';
Session::set_flash('error', $msg);
}
}
$this->theme->set_template('edit');
$this->theme->get_template()->set_global('current_menu', "Users", false);
$this->theme->get_template()->set_global('current_menu_desc', "จัดการผู้ใช้งาน CMS ทั้งหมดในระบบ", false);
$this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "Users", 'icon' => "fa-users", 'link' => Uri::create('user/index'), 'active' => false), array('title' => "Create", 'icon' => "", 'link' => "", 'active' => true)));
$this->theme->get_template()->set_global('menu', "create", false);
$this->theme->set_partial('sidebar', 'common/sidebar');
$this->theme->set_partial('left', 'user/create');
}
示例3: post_login
public function post_login()
{
$errors = [];
if (!Input::post('email')) {
$errors[] = 'Please include email';
}
if (!Input::post('password')) {
$errors[] = 'Please include password';
}
if (count($errors)) {
return $this->error($errors);
}
$val = Validation::forge();
$val->add('email', 'Email or Username')->add_rule('required');
$val->add('password', 'Password')->add_rule('required');
if ($val->run()) {
if ($user = Auth::validate_user(Input::post('email'), Input::post('password'))) {
$user = Model_User::forge($user);
if ($user->isDeactivated()) {
return $this->error(['User is deactivated.']);
} else {
if (!$user->isApproved()) {
return $this->error(['User is not yet approved, please contact admin to set year/course for student.']);
}
}
return $this->response(['success' => true, 'data' => $user]);
} else {
return $this->error(['Invalid username or password']);
}
}
}
示例4: _get_user
/**
* Check if the user is logged in and fetches their information
* if not then assign the guest info and pass it to the views.
*/
private function _get_user()
{
if (Cookie::get('_sess') and $user = Model_User::find('first', array('where' => array('login_hash' => Crypt::decode(Cookie::get('_sess')))))) {
$this->current_user = $user;
$this->current_user->_set_logged_in(true);
} else {
$this->current_user = Model_User::forge(array('username' => 'Guest', 'group_id' => 5));
$this->current_user->_set_logged_in(false);
}
$this->template->set_global('current_user', $this->current_user);
}
示例5: insert
public static function insert($data)
{
try {
$props = ['username' => $data['username'], 'email' => strtolower($data['email']), 'password' => Model_Service_Util::hash_password($data['password']), 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())];
$new = Model_User::forge($props);
$new->save();
return $new->id;
} catch (Exception $e) {
Log::write('ERROR', $e->getMessage());
return false;
}
}
示例6: action_register
public function action_register()
{
$this->title('Register');
$this->view = $this->theme->view('users/register');
$user = Model_User::forge();
$this->view->set('user', $user);
if (Input::param() != array()) {
$user->values(array('name' => Input::param('name'), 'username' => Input::param('username'), 'password' => Input::param('password'), 'email' => Input::param('email')));
if ($user->is_valid()) {
$user->save();
Response::redirect('login');
} else {
$this->view->errors = $user->errors();
}
}
}
示例7: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('username' => Input::post('username'), 'password' => Input::post('password'), 'group_id' => Input::post('group_id'), 'email' => Input::post('email'), 'last_login' => Input::post('last_login'), 'previous_login' => Input::post('previous_login'), 'login_hash' => Input::post('login_hash'), 'user_id' => Input::post('user_id')));
if ($user and $user->save()) {
Session::set_flash('success', 'Added user #' . $user->id . '.');
Response::redirect('user');
} else {
Session::set_flash('error', 'Could not save user.');
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->title = "Users";
$this->template->content = View::forge('user/create');
}
示例8: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('id' => Input::post('id'), 'password' => sha1(Input::post('password')), 'name' => Input::post('name'), 'sex' => Input::post('sex'), 'birth_station_id' => Input::post('birth_station_id')));
if ($user and $user->save()) {
Session::set_flash('success', 'Added user #' . $user->id . '.');
Response::redirect('user');
} else {
Session::set_flash('error', 'Could not save user.');
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->title = "Users";
$this->template->content = View::forge('user/create');
}
示例9: install
public static function install()
{
//\Migrate::latest();
// Insert the default settings and user groups
echo "\nInserting defaults...";
\DB::insert('settings')->columns(array('setting', 'value'))->values(array('title', 'LitePress'))->execute();
\DB::insert('settings')->columns(array('setting', 'value'))->values(array('theme', 'default'))->execute();
\DB::insert('settings')->columns(array('setting', 'value'))->values(array('validate_users', '0'))->execute();
$groups = array(array('Admin', 1, 1, 1, 1, 1), array('Author', 0, 1, 1, 1, 1), array('Reader', 0, 0, 0, 0, 0), array('Validating', 0, 0, 0, 0, 0), array('Guest', 0, 0, 0, 0, 0));
foreach ($groups as $group) {
$row = \Model_Group::forge(array('name' => $group[0], 'is_admin' => $group[1], 'is_author' => $group[2], 'create_articles' => $group[3], 'edit_articles' => $group[4], 'delete_articles' => $group[5]));
$row->save();
}
// Create an admin account
echo "\nCreating admin account...";
$admin_password = strtolower(substr(sha1(time() . rand(1, 100)), 0, 5));
$admin = \Model_User::forge(array('name' => 'Admin', 'username' => 'Admin', 'password' => $admin_password, 'email' => 'you@example.com', 'group_id' => 1));
$admin->save();
echo "\nAdmin account created,", "\nUsername: Admin\n", "Password: " . $admin_password;
}
示例10: action_create
public function action_create()
{
parent::has_access("add_user");
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('name' => Input::post('username'), 'password' => md5(Input::post('password')), 'access_level' => Input::post('access_level')));
if ($user and $user->save()) {
Session::set_flash('success', 'Added user #' . $user->id . '.');
Response::redirect('users');
} else {
Session::set_flash('error', 'Could not save user.');
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->title = "Users";
$this->template->content = View::forge('users/create');
}
示例11: action_register
public function action_register()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('username' => Input::post('username'), 'password' => Auth::instance()->hash_password(Input::post('password')), 'group' => 1, 'email' => Input::post('email'), 'fname' => Input::post('fname'), 'mname' => Input::post('mname'), 'lname' => Input::post('lname'), 'contact_num' => Input::post('contact_num'), 'address' => Input::post('address'), 'profile_pic' => Input::post('profile_pic'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash'), 'profile_fields' => Input::post('profile_fields')));
Upload::process(Config::get('upload_profile_picture'));
$user->profile = Model_Student::forge(['year_level' => 0, 'course_id' => 0]);
if (Upload::is_valid()) {
Upload::save();
$value = Upload::get_files();
foreach ($value as $files) {
$user->profile_pic = $value[0]['saved_as'];
}
if ($user and $user->save()) {
Session::set_flash('success', e('Succesfully Added user #' . $user->id . '.'));
Response::redirect('site/login');
} else {
Session::set_flash('error', e('Could not save user.'));
}
} else {
Session::set_flash('error', e('Uploaded photo is invalid.'));
}
// if ($user and $user->save())
// {
// Session::set_flash('success', e('Succesfully Added user #'.$user->id.'.'));
// Response::redirect('site/login');
// }
// else
// {
// Session::set_flash('error', e('Could not save user.'));
// }
} else {
Session::set_flash('error', $val->error());
}
}
// $this->template->title = "Users";
// $this->template->content = View::forge('admin/users/create');
$this->template->title = 'Register';
$this->template->content = View::forge('site/register');
}
示例12: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('username' => Input::post('username'), 'email' => Input::post('email'), 'group' => Input::post('group'), 'description' => Input::post('description'), 'id_number' => Input::post('id_number'), 'employee_number' => Input::post('employee_number'), 'date_of_birth' => Input::post('date_of_birth'), 'user_type_id' => Input::post('user_type_id'), 'access_options' => Input::post('access_options'), 'phone' => Input::post('phone')));
if ($user and $user->save()) {
Session::set_flash('success', e('Added user #' . $user->id . '.'));
Response::redirect('admin/users');
} else {
Session::set_flash('error', e('Could not save user.'));
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->set_global('user_types', Model_User_Type::find('all', array('order_by' => array(array('name', 'asc')))));
$this->template->set_global('groups', $this->get_groups());
$this->template->title = "Users";
$this->template->content = View::forge('admin/users/create');
}
示例13: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_User::validate('create');
if ($val->run()) {
$user = Model_User::forge(array('username' => Input::post('username'), 'password' => Auth::instance()->hash_password(Input::post('password')), 'group' => 50, 'email' => Input::post('email'), 'fname' => Input::post('fname'), 'mname' => Input::post('mname'), 'lname' => Input::post('lname'), 'contact_num' => Input::post('contact_num'), 'address' => Input::post('address'), 'profile_pic' => Input::post('profile_pic'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash'), 'profile_fields' => Input::post('profile_fields')));
if ($user and $user->save()) {
Session::set_flash('success', e('Added user #' . $user->id . '.'));
Response::redirect('site/users');
} else {
Session::set_flash('error', e('Could not save user.'));
}
} else {
Session::set_flash('error', $val->error());
}
}
// Global variables
$teachers = Model_User::get_list_of_teachers();
$this->template->set_global('teachers', $teachers, false);
$this->template->title = "Users";
$this->template->content = View::forge('site/users/create');
}
示例14: array
<?php
use Model_User;
$seeds = array(array('email' => 'shimma@aucfan.com', 'password' => \Auth::hash_password('shimma@aucfan.com'), 'last_name' => '新間', 'last_name_kana' => 'シンマ', 'first_name' => '楽市', 'first_name_kana' => 'ラクイチ', 'nick_name' => 'てすと', 'gender' => 1, 'prefecture_id' => 40, 'zip' => '160-0001', 'tel' => '03-1212-1212', 'address' => '東京都渋谷区道玄坂1-14-6 ヒューマックス渋谷ビル6階', 'mm_flag' => 1, 'register_status' => \REGISTER_STATUS_ACTIVATED), array('email' => 'h_kobayashi@aucfan.com', 'password' => \Auth::hash_password('h_kobayashi@aucfan.com'), 'last_name' => '小林', 'last_name_kana' => 'コバヤシ', 'first_name' => '楽市', 'first_name_kana' => 'ラクイチ', 'nick_name' => 'テスト', 'prefecture_id' => 13, 'zip' => '144-1121', 'tel' => '03-1369-2480', 'gender' => 2, 'address' => '東京都渋谷区道玄坂1-14-6 ヒューマックス渋谷ビル6階', 'mm_flag' => 1, 'register_status' => \REGISTER_STATUS_ACTIVATED), array('email' => 'ida@aucfan.com', 'password' => \Auth::hash_password('ida@aucfan.com'), 'last_name' => '井田', 'last_name_kana' => 'イダ', 'first_name' => '楽市', 'first_name_kana' => 'ラクイチ', 'nick_name' => 'テスト', 'prefecture_id' => 31, 'zip' => '160-0001', 'tel' => '03-1212-1212', 'gender' => 2, 'address' => '東京都渋谷区道玄坂1-14-6 ヒューマックス渋谷ビル6階', 'mm_flag' => 1, 'register_status' => \REGISTER_STATUS_ACTIVATED), array('email' => 'ichiba@aucfan.com', 'password' => \Auth::hash_password('ichiba@aucfan.com'), 'last_name' => '市場', 'last_name_kana' => 'イチバ', 'first_name' => '楽市', 'first_name_kana' => 'ラクイチ', 'nick_name' => 'テスト', 'prefecture_id' => 31, 'zip' => '160-0001', 'tel' => '03-1212-1212', 'gender' => 2, 'address' => '東京都渋谷区道玄坂1-14-6 ヒューマックス渋谷ビル6階', 'mm_flag' => 1, 'register_status' => \REGISTER_STATUS_ACTIVATED));
foreach ($seeds as $line) {
\Model_User::forge($line)->save();
}
示例15: registerUser
/**
* ユーザ情報の登録
*
* @access private
* @param
* @return object
* @author kobayashi
* @author ida
*/
private function registerUser()
{
$data = $this->getUserData();
if (!$data) {
throw new Exception(\Model_Error::ER00402);
}
$user_id = \Input::post('user_id');
if (!empty($user_id)) {
$user = \Model_User::find(\Input::post('user_id'));
} else {
$user = \Model_User::forge();
}
$administrator_id = $this->administrator->administrator_id;
if (!empty($user_id)) {
$data['updated_user'] = $administrator_id;
unset($data['password']);
unset($data['created_at']);
unset($data['created_user']);
} else {
$data['created_user'] = $administrator_id;
$data['password'] = \Auth::hash_password($data['password']);
}
unset($data['mm_device']);
unset($data['mm_error_flag']);
unset($data['mobile_carrier']);
unset($data['mobile_uid']);
unset($data['last_login']);
$user->set($data)->save();
return $user;
}