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


PHP Model_User::values方法代码示例

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


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

示例1: action_index

 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('');
     }
 }
开发者ID:reGative,项目名称:Phorumph,代码行数:27,代码来源:Install.php

示例2: action_index

 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();
 }
开发者ID:reGative,项目名称:Phorumph,代码行数:23,代码来源:Register.php

示例3: action_adduser

 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');
     }
 }
开发者ID:natgeo,项目名称:kids-myshot,代码行数:58,代码来源:account.php

示例4: add_edit

 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);
 }
开发者ID:woduda,项目名称:kohana-dashboard,代码行数:62,代码来源:Users.php


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