当前位置: 首页>>代码示例>>PHP>>正文


PHP User_Model::custom_validate方法代码示例

本文整理汇总了PHP中User_Model::custom_validate方法的典型用法代码示例。如果您正苦于以下问题:PHP User_Model::custom_validate方法的具体用法?PHP User_Model::custom_validate怎么用?PHP User_Model::custom_validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User_Model的用法示例。


在下文中一共展示了User_Model::custom_validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_custom_validate

 /**
  * Tests User_Model::custom_validate
  *
  * @test
  * @dataProvider provider_custom_validate
  */
 public function test_custom_validate($valid, $invalid)
 {
     // set up mock, for prevent_superadmin_modification
     $auth = $this->getMock('Auth', array('logged_in'));
     $auth->expects($this->exactly(2))->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(True));
     // Save initial data
     $initial_valid = $valid;
     $initial_invalid = $invalid;
     // Test with valid data
     $response = User_Model::custom_validate($valid, $auth);
     $this->assertEquals(TRUE, $valid instanceof Validation);
     $this->assertTrue($response, Kohana::debug($valid->errors()));
     // Test with invalid data
     $response = User_Model::custom_validate($invalid, $auth);
     $this->assertEquals(TRUE, $invalid instanceof Validation);
     $this->assertFalse($response);
     // restore valid, invalid
     $valid = $initial_valid;
     $invalid = $initial_invalid;
     // Test modification to superadmin as admin
     $auth = $this->getMock('Auth', array('logged_in'));
     $auth->expects($this->once())->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(False));
     $response = User_Model::custom_validate($valid, $auth);
     $this->assertTrue($valid instanceof Validation);
     $this->assertFalse($response, Kohana::debug($valid->errors()));
 }
开发者ID:nanangsyaifudin,项目名称:HAC-2012,代码行数:32,代码来源:User_Model_Test.php

示例2: test_custom_validate

 /**
  * Tests User_Model::custom_validate
  *
  * @test
  * @dataProvider provider_custom_validate
  */
 public function test_custom_validate($valid, $invalid)
 {
     // Test with valid data
     $response = User_Model::custom_validate($valid);
     $this->assertEquals(TRUE, $valid instanceof Validation);
     $this->assertTrue($response, Kohana::debug($valid->errors()));
     // Test with invalid data
     $response = User_Model::custom_validate($invalid);
     $this->assertEquals(TRUE, $invalid instanceof Validation);
     $this->assertFalse($response);
 }
开发者ID:rabbit09,项目名称:Taarifa_Web,代码行数:17,代码来源:User_Model_Test.php

