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


PHP ValidateRequired函数代码示例

本文整理汇总了PHP中ValidateRequired函数的典型用法代码示例。如果您正苦于以下问题:PHP ValidateRequired函数的具体用法?PHP ValidateRequired怎么用?PHP ValidateRequired使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: UserController_TempBan_Create

 public function UserController_TempBan_Create($Sender, $Args)
 {
     $Sender->Permission('Garden.Moderation.Manage');
     $UserID = (int) GetValue('0', $Args);
     $Unban = (bool) GetValue('1', $Args);
     $User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw NotFoundException($User);
     }
     $UserModel = Gdn::UserModel();
     if ($Sender->Form->AuthenticatedPostBack()) {
         if ($Unban) {
             $UserModel->Unban($UserID, array('RestoreContent' => $Sender->Form->GetFormValue('RestoreContent')));
         } else {
             $Minutes = $Sender->Form->GetValue('TempBanPeriodMinutes');
             $Hours = $Sender->Form->GetValue('TempBanPeriodHours');
             $Days = $Sender->Form->GetValue('TempBanPeriodDays');
             $Months = $Sender->Form->GetValue('TempBanPeriodMonths');
             $Years = $Sender->Form->GetValue('TempBanPeriodYears');
             if (!(empty($Minutes) && empty($Hours) && empty($Days) && empty($Months) && empty($Years))) {
                 $AutoExpirePeriod = Gdn_Format::ToDateTime(strtotime("+{$Years} years {$Months} months {$Days} days {$Hours} hours {$Minutes} minutes"));
             } else {
                 $Sender->Form->AddError('ValidateRequired', 'Ban Period');
             }
             if (!ValidateRequired($Sender->Form->GetFormValue('Reason'))) {
                 $Sender->Form->AddError('ValidateRequired', 'Reason');
             }
             if ($Sender->Form->GetFormValue('Reason') == 'Other' && !ValidateRequired($Sender->Form->GetFormValue('ReasonText'))) {
                 $Sender->Form->AddError('ValidateRequired', 'Reason Text');
             }
             if ($Sender->Form->ErrorCount() == 0) {
                 if ($Sender->Form->GetFormValue('Reason') == 'Other') {
                     $Reason = $Sender->Form->GetFormValue('ReasonText');
                 } else {
                     $Reason = $Sender->Form->GetFormValue('Reason');
                 }
                 Gdn::Locale()->SetTranslation('HeadlineFormat.Ban', FormatString('{RegardingUserID,You} banned {ActivityUserID,you} until {BanExpire, date}.', array('BanExpire' => $AutoExpirePeriod)));
                 $UserModel->Ban($UserID, array('Reason' => $Reason));
                 $UserModel->SetField($UserID, 'BanExpire', $AutoExpirePeriod);
             }
         }
         if ($Sender->Form->ErrorCount() == 0) {
             // Redirect after a successful save.
             if ($Sender->Request->Get('Target')) {
                 $Sender->RedirectUrl = $Sender->Request->Get('Target');
             } else {
                 $Sender->RedirectUrl = Url(UserUrl($User));
             }
         }
     }
     $Sender->SetData('User', $User);
     $Sender->AddSideMenu();
     $Sender->Title($Unban ? T('Unban User') : T('Temporary Ban User'));
     if ($Unban) {
         $Sender->View = 'Unban';
     } else {
         $Sender->View = $this->ThemeView('tempban');
     }
     $Sender->Render();
 }
开发者ID:pawigor,项目名称:TempBan-Vanilla-Plugin,代码行数:60,代码来源:default.php

