/** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggreagated array of ValidationFailed objects will be returned. * * @param array $columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise. */ protected function doValidate($columns = null) { if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; $failureMap = array(); // We call the validate method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aAccount !== null) { if (!$this->aAccount->validate($columns)) { $failureMap = array_merge($failureMap, $this->aAccount->getValidationFailures()); } } if (($retval = HolidayPeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); } if ($this->collHolidayDomains !== null) { foreach ($this->collHolidayDomains as $referrerFK) { if (!$referrerFK->validate($columns)) { $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures()); } } } $this->alreadyInValidation = false; } return !empty($failureMap) ? $failureMap : true; }
protected function checkPermissions($action, $params) { try { $permissions = array(); if (!empty($this->permissions)) { foreach ($this->permissions as $key => $value) { if ($action === $key) { $permissions = array_merge($permissions, (array) $value); } elseif (substr($key, 0, 1) === '^' && $action !== substr($key, 1)) { $permissions = array_merge($permissions, (array) $value); } elseif (is_numeric($key)) { $permissions = array_merge($permissions, (array) $value); } } } if (!empty($permissions)) { Account::validate($permissions); } parent::beforeAction($action, $params); } catch (LoginRequiredException $e) { $loginUrl = array('route://admin_login', array('redirect' => \Simplify::request()->base() . \Simplify::request()->uri())); \Simplify::response()->redirect($loginUrl); } catch (SecurityException $e) { \Simplify::session()->warnings($e->getMessage()); \Simplify::response()->redirect('route://admin'); } }
public static function Login($email = "", $password = "") { $account = new Account(); $account->email = $email; $account->password = $password; $account->validate()->get(); if ($account->exists()) { $CI =& get_instance(); $CI->session->set_userdata(array("logged" => true, "id" => $account->id, "first_name" => $account->first_name, "last_name" => $account->last_name, "access" => $account->access, "email" => $account->email, "mobile_number" => $account->mobile_number, "manager" => $account->manager)); $account->lastlogin = time(); $account->save(); return $account; } return false; }
public static function remove() { global $objLiveAdmin; $strReturn = ""; $intAppId = request("application_id"); $strReturn .= "<fields>"; if (Account::validate('application', $intAppId, CMD_REMOVE)) { $filters = array('application_id' => $intAppId); $objLiveAdmin->perm->removeApplication($filters); } $strReturn .= "<field name=\"application_id\">"; $strReturn .= "<value>{$intAppId}</value>"; $strReturn .= "</field>"; $strReturn .= "</fields>"; return $strReturn; }
/** * 用户后台登陆 */ public function actionLogin() { $Account = new Account(); if (Yii::app()->session->get('IsLogin')) { $this->redirect($this->createUrl('Main/Index')); } if ($_POST) { $Account->attributes = $_POST['Account']; if ($Account->validate()) { if ($Account->execLogin()) { if ($this->getSuccess(Yii::app()->session['USER_ACCOUNT']['id'])) { Yii::app()->session->add('IsLogin', 'true'); $this->redirect($this->createUrl('Main/Index')); } } } } $this->renderPartial("login", array('FormObj' => $Account)); }
/** * @depends testCreateAndGetAccountById */ public function testValidatesWithoutOwnerWhenSpecifyingAttributesToValidate() { $user = User::getByUsername('steven'); $this->assertTrue($user->id > 0); $account = new Account(false); $_POST['MassEdit'] = array('employees' => '1'); $_POST['fake'] = array('employees' => 4); PostUtil::sanitizePostForSavingMassEdit('fake'); $account->setAttributes($_POST['fake']); $account->validate(array_keys($_POST['MassEdit'])); $this->assertEquals(array(), $account->getErrors()); $account->forget(); $account = new Account(false); $_POST['MassEdit'] = array('owner' => '1'); $_POST['fake'] = array('owner' => array('id' => '')); PostUtil::sanitizePostForSavingMassEdit('fake'); $account->setAttributes($_POST['fake']); $account->validate(array_keys($_POST['MassEdit'])); //there should be an owner error since it is specified but blank $this->assertNotEquals(array(), $account->getErrors()); $account->forget(); $account = new Account(false); $_POST['MassEdit'] = array('employees' => '1', 'owner' => '2'); $_POST['fake'] = array('employees' => 4, 'owner' => array('id' => $user->id)); PostUtil::sanitizePostForSavingMassEdit('fake'); $account->setAttributes($_POST['fake']); $account->validate(array_keys($_POST['MassEdit'])); $this->assertEquals(array(), $account->getErrors()); }
/** * @depends testBulkSetAndGetWithRelatedModels */ public function testEmptyPostValueForRequiredRelations() { Yii::app()->user->userModel = User::getByUsername('super'); $_FAKEPOST = array('Account' => array('name' => 'Vomitorio Corp 2', 'officePhone' => '123456789', 'officeFax' => null, 'employees' => 3, 'annualRevenue' => null, 'website' => 'http://barf.com', 'billingAddress' => array('street1' => '123 Road Rd', 'street2' => null, 'city' => 'Cityville', 'postalCode' => '12345', 'country' => 'Countrilia'), 'description' => 'a description', 'owner' => array('id' => ''), 'industry' => array('id' => ''))); $user = User::getByUsername('bobby'); $account = new Account(); $account->owner = $user; $account->setAttributes($_FAKEPOST['Account']); $this->assertFalse($account->validate()); $errors = $account->getErrors(); $this->assertEquals(1, count($errors)); $this->assertEquals('Username cannot be blank.', $errors['owner']['username'][0]); $this->assertEquals('Last Name cannot be blank.', $errors['owner']['lastName'][0]); }
/** * Create root account * * If root account not existed, this feature will be call to create\ * Else redirect to login feature */ public function createAccount() { $data = array(); $root = Account::model()->findByPk(1); if (empty($root)) { $root = Account::model()->findByPk(1); if (isset($_POST['Account'])) { $_POST['Account']['password'] = md5($_POST['Account']['password']); $_POST['Account']['cfpassword'] = md5($_POST['Account']['cfpassword']); $_POST['Account']['status'] = 'actived'; $account = new Account('account'); $account->attributes = $_POST['Account']; if ($account->validate()) { try { if ($account->save()) { $this->redirect($this->createRoleOrigin()); } } catch (Exception $ex) { $data['errmsg'] = $ex->getMessage(); } } else { $data['errmsg'] = 'Data input incorrect'; } $data['email'] = $_POST['Account']['email']; } } else { $this->redirect($this->createRoleOrigin()); } $this->render('account', $data); }
public function testReadOnlyFieldsOnSearchScenario() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $account = new Account(false); $account->setScenario('searchModel'); $account->name = 'aTestAccountForTestReadOnlyFieldsOnSearchScenario'; $account->owner = $super; $account->createdByUser = $super; $account->modifiedByUser = $super; $account->validate(); $this->assertFalse($account->hasErrors()); }
public static function remove() { global $objLiveAdmin; $strReturn = ""; $intPermUserId = request("perm_user_id"); $strReturn .= "<fields>"; if (Account::validate('perm_user', $intPermUserId)) { $filters = array('perm_user_id' => $intPermUserId); $objLiveAdmin->removeUser($filters); } $strReturn .= "<field name=\"perm_user_id\">"; $strReturn .= "<value>{$intPermUserId}</value>"; $strReturn .= "</field>"; $strReturn .= "</fields>"; return $strReturn; }
public function testUserCanReadEmptyModelWithoutPermissionAndNoDefaultsSetOnModelButCantSaveItUntilTheySetAnOwner() { $user = UserTestHelper::createBasicUser('atester'); $this->assertTrue($user->id > 0); $item = NamedSecurableItem::getByName('AccountsModule'); $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($user)); Yii::app()->user->userModel = $user; $account = new Account(false); $this->assertEquals('', $account->name); $account->name = 'Something Corp'; $account->validate(); $this->assertFalse($account->save()); $this->assertEquals(array('owner' => array('username' => array('Username cannot be blank.'), 'lastName' => array('Last Name cannot be blank.'))), $account->getErrors()); }
/* hide password and telephonenumber */ foreach ($accounts as $account) { $account->setPassword("hidden"); $account->setSalt("hidden"); } $response->getBody()->write(parseToJSONArray($accounts)); return $response; }); $app->post('/accounts', function ($request, $response, $args) { $parsedBody = $request->getParsedBody(); if ($parsedBody == null) { return err_general_error($response, "Provide a body to create a new account"); } $account = new Account(); $account->fromArray($parsedBody); if ($account->validate()) { $account->save(); } else { return err_general_error($response, "Validation failed"); } /* Response with resulting account */ $response->getBody()->write($account->toJSON()); return $response; }); $app->get('/accounts/{id}', function ($request, $response, $args) { $id = $request->getAttribute('id'); $account = AccountQuery::create()->findPK($id); if ($account == null) { return err_general_error($response, "Account Id {$id} not found"); } /* Hide password and salt */
public static function remove() { global $objLiveAdmin; $strReturn = ""; $intGroupId = request("group_id"); $strReturn .= "<fields>"; if (Account::validate('group', $intGroupId)) { $filters = array('group_id' => $intGroupId); $objLiveAdmin->perm->removeGroup($filters); } $strReturn .= "<field name=\"group_id\">"; $strReturn .= "<value>{$intGroupId}</value>"; $strReturn .= "</field>"; $strReturn .= "</fields>"; return $strReturn; }