示例3: edit

 /**
  * Edit a user
  * @param bool|int $user_id The id no. of the user
  * @param bool|string $saved
  */
 public function edit($user_id = FALSE, $saved = FALSE)
 {
     $this->template->content = new View('admin/users/edit');
     if ($user_id) {
         $user_exists = ORM::factory('user')->find($user_id);
         if (!$user_exists->loaded) {
             // Redirect
             url::redirect(url::site() . 'admin/users/');
         }
     }
     // Setup and initialize form field names
     $form = array('username' => '', 'name' => '', 'email' => '', 'password' => '', 'notify' => '', 'role' => '');
     $this->template->content->user_id = $user_id;
     if ($user_id == FALSE) {
         // Tack this on when adding a new user
         $form['password'] = '';
         $form['password_again'] = '';
     }
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $user = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Get the submitted data
         $post = $_POST;
         // Add the user_id to the $_POST data
         $user_id = $user_id ? $user_id : NULL;
         $post = array_merge($post, array('user_id' => $user_id));
         if (User_Model::custom_validate($post)) {
             $user = ORM::factory('user', $user_id);
             $user->name = $post->name;
             $user->email = $post->email;
             $user->notify = $post->notify;
             if ($user_id == NULL) {
                 $user->password = $post->password;
             }
             // We can only set a new password if we are using the standard ORM method,
             //    otherwise it won't actually change the password used for authentication
             if (isset($post->new_password) and Kohana::config('riverid.enable') == FALSE and strlen($post->new_password) > 0) {
                 $user->password = $post->new_password;
             }
             // Existing User??
             if ($user->loaded) {
                 // Prevent modification of the main admin account username or role
                 if ($user->id != 1) {
                     $user->username = $post->username;
                     // Remove Old Roles
                     foreach ($user->roles as $role) {
                         $user->remove($role);
                     }
                     // Add New Roles
                     if ($post->role != 'none') {
                         $user->add(ORM::factory('role', 'login'));
                         $user->add(ORM::factory('role', $post->role));
                     }
                 }
             } else {
                 $user->username = $post->username;
                 // Add New Roles
                 if ($post->role != 'none') {
                     $user->add(ORM::factory('role', 'login'));
                     $user->add(ORM::factory('role', $post->role));
                 }
             }
             $user->save();
             //Event for adding user admin details
             Event::run('ushahidi_action.users_add_admin', $post);
             Event::run('ushahidi_action.user_edit', $user);
             // Redirect
             url::redirect(url::site() . 'admin/users/');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
     } else {
         if ($user_id) {
             // Retrieve Current Incident
             $user = ORM::factory('user', $user_id);
             if ($user->loaded) {
                 // Some users don't have roles so we have this "none" role
                 $role = 'none';
                 foreach ($user->roles as $user_role) {
                     $role = $user_role->name;
                 }
                 $form = array('user_id' => $user->id, 'username' => $user->username, 'name' => $user->name, 'email' => $user->email, 'notify' => $user->notify, 'role' => $role);
             }
         }
     }
     $roles = ORM::factory('role')->where('id != 1')->orderby('name', 'asc')->find_all();
//.........这里部分代码省略.........
开发者ID:rjmackay,项目名称:Ushahidi_Web,代码行数:101,代码来源:users.php

示例4: edit

 /**
  * Edit a user
  * @param bool|int $user_id The id no. of the user
  * @param bool|string $saved
  */
 public function edit($user_id = FALSE, $saved = FALSE)
 {
     $this->template->content = new View('admin/users_edit');
     if ($user_id) {
         $user_exists = ORM::factory('user')->find($user_id);
         if (!$user_exists->loaded) {
             // Redirect
             url::redirect(url::site() . 'admin/users/');
         }
     }
     // Setup and initialize form field names
     $form = array('username' => '', 'password' => '', 'password_again' => '', 'name' => '', 'email' => '', 'notify' => '', 'role' => '');
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $user = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Get the submitted data
         $post = $_POST;
         // Add the user_id to the $_POST data
         $user_id = $user_id ? $user_id : NULL;
         $post = array_merge($post, array('user_id' => $user_id));
         if (User_Model::custom_validate($post)) {
             $user = ORM::factory('user', $user_id);
             $user->name = $post->name;
             $user->email = $post->email;
             $user->notify = $post->notify;
             // Existing User??
             if ($user->loaded == true) {
                 // Prevent modification of the main admin account username or role
                 if ($user->id != 1) {
                     $user->username = $post->username;
                     // Remove Old Roles
                     foreach ($user->roles as $role) {
                         $user->remove($role);
                     }
                     // Add New Roles
                     $user->add(ORM::factory('role', 'login'));
                     $user->add(ORM::factory('role', $post->role));
                 }
                 $post->password != '' ? $user->password = $post->password : '';
             } else {
                 $user->username = $post->username;
                 $user->password = $post->password;
                 // Add New Roles
                 $user->add(ORM::factory('role', 'login'));
                 $user->add(ORM::factory('role', $post->role));
             }
             $user->save();
             //Event for adding user admin details
             Event::run('ushahidi_action.users_add_admin', $post);
             Event::run('ushahidi_action.user_edit', $user);
             // Redirect
             url::redirect(url::site() . 'admin/users/');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
     } else {
         if ($user_id) {
             // Retrieve Current Incident
             $user = ORM::factory('user', $user_id);
             if ($user->loaded == true) {
                 foreach ($user->roles as $user_role) {
                     $role = $user_role->name;
                 }
                 $form = array('user_id' => $user->id, 'username' => $user->username, 'password' => '', 'password_again' => '', 'name' => $user->name, 'email' => $user->email, 'notify' => $user->notify, 'role' => $role);
             }
         }
     }
     $roles = ORM::factory('role')->where('id != 1')->orderby('name', 'asc')->find_all();
     $role_array = array("login" => "NONE");
     foreach ($roles as $role) {
         $role_array[$role->name] = strtoupper($role->name);
     }
     $this->template->content->id = $user_id;
     $this->template->content->display_roles = $this->display_roles;
     $this->template->content->user = $user;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     $this->template->content->role_array = $role_array;
 }
开发者ID:neumicro,项目名称:Ushahidi_Web_Dev,代码行数:96,代码来源:users.php


注:本文中的User_Model::custom_validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。