示例2: counts

 /**
  * Recalculate counters.
  *
  * @param bool $Table
  * @param bool $Column
  * @param bool $From
  * @param bool $To
  * @param bool $Max
  * @throws Exception
  * @throws Gdn_UserException
  */
 public function counts($Table = false, $Column = false, $From = false, $To = false, $Max = false)
 {
     increaseMaxExecutionTime(300);
     $this->permission('Garden.Settings.Manage');
     if ($Table && $Column && strcasecmp($this->Request->requestMethod(), Gdn_Request::INPUT_POST) == 0) {
         if (!ValidateRequired($Table)) {
             throw new Gdn_UserException("Table is required.");
         }
         if (!ValidateRequired($Column)) {
             throw new Gdn_UserException("Column is required.");
         }
         $Result = $this->Model->counts($Table, $Column, $From, $To);
         $this->setData('Result', $Result);
     } else {
         $this->setData('Jobs', array());
         $this->fireEvent('CountJobs');
     }
     $this->setData('Title', t('Recalculate Counts'));
     $this->render('Job');
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:31,代码来源:class.dbacontroller.php

示例3: Counts

 public function Counts($Table = FALSE, $Column = FALSE, $From = FALSE, $To = FALSE, $Max = FALSE)
 {
     $this->Permission('Garden.Settings.Manage');
     if ($Table && $Column && strcasecmp($this->Request->RequestMethod(), Gdn_Request::INPUT_POST) == 0) {
         if (!ValidateRequired($Table)) {
             throw new Gdn_UserException("Table is required.");
         }
         if (!ValidateRequired($Column)) {
             throw new Gdn_UserException("Column is required.");
         }
         $Result = $this->Model->Counts($Table, $Column, $From, $To);
         $this->SetData('Result', $Result);
     } else {
         $this->SetData('Jobs', array());
         $this->FireEvent('CountJobs');
     }
     $this->SetData('Title', T('Recalculate Counts'));
     $this->AddSideMenu();
     $this->Render('Job');
 }
开发者ID:rnovino,项目名称:Garden,代码行数:20,代码来源:class.dbacontroller.php

示例4: ban

 /**
  * Ban a user and optionally delete their content.
  *
  * @since 2.1
  * @param type $UserID
  */
 public function ban($UserID, $Unban = false)
 {
     $this->permission(array('Garden.Moderation.Manage', 'Garden.Users.Edit', 'Moderation.Users.Ban'), false);
     $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw notFoundException($User);
     }
     $UserModel = Gdn::userModel();
     // Block banning the super admin or system accounts.
     $User = $UserModel->getID($UserID);
     if (val('Admin', $User) == 2) {
         throw forbiddenException("@You may not ban a system user.");
     } elseif (val('Admin', $User)) {
         throw forbiddenException("@You may not ban a super admin.");
     }
     // Is the user banned for other reasons?
     $this->setData('OtherReasons', BanModel::isBanned(val('Banned', $User, 0), ~BanModel::BAN_AUTOMATIC));
     if ($this->Form->authenticatedPostBack()) {
         if ($Unban) {
             $UserModel->unban($UserID, array('RestoreContent' => $this->Form->getFormValue('RestoreContent')));
         } else {
             if (!ValidateRequired($this->Form->getFormValue('Reason'))) {
                 $this->Form->addError('ValidateRequired', 'Reason');
             }
             if ($this->Form->getFormValue('Reason') == 'Other' && !ValidateRequired($this->Form->getFormValue('ReasonText'))) {
                 $this->Form->addError('ValidateRequired', 'Reason Text');
             }
             if ($this->Form->errorCount() == 0) {
                 if ($this->Form->getFormValue('Reason') == 'Other') {
                     $Reason = $this->Form->getFormValue('ReasonText');
                 } else {
                     $Reason = $this->Form->getFormValue('Reason');
                 }
                 // Just because we're banning doesn't mean we can nuke their content
                 $DeleteContent = checkPermission('Garden.Moderation.Manage') ? $this->Form->getFormValue('DeleteContent') : false;
                 $UserModel->ban($UserID, array('Reason' => $Reason, 'DeleteContent' => $DeleteContent));
             }
         }
         if ($this->Form->errorCount() == 0) {
             // Redirect after a successful save.
             if ($this->Request->get('Target')) {
                 $this->RedirectUrl = $this->Request->get('Target');
             } elseif ($this->deliveryType() == DELIVERY_TYPE_ALL) {
                 $this->RedirectUrl = url(userUrl($User));
             } else {
                 $this->jsonTarget('', '', 'Refresh');
             }
         }
     }
     // Permission flag for view
     $this->setData('_MayDeleteContent', checkPermission('Garden.Moderation.Manage'));
     $this->setData('User', $User);
     $this->addSideMenu();
     $this->title($Unban ? t('Unban User') : t('Ban User'));
     if ($Unban) {
         $this->View = 'Unban';
     }
     $this->render();
 }
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:65,代码来源:class.usercontroller.php

