本文整理汇总了PHP中User_Model::add方法的典型用法代码示例。如果您正苦于以下问题:PHP User_Model::add方法的具体用法?PHP User_Model::add怎么用?PHP User_Model::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User_Model
的用法示例。
在下文中一共展示了User_Model::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
$this->template->content = new View('users/create');
$form = new Validation($_POST);
$form->pre_filter('trim', true);
$form->add_rules('username', 'required')->add_rules('password', 'required')->add_rules('email', 'required', 'valid::email');
$this->template->content->repopulate = $form;
if ($form->validate()) {
// Create new user
$user = new User_Model();
if (!$user->username_exists($this->input->post('username'))) {
foreach ($form->as_array() as $key => $val) {
// Set user data
$user->{$key} = $val;
}
if ($user->validate($form->as_array())) {
if ($user->add(ORM::factory('role', 'login')) and $user->save()) {
// Redirect to the login page
url::redirect('login');
}
}
}
}
// Error
$this->template->content->error = $form->errors('login');
}
示例2: _edit
/**
* Edit basic info
*/
public function _edit()
{
$this->tab_id = 'profile';
$this->history = false;
// only owner or admin
if ($this->member->id !== $this->user->id && !$this->visitor->logged_in('admin')) {
url::back('members');
}
$form_errors = array();
$form_values = $this->member->as_array();
// check post
if (request::method() == 'post') {
$post = array_merge($this->input->post(), $_FILES);
$extra = array();
// location
if (empty($post['address_street']) && empty($post['address_city'])) {
// empty address, clear location
$extra['latitude'] = 0;
$extra['longitude'] = 0;
} else {
if ($post['address_street'] != $this->member->address_street || $post['address_city'] != $this->member->address_city) {
// update location
list($extra['latitude'], $extra['longitude']) = Gmap::address_to_ll(implode(', ', array($post['address_street'], $post['address_zip'], $post['address_city'])));
}
}
if ($this->member->validate($post, true, $extra)) {
// handle picture upload
if (isset($post->image) && empty($post->image['error'])) {
$image = Image_Model::factory('members.image', $post->image, $this->member->id);
if ($image->id) {
$this->member->add($image);
$this->member->default_image_id = $image->id;
$this->member->save();
}
}
url::redirect(url::user($this->member));
} else {
$form_errors = $post->errors();
}
$form_values = arr::overwrite($form_values, $post->as_array());
}
// City autocomplete
$this->_autocomplete_city('address_city');
// Date pickers
widget::add('footer', html::script_source("\$('input#dob').datepicker({ dateFormat: 'd.m.yy', firstDay: 1, changeFirstDay: false, showOtherMonths: true, showStatus: true, showOn: 'both', minDate: '-60Y', maxDate: 0 });"));
if (empty($errors)) {
widget::add('main', View::factory('member/info_edit', array('values' => $form_values, 'errors' => $form_errors)));
} else {
$this->_error(Kohana::lang('generic.error'), $errors);
}
$this->_side_views();
}
示例3: testAdminAccess
public function testAdminAccess()
{
// not logged in: return false
$this->assertFalse(Auth::instance()->admin_access());
// Login role : return false
$user = new User_Model();
$user->add(ORM::factory('role', 'login'));
$this->assertFalse(Auth::instance()->admin_access($user));
// member: return false
$user = new User_Model();
$user->add(ORM::factory('role', 'member'));
$this->assertFalse(Auth::instance()->admin_access($user));
// admin: return true
$user = new User_Model();
$user->add(ORM::factory('role', 'admin'));
$this->assertTrue(Auth::instance()->admin_access($user));
// superadmin: return false
$user = new User_Model();
$user->add(ORM::factory('role', 'superadmin'));
$this->assertTrue(Auth::instance()->admin_access($user));
// Test custom role/permission
$user = new User_Model();
$user->add(ORM::factory('role', 'phpunit'));
$this->assertFalse(Auth::instance()->admin_access($user));
$user->add(ORM::factory('role', 'phpunit_admin'));
$this->assertTrue(Auth::instance()->admin_access($user));
}
示例4: _join
/**
* Register with code
*
* @param Invitation_Model $invitation
*/
public function _join(Invitation_Model $invitation)
{
$this->history = false;
$user = new User_Model();
$form_values = $user->as_array();
$form_errors = array();
// handle post
if (request::method() == 'post') {
$post = $this->input->post();
$post['email'] = $invitation->email;
$post['username_clean'] = utf8::clean($post['username']);
if ($user->validate($post, false, null, null, array('rules' => 'register', 'callbacks' => 'register'))) {
$invitation->delete();
$user->add(ORM::factory('role', 'login'));
$user->save();
$this->visitor->login($user, $post->password);
url::back();
} else {
$form_errors = $post->errors();
$form_values = arr::overwrite($form_values, $post->as_array());
}
}
widget::add('main', View::factory('member/signup', array('values' => $form_values, 'errors' => $form_errors, 'invitation' => $invitation)));
}