Exemplo n.º 1
0
 /**
  * @param DbObject $user
  * @param mixed $onFailReturn
  * @return mixed|DbObject
  */
 protected function validateUser(DbObject $user, $onFailReturn = null)
 {
     if ($user->exists() && (!$user->_hasField('is_active') || $user->is_active) && (!$user->_hasField('is_banned') || !$user->is_banned)) {
         return $user;
     }
     return $onFailReturn;
 }
Exemplo n.º 2
0
 /**
  * @param Request $request
  * @param DbObject|Authenticatable $admin
  * @return array|\Illuminate\Http\JsonResponse
  */
 protected function validateAndGetAdminProfileUpdates(Request $request, DbObject $admin)
 {
     $validationRules = ['old_password' => 'required', 'new_password' => 'min:6'];
     $fieldsToUpdate = [];
     if ($admin->_hasField('language')) {
         $validationRules['language'] = 'required|in:' . implode(CmfConfig::getInstance()->locales());
         $fieldsToUpdate[] = 'language';
     }
     if ($admin->_hasField('name')) {
         $validationRules['name'] = 'max:200';
         $fieldsToUpdate[] = 'name';
     }
     if ($admin->_hasField('timezone')) {
         $validationRules['timezone'] = 'required|exists2:pg_timezone_names,name';
         $fieldsToUpdate[] = 'timezone';
     }
     $usersTable = CmfConfig::getInstance()->users_table_name();
     $userLoginCol = CmfConfig::getInstance()->user_login_column();
     if ($admin->_hasField('email')) {
         if ($userLoginCol === 'email') {
             $validationRules['email'] = "required|email|unique:{$usersTable},email,{$admin->getAuthIdentifier()},id";
         } else {
             $validationRules['email'] = 'email';
         }
         $fieldsToUpdate[] = 'email';
     }
     if ($userLoginCol !== 'email') {
         $validationRules[$userLoginCol] = "required|regex:%^[a-zA-Z0-9_@.-]+\$%is|min:4|unique:{$usersTable},{$userLoginCol},{$admin->getAuthIdentifier()},id";
         $fieldsToUpdate[] = $userLoginCol;
     }
     foreach (CmfConfig::getInstance()->additional_user_profile_fields() as $fieldName => $rules) {
         if (is_int($fieldName)) {
             $fieldName = $rules;
         } else {
             $validationRules[$fieldName] = $rules;
         }
         $fieldsToUpdate[] = $fieldName;
     }
     $validator = \Validator::make($request->data(), $validationRules, Set::flatten(CmfConfig::transCustom('.page.profile.errors')));
     $errors = [];
     if ($validator->fails()) {
         $errors = $validator->getMessageBag()->toArray();
     } else {
         if (!\Hash::check($request->data('old_password'), $admin->getAuthPassword())) {
             $errors['old_password'] = CmfConfig::transCustom('.page.profile.errors.old_password.match');
         }
     }
     if (!empty($errors)) {
         return cmfJsonResponseForValidationErrors($errors);
     }
     return $request->only($fieldsToUpdate);
 }
Exemplo n.º 3
0
 /**
  * Needed for IDE autocompletion
  * @return CmfDbModel|CacheForDbSelects
  */
 public function _getModel()
 {
     return parent::_getModel();
 }
Exemplo n.º 4
0
 /**
  * @param int|string|array|DbObject $record
  * @param bool $cleanRelatedModelsCache
  * @throws DbModelException
  * @throws \BadMethodCallException
  * @throws \PeskyORM\Exception\DbConnectionConfigException
  * @throws \PeskyORM\Exception\DbObjectException
  * @throws \PeskyORM\Exception\DbUtilsException
  * @throws \InvalidArgumentException
  */
 public function cleanRecordCache($record, $cleanRelatedModelsCache = null)
 {
     /** @var CmfDbModel|TaggedCacheForDbSelects $this */
     if (!$record instanceof DbObject || $record->exists()) {
         \Cache::tags($this->getRecordCacheTag($record))->flush();
     }
     $this->cleanRelatedModelsCache($cleanRelatedModelsCache);
 }