示例5: Connect

 /**
  * Connect the user with an external source.
  *
  * This controller method is meant to be used with plugins that set its data array to work.
  * Events: ConnectData
  * 
  * @since 2.0.0
  * @access public
  *
  * @param string $Method Used to register multiple providers on ConnectData event.
  */
 public function Connect($Method)
 {
     $this->AddJsFile('entry.js');
     $this->View = 'connect';
     $IsPostBack = $this->Form->IsPostBack() && $this->Form->GetFormValue('Connect', NULL) !== NULL;
     if (!$IsPostBack) {
         // Here are the initial data array values. that can be set by a plugin.
         $Data = array('Provider' => '', 'ProviderName' => '', 'UniqueID' => '', 'FullName' => '', 'Name' => '', 'Email' => '', 'Photo' => '', 'Target' => $this->Target());
         $this->Form->SetData($Data);
         $this->Form->AddHidden('Target', $this->Request->Get('Target', '/'));
     }
     // The different providers can check to see if they are being used and modify the data array accordingly.
     $this->EventArguments = array($Method);
     // Fire ConnectData event & error handling.
     $CurrentData = $this->Form->FormValues();
     try {
         $this->FireEvent('ConnectData');
     } catch (Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
         return $this->Render('ConnectError');
     } catch (Exception $Ex) {
         if (Debug()) {
             $this->Form->AddError($Ex);
         } else {
             $this->Form->AddError('There was an error fetching the connection data.');
         }
         return $this->Render('ConnectError');
     }
     if (!UserModel::NoEmail()) {
         if (!$this->Form->GetFormValue('Email') || $this->Form->GetFormValue('EmailVisible')) {
             $this->Form->SetFormValue('EmailVisible', TRUE);
             $this->Form->AddHidden('EmailVisible', TRUE);
             if ($IsPostBack) {
                 $this->Form->SetFormValue('Email', GetValue('Email', $CurrentData));
             }
         }
     }
     $FormData = $this->Form->FormValues();
     // debug
     // Make sure the minimum required data has been provided to the connect.
     if (!$this->Form->GetFormValue('Provider')) {
         $this->Form->AddError('ValidateRequired', T('Provider'));
     }
     if (!$this->Form->GetFormValue('UniqueID')) {
         $this->Form->AddError('ValidateRequired', T('UniqueID'));
     }
     if (!$this->Data('Verified')) {
         // Whatever event handler catches this must Set the data 'Verified' to true to prevent a random site from connecting without credentials.
         // This must be done EVERY postback and is VERY important.
         $this->Form->AddError('The connection data has not been verified.');
     }
     if ($this->Form->ErrorCount() > 0) {
         return $this->Render();
     }
     $UserModel = Gdn::UserModel();
     // Check to see if there is an existing user associated with the information above.
     $Auth = $UserModel->GetAuthentication($this->Form->GetFormValue('UniqueID'), $this->Form->GetFormValue('Provider'));
     $UserID = GetValue('UserID', $Auth);
     // Check to synchronise roles upon connecting.
     if (($this->Data('Trusted') || C('Garden.SSO.SynchRoles')) && $this->Form->GetFormValue('Roles', NULL) !== NULL) {
         $SaveRoles = TRUE;
         // Translate the role names to IDs.
         $Roles = $this->Form->GetFormValue('Roles', NULL);
         $Roles = RoleModel::GetByName($Roles);
         $RoleIDs = array_keys($Roles);
         if (empty($RoleIDs)) {
             // The user must have at least one role. This protects that.
             $RoleIDs = $this->UserModel->NewUserRoleIDs();
         }
         $this->Form->SetFormValue('RoleID', $RoleIDs);
     } else {
         $SaveRoles = FALSE;
     }
     if ($UserID) {
         // The user is already connected.
         $this->Form->SetFormValue('UserID', $UserID);
         if (C('Garden.Registration.ConnectSynchronize', TRUE)) {
             $User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
             $Data = $this->Form->FormValues();
             // Don't overwrite the user photo if the user uploaded a new one.
             $Photo = GetValue('Photo', $User);
             if (!GetValue('Photo', $Data) || $Photo && !StringBeginsWith($Photo, 'http')) {
                 unset($Data['Photo']);
             }
             // Synchronize the user's data.
             $UserModel->Save($Data, array('NoConfirmEmail' => TRUE, 'FixUnique' => TRUE, 'SaveRoles' => $SaveRoles));
         }
         // Always save the attributes because they may contain authorization information.
         if ($Attributes = $this->Form->GetFormValue('Attributes')) {
//.........这里部分代码省略.........
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:101,代码来源:class.entrycontroller.php

示例6: fixUserRole

 /**
  * Look for users with an invalid role and apply the role specified to those users.
  */
 public function fixUserRole()
 {
     $this->permission('Garden.Settings.Manage');
     if ($this->Request->isAuthenticatedPostBack()) {
         if (ValidateRequired($this->Form->getFormValue('DefaultUserRole'))) {
             $this->Model->fixUserRole($this->Form->getFormValue('DefaultUserRole'));
             $this->setData('CompletedFix', true);
         }
     }
     $this->addSideMenu();
     $this->render();
 }
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:15,代码来源:class.dbacontroller.php

示例7: controller_Modify

 public function controller_Modify($Sender)
 {
     $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
     $Sender->DeliveryType(DELIVERY_TYPE_DATA);
     $UserID = Gdn::Request()->Get('UserID');
     if ($UserID != Gdn::Session()->UserID) {
         $Sender->Permission(array('Garden.Users.Edit', 'Moderation.Signatures.Edit'), FALSE);
     }
     $User = Gdn::UserModel()->GetID($UserID);
     if (!$User) {
         throw new Exception("No such user '{$UserID}'", 404);
     }
     $Translation = array('Plugin.Signatures.Sig' => 'Body', 'Plugin.Signatures.Format' => 'Format', 'Plugin.Signatures.HideAll' => 'HideAll', 'Plugin.Signatures.HideImages' => 'HideImages', 'Plugin.Signatures.HideMobile' => 'HideMobile');
     $UserMeta = $this->GetUserMeta($UserID, '%');
     $SigData = array();
     foreach ($Translation as $TranslationField => $TranslationShortcut) {
         $SigData[$TranslationShortcut] = GetValue($TranslationField, $UserMeta, NULL);
     }
     $Sender->SetData('Signature', $SigData);
     if ($Sender->Form->IsPostBack()) {
         $Sender->SetData('Success', FALSE);
         // Validate the signature.
         if (function_exists('ValidateSignature')) {
             $Sig = $Sender->Form->GetFormValue('Body');
             $Format = $Sender->Form->GetFormValue('Format');
             if (ValidateRequired($Sig) && !ValidateSignature($Sig, $Format)) {
                 $Sender->Form->AddError('Signature invalid.');
             }
         }
         if ($Sender->Form->ErrorCount() == 0) {
             foreach ($Translation as $TranslationField => $TranslationShortcut) {
                 $UserMetaValue = $Sender->Form->GetValue($TranslationShortcut, NULL);
                 if (is_null($UserMetaValue)) {
                     continue;
                 }
                 if ($TranslationShortcut == 'Body' && empty($UserMetaValue)) {
                     $UserMetaValue = NULL;
                 }
                 $Key = $this->TrimMetaKey($TranslationField);
                 switch ($Key) {
                     case 'Format':
                         if (strcasecmp($UserMetaValue, 'Raw') == 0) {
                             $UserMetaValue = NULL;
                         }
                         // don't allow raw signatures.
                         break;
                 }
                 if ($Sender->Form->ErrorCount() == 0) {
                     $this->SetUserMeta($UserID, $Key, $UserMetaValue);
                 }
             }
             $Sender->SetData('Success', TRUE);
         }
     }
     $Sender->Render();
 }
开发者ID:jamesinc,项目名称:addons,代码行数:56,代码来源:class.signatures.plugin.php

示例8: ValidateEnum

 function ValidateEnum($Value, $Field)
 {
     return in_array($Value, $Field->Enum) || $Field->AllowNull && !ValidateRequired($Value);
 }
开发者ID:3marproof,项目名称:vanilla,代码行数:4,代码来源:functions.validation.php

示例9: ValidateSpamRegistration

 /**
  *
  * @param array $User
  * @return bool|string
  * @since 2.1 
  */
 public function ValidateSpamRegistration($User)
 {
     $DiscoveryText = GetValue('DiscoveryText', $User);
     $Log = ValidateRequired($DiscoveryText);
     $Spam = SpamModel::IsSpam('Registration', $User, array('Log' => $Log));
     if ($Spam) {
         if ($Log) {
             // The user entered discovery text.
             return self::REDIRECT_APPROVE;
         } else {
             $this->Validation->AddValidationResult('DiscoveryText', 'Tell us why you want to join!');
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:statico,项目名称:openshift-origin-vanillaforums,代码行数:22,代码来源:class.usermodel.php

示例10: SSO

 public function SSO($UserID = FALSE)
 {
     $this->Permission('Garden.Users.Edit');
     $ProviderModel = new Gdn_AuthenticationProviderModel();
     $Form = new Gdn_Form();
     if ($this->Request->IsPostBack()) {
         // Make sure everything has been posted.
         $Form->ValidateRule('ClientID', 'ValidateRequired');
         $Form->ValidateRule('UniqueID', 'ValidateRequired');
         if (!ValidateRequired($Form->GetFormValue('Username')) && !ValidateRequired($Form->GetFormValue('Email'))) {
             $Form->AddError('Username or Email is required.');
         }
         $Provider = $ProviderModel->GetProviderByKey($Form->GetFormValue('ClientID'));
         if (!$Provider) {
             $Form->AddError(sprintf('%1$s "%2$s" not found.', T('Provider'), $Form->GetFormValue('ClientID')));
         }
         if ($Form->ErrorCount() > 0) {
             throw new Gdn_UserException($Form->ErrorString());
         }
         // Grab the user.
         $User = FALSE;
         if ($Email = $Form->GetFormValue('Email')) {
             $User = Gdn::UserModel()->GetByEmail($Email);
         }
         if (!$User && ($Username = $Form->GetFormValue('Username'))) {
             $User = Gdn::UserModel()->GetByUsername($Username);
         }
         if (!$User) {
             throw new Gdn_UserException(sprintf(T('User not found.'), strtolower(T(UserModel::SigninLabelCode()))), 404);
         }
         // Validate the user's password.
         $PasswordHash = new Gdn_PasswordHash();
         $Password = $this->Form->GetFormValue('Password', NULL);
         if ($Password !== NULL && !$PasswordHash->CheckPassword($Password, GetValue('Password', $User), GetValue('HashMethod', $User))) {
             throw new Gdn_UserException(T('Invalid password.'), 401);
         }
         // Okay. We've gotten this far. Let's save the authentication.
         $User = (array) $User;
         Gdn::UserModel()->SaveAuthentication(array('UserID' => $User['UserID'], 'Provider' => $Form->GetFormValue('ClientID'), 'UniqueID' => $Form->GetFormValue('UniqueID')));
         $Row = Gdn::UserModel()->GetAuthentication($Form->GetFormValue('UniqueID'), $Form->GetFormValue('ClientID'));
         if ($Row) {
             $this->SetData('Result', $Row);
         } else {
             throw new Gdn_UserException(T('There was an error saving the data.'));
         }
     } else {
         $User = Gdn::UserModel()->GetID($UserID);
         if (!$User) {
             throw NotFoundException('User');
         }
         $Result = Gdn::SQL()->Select('ua.ProviderKey', '', 'ClientID')->Select('ua.ForeignUserKey', '', 'UniqueID')->Select('ua.UserID')->Select('p.Name')->Select('p.AuthenticationSchemeAlias', '', 'Type')->From('UserAuthentication ua')->Join('UserAuthenticationProvider p', 'ua.ProviderKey = p.AuthenticationKey')->Where('UserID', $UserID)->Get()->ResultArray();
         $this->SetData('Result', $Result);
     }
     $this->Render('Blank', 'Utility', 'Dashboard');
 }
开发者ID:3marproof,项目名称:vanilla,代码行数:55,代码来源:class.usercontroller.php

示例11: ValidateEmail

 function ValidateEmail($Value, $Field = '')
 {
     if (!ValidateRequired($Value)) {
         return TRUE;
     }
     $Result = PHPMailer::ValidateAddress($Value);
     $Result = (bool) $Result;
     return $Result;
 }
开发者ID:remobjects,项目名称:Garden,代码行数:9,代码来源:functions.validation.php

示例12: Ban

 /**
  * Ban a user and optionally delete their content.
  * @since 2.1
  * @param type $UserID 
  */
 public function Ban($UserID, $Unban = FALSE)
 {
     $this->Permission('Garden.Moderation.Manage');
     $User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw NotFoundException($User);
     }
     //      $this->Form = new Gdn_Form();
     $UserModel = Gdn::UserModel();
     if ($this->Form->IsPostBack()) {
         if ($Unban) {
             $UserModel->Unban($UserID, array('RestoreContent' => $this->Form->GetFormValue('RestoreContent')));
         } else {
             if (!ValidateRequired($this->Form->GetFormValue('Reason'))) {
                 $this->Form->AddError('ValidateRequired', 'Reason');
             }
             if ($this->Form->GetFormValue('Reason') == 'Other' && !ValidateRequired($this->Form->GetFormValue('ReasonText'))) {
                 $this->Form->AddError('ValidateRequired', 'Reason Text');
             }
             if ($this->Form->ErrorCount() == 0) {
                 if ($this->Form->GetFormValue('Reason') == 'Other') {
                     $Reason = $this->Form->GetFormValue('ReasonText');
                 } else {
                     $Reason = $this->Form->GetFormValue('Reason');
                 }
                 $UserModel->Ban($UserID, array('Reason' => $Reason, 'DeleteContent' => $this->Form->GetFormValue('DeleteContent')));
             }
         }
         if ($this->Form->ErrorCount() == 0) {
             // Redirect after a successful save.
             if ($this->Request->Get('Target')) {
                 $this->RedirectUrl = $this->Request->Get('Target');
             } else {
                 $this->RedirectUrl = UserUrl($User);
             }
         }
     }
     $this->SetData('User', $User);
     $this->AddSideMenu();
     $this->Title($Unban ? T('Unban User') : T('Ban User'));
     if ($Unban) {
         $this->View = 'Unban';
     }
     $this->Render();
 }
开发者ID:robhazkes,项目名称:Garden,代码行数:50,代码来源:class.usercontroller.php


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