Example #1
0
 public function itShouldBeCorrectName()
 {
     App::import('Model', 'User');
     $user = new User();
     $ret = $user->create(array('name' => 'cakephp'));
     $ret = $user->validates();
     $this->spec($user->validates())->should->beTrue();
 }
 private function createNewUser()
 {
     $username = $this->facebookUser['first_name'] . $this->facebookUser['last_name'] . rand(0, 9999);
     $this->Users->clear();
     $this->Users->set(array('User' => array('email' => $this->facebookUser['email'], 'username' => $username, 'facebook_id' => $this->facebookUser['id'])));
     if ($this->Users->validates()) {
         $this->user = $this->Users->save($this->Users->data, false, array('id', 'email', 'username', 'facebook_id'));
         if (!$this->user) {
             throw new Exception('Internal error');
         }
     } else {
         $errors = $this->Users->validationErrors;
         throw new Exception($errors[0]);
     }
 }
Example #3
0
File: user.php Project: taq/torm
    }
    public function afterInitialize()
    {
        if (is_null($this->name)) {
            $this->name = "Unnamed User";
        }
    }
}
User::setOrder("name");
User::validates("name", array("presence" => true));
User::validates("name", array("format" => "^[\\p{L},]{2,} [\\p{L}\\s\\.]{2,}"));
User::validates("email", array("presence" => true));
User::validates("email", array("format" => "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})\$"));
User::validates("email", array("uniqueness" => true, "allow_null" => true, "allow_blank" => true));
User::validates("user_level", array("numericality" => true));
User::validates("code", array("format" => "^[0-9]{5}\$", "allow_null" => true));
User::hasMany("tickets", array("class_name" => "Ticket"));
User::hasOne("account");
User::beforeSave("before_save");
User::beforeSave("strip_invalid");
User::afterSave("after_save");
User::beforeDestroy("before_destroy");
User::afterDestroy("after_destroy");
User::beforeCreate("before_create");
User::afterCreate("after_create");
User::beforeUpdate("before_update");
User::afterUpdate("after_update");
User::scope("first_level", array("user_level" => 1));
User::scope("by_level", function ($args) {
    return "user_level=" . $args[0];
});
 public function employee_data_validates($user_data, $row)
 {
     $user = new User();
     $user->set($user_data["User"]);
     $emp_data_valid = true;
     if (!$user->validates(array('fieldList' => array('email', 'password')))) {
         $emp_data_valid = false;
         foreach ($user->validationErrors as $field_errors) {
             foreach ($field_errors as $field_error) {
                 $this->sheet_errors[] = $field_error . " at in USER sheet at row number " . $row;
             }
         }
     }
     return $emp_data_valid;
 }
 /**
  * Step 4: データベース生成/管理者ユーザー作成
  *
  * @return void
  * @access public
  */
 function step4()
 {
     if (!$this->data) {
         $this->data = $this->_getDefaultValuesStep4();
     } else {
         // ユーザー情報をセッションに保存
         $this->Session->write('Installation.admin_email', $this->data['Installation']['admin_email']);
         $this->Session->write('Installation.admin_username', $this->data['Installation']['admin_username']);
         $this->Session->write('Installation.admin_password', $this->data['Installation']['admin_password']);
         if ($this->data['clicked'] == 'back') {
             $this->redirect('step3');
         } elseif ($this->data['clicked'] == 'finish') {
             // DB接続
             $db =& $this->_connectDb($this->_readDbSettingFromSession());
             // サイト基本設定登録
             App::import('Model', 'SiteConfig');
             $siteConfig['SiteConfig']['email'] = $this->data['Installation']['admin_email'];
             $SiteConfigClass = new SiteConfig();
             $SiteConfigClass->saveKeyValue($siteConfig);
             // 管理ユーザー登録
             $salt = $this->_createKey(40);
             Configure::write('Security.salt', $salt);
             $this->Session->write('Installation.salt', $salt);
             App::import('Model', 'User');
             $User = new User();
             $user['User']['name'] = $this->data['Installation']['admin_username'];
             $user['User']['real_name_1'] = $this->data['Installation']['admin_username'];
             $user['User']['email'] = $this->data['Installation']['admin_email'];
             $user['User']['user_group_id'] = 1;
             $user['User']['password_1'] = $this->data['Installation']['admin_password'];
             $user['User']['password_2'] = $this->data['Installation']['admin_confirmpassword'];
             $user['User']['password'] = $user['User']['password_1'];
             $User->create($user);
             if ($User->validates()) {
                 $user['User']['password'] = Security::hash($this->data['Installation']['admin_password'], null, true);
                 $User->save($user, false);
                 $this->_sendCompleteMail($user['User']['email'], $user['User']['name'], $this->data['Installation']['admin_password']);
                 $this->redirect('step5');
             } else {
                 $message = '管理ユーザーを作成できませんでした。<br />' . $db->error;
                 $this->Session->setFlash($message);
             }
         }
     }
     $this->pageTitle = 'BaserCMSのインストール [ステップ4]';
 }
Example #6
0
    /**
     * Gather the root user login credentials and create the root user
     *
     * @access private
     *
     */
    private function __createRootUser()
    {
        $this->out('...... Create root user');

        if(!$this->__getStepCompleteByIndex($this->__stepIndexList['security_codes'])) {
            $this->out('*** ERROR *** You first need to run the security cipher and salt generation step');
            return;
        }

        if(!$this->__getStepCompleteByIndex($this->__stepIndexList['database_config'])) {
            $this->out('*** ERROR *** You first need to run the database configuration step');
            return;
        }

        if(!$this->__getStepCompleteByIndex($this->__stepIndexList['run_schema_shell'])) {
            $this->out('*** ERROR *** You first need to run the schema generation step');
            return;
        }

        $userModel = new User();

        $user = array();
        $user['User']['id'] = '4e27efec-ece0-4a36-baaf-38384bb83359';
        $user['User']['employee'] = 1;

        $emailValidates = true;
        do {
            if(!$emailValidates) {
                $invalidData = $userModel->invalidFields();
                $this->out('** ERROR ** ' . $invalidData['email'][0]);
            }

            $user['User']['email'] = $this->in('Email: ');
            $userModel->set($user);
            $emailValidates = $userModel->validates(array('fieldList' => array('email')));
        } while(!$emailValidates);


        $passwordValidates = true;
        do {
            if(!$passwordValidates) {
                $invalidData = $userModel->invalidFields();
                $this->out('** ERROR ** ' . $invalidData['password'][0]);
            }

            system('stty -echo');
            $user['User']['password'] = $this->in('Password: '******'User']['verify_password'] = $this->in('Verify Password: '******'stty echo');

            $userModel->set($user);
            $passwordValidates = $userModel->validates(array('fieldList' => array('password')));

        } while(!$passwordValidates);

        if($userModel->createUser($user['User'])) {
            $this->out('+++ Successfully created "root"');
        } else {
            $this->out('** ERROR ** There was a problem creating root user, please try again');
            $this->__createRootUser();
        }

        $this->__updateSetupState('create_root_user');
    }
 /**
  * Tests that validates triggers the beforeValidate callback
  *
  * @return void
  */
 public function testValidationBeforeCallback()
 {
     $user = new User();
     $user->validate = array('username' => array('notEmpty' => array('rule' => array('notEmpty'), 'message' => 'The username is required', 'required' => true)), 'password' => array('length' => array('rule' => array('between', 6, 100), 'required' => true, 'message' => 'The password is required')));
     $user->setUsername('thisshouldnotvalidate');
     $this->assertFalse($user->validates());
     $this->assertEquals(array('This is not good'), $user->validationErrors['username']);
 }