예제 #1
0
 /**
  * Show a warning if default roles are not setup yet.
  *
  * @since 2.0.?
  * @access public
  */
 public function DefaultRolesWarning()
 {
     // Check to see if there are no default roles for guests or members.
     $DefaultRolesWarning = FALSE;
     $DefaultRoles = C('Garden.Registration.DefaultRoles');
     if (!is_array($DefaultRoles) || count($DefaultRoles) == 0) {
         $DefaultRolesWarning = TRUE;
     } elseif (!C('Garden.Registration.ApplicantRoleID') && C('Garden.Registration.Method') == 'Approval') {
         $DefaultRolesWarning = TRUE;
     } else {
         $RoleModel = new RoleModel();
         $GuestRoles = $RoleModel->GetByUserID(0);
         if ($GuestRoles->NumRows() == 0) {
             $DefaultRolesWarning = TRUE;
         }
     }
     if ($DefaultRolesWarning) {
         echo '<div class="Messages Errors"><ul><li>', sprintf(T('No default roles.', 'You don\'t have your default roles set up. To correct this problem click %s.'), Anchor(T('here'), 'dashboard/role/defaultroles')), '</div>';
     }
 }
예제 #2
0
 /**
  * Configuration of registration settings.
  */
 public function Registration($RedirectUrl = '')
 {
     $this->Permission('Garden.Registration.Manage');
     if (!C('Garden.Registration.Manage', TRUE)) {
         return Gdn::Dispatcher()->Dispatch('Default404');
     }
     $this->AddSideMenu('dashboard/settings/registration');
     $this->AddJsFile('registration.js');
     $this->Title(T('Registration'));
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Registration.Method' => 'Captcha', 'Garden.Registration.CaptchaPrivateKey', 'Garden.Registration.CaptchaPublicKey', 'Garden.Registration.InviteExpiration'));
     // Set the model on the forms.
     $this->Form->SetModel($ConfigurationModel);
     // Load roles with sign-in permission
     $RoleModel = new RoleModel();
     $this->RoleData = $RoleModel->GetByPermission('Garden.SignIn.Allow');
     // Get the currently selected default roles
     // $this->ExistingRoleData = Gdn::Config('Garden.Registration.DefaultRoles');
     // if (is_array($this->ExistingRoleData) === FALSE)
     //    $this->ExistingRoleData = array();
     // Get currently selected InvitationOptions
     $this->ExistingRoleInvitations = Gdn::Config('Garden.Registration.InviteRoles');
     if (is_array($this->ExistingRoleInvitations) === FALSE) {
         $this->ExistingRoleInvitations = array();
     }
     // Get the currently selected Expiration Length
     $this->InviteExpiration = Gdn::Config('Garden.Registration.InviteExpiration', '');
     // Registration methods.
     $this->RegistrationMethods = array('Captcha' => "New users fill out a simple form and are granted access immediately.", 'Approval' => "New users are reviewed and approved by an administrator (that's you!).", 'Invitation' => "Existing members send invitations to new members.");
     // Options for how many invitations a role can send out per month.
     $this->InvitationOptions = array('0' => T('None'), '1' => '1', '2' => '2', '5' => '5', '-1' => T('Unlimited'));
     // Options for when invitations should expire.
     $this->InviteExpirationOptions = array('-1 week' => T('1 week after being sent'), '-2 weeks' => T('2 weeks after being sent'), '-1 month' => T('1 month after being sent'), 'FALSE' => T('never'));
     // Check to see if there are no default roles for guests or members.
     $DefaultRoleWarning = FALSE;
     $DefaultRoles = C('Garden.Registration.DefaultRoles');
     if (count($DefaultRoles) == 0) {
         $DefaultRoleWarning = TRUE;
     } else {
         $GuestRoles = $RoleModel->GetByUserID(0);
         if ($GuestRoles->NumRows() == 0) {
             $DefaultRoleWarning = TRUE;
         }
     }
     $this->SetData('DefaultRoleWarning', $DefaultRoleWarning);
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Registration.Method', 'Required');
         // if($this->Form->GetValue('Garden.Registration.Method') != 'Closed')
         //    $ConfigurationModel->Validation->ApplyRule('Garden.Registration.DefaultRoles', 'RequiredArray');
         // Define the Garden.Registration.RoleInvitations setting based on the postback values
         $InvitationRoleIDs = $this->Form->GetValue('InvitationRoleID');
         $InvitationCounts = $this->Form->GetValue('InvitationCount');
         $this->ExistingRoleInvitations = ArrayCombine($InvitationRoleIDs, $InvitationCounts);
         $ConfigurationModel->ForceSetting('Garden.Registration.InviteRoles', $this->ExistingRoleInvitations);
         // Save!
         if ($this->Form->Save() !== FALSE) {
             $this->StatusMessage = T("Your settings have been saved.");
             if ($RedirectUrl != '') {
                 $this->RedirectUrl = $RedirectUrl;
             }
         }
     }
     $this->Render();
 }
예제 #3
0
 /** Test an individual condition.
  *
  * @param string $Type One of the types in this condition.
  * @param string $Field The field to test against.
  * @param string $Expr The expression to test with.
  * @return bool
  */
 public static function TestOne($Type, $Field, $Expr = NULL)
 {
     switch (strtolower($Type)) {
         case PERMISSION:
             // Check to see if the user has the given permission.
             $Result = Gdn::Session()->CheckPermission($Field);
             if ($Value === FALSE) {
                 return !$Result;
             }
             return $Result;
         case REQUEST:
             // See if the field is a specific value.
             switch (strtolower($Field)) {
                 case 'path':
                     $Value = Gdn::Request()->Path();
                     break;
                 default:
                     // See if the field is targetting a specific part of the request.
                     $Fields = explode('.', $Field, 2);
                     if (count($Fields) >= 2) {
                         $Value = Gdn::Request()->GetValueFrom($Fields[0], $Fields[1], NULL);
                     } else {
                         $Value = Gdn::Request()->GetValue($Field, NULL);
                     }
                     break;
             }
             $Result = Gdn_Condition::TestValue($Value, $Expr);
             return $Result;
         case ROLE:
             // See if the user is in the given role.
             $RoleModel = new RoleModel();
             $Roles = $RoleModel->GetByUserID(Gdn::Session()->UserID)->ResultArray();
             foreach ($Roles as $Role) {
                 if (is_numeric($Expr)) {
                     $Result = $Expr == GetValue('RoleID', $Role);
                 } else {
                     $Result = Gdn_Condition::TestValue(GetValue('Name', $Role), $Expr);
                 }
                 if ($Result) {
                     return TRUE;
                 }
             }
             return FALSE;
     }
     return FALSE;
 }
 /**
  * Pre-process content into a uniform format for output
  *
  * @param Array $content By reference
  */
 protected function processContent(&$content)
 {
     foreach ($content as &$item) {
         $contentType = val('RecordType', $item);
         $userID = val('InsertUserID', $item);
         $itemProperties = array();
         $itemFields = array('DiscussionID', 'DateInserted', 'DateUpdated', 'Body', 'Format', 'RecordType', 'Url', 'CategoryID', 'CategoryName', 'CategoryUrl');
         switch (strtolower($contentType)) {
             case 'comment':
                 $itemFields = array_merge($itemFields, array('CommentID'));
                 // Comment specific
                 $itemProperties['Name'] = sprintf(t('Re: %s'), valr('Discussion.Name', $item, val('Name', $item)));
                 $url = CommentUrl($item);
                 break;
             case 'discussion':
                 $itemFields = array_merge($itemFields, array('Name', 'Type'));
                 $url = DiscussionUrl($item);
                 break;
         }
         $item['Url'] = $url;
         if ($categoryId = val('CategoryID', $item)) {
             $category = CategoryModel::categories($categoryId);
             $item['CategoryName'] = val('Name', $category);
             $item['CategoryUrl'] = CategoryUrl($category);
         }
         $itemFields = array_fill_keys($itemFields, true);
         $filteredItem = array_intersect_key($item, $itemFields);
         $itemProperties = array_merge($itemProperties, $filteredItem);
         $item = $itemProperties;
         // Attach User
         $userFields = array('UserID', 'Name', 'Title', 'Location', 'PhotoUrl', 'RankName', 'Url', 'Roles', 'RoleNames');
         $user = Gdn::userModel()->getID($userID);
         $roleModel = new RoleModel();
         $roles = $roleModel->GetByUserID($userID)->resultArray();
         $roleNames = '';
         foreach ($roles as $role) {
             $roleNames[] = val('Name', $role);
         }
         // check
         $rankName = null;
         if (class_exists('RankModel')) {
             $rankName = val('Name', RankModel::Ranks(val('RankID', $user)), null);
         }
         $userProperties = array('Url' => url(userUrl($user), true), 'PhotoUrl' => UserPhotoUrl($user), 'RankName' => $rankName, 'RoleNames' => $roleNames, 'CssClass' => val('_CssClass', $user));
         $user = (array) $user;
         $userFields = array_fill_keys($userFields, true);
         $filteredUser = array_intersect_key($user, $userFields);
         $userProperties = array_merge($filteredUser, $userProperties);
         $item['Author'] = $userProperties;
     }
 }
예제 #5
0
 /**
  * Filters permission array based on config setting.
  *
  * @param object $sender Generally this is the UserModel.
  * @param mixed $args EventArguments, mainly the user.
  * @return void.
  * @package ReadOnly
  * @since 0.1
  */
 public function base_afterGetSession_handler($sender, $args)
 {
     // Admin user will never be restricted.
     if ($args['User']->Admin) {
         return;
     }
     $roles = c('ReadOnly.Roles');
     $roleModel = new RoleModel();
     $userRoles = $roleModel->GetByUserID($args['User']->UserID)->ResultArray();
     foreach ($userRoles as $userRole) {
         if (in_array($userRole, $roles)) {
             return;
         }
     }
     $restrictions = c('ReadOnly.Restrictions');
     // Go through all permissions of the session user.
     $permissions = $args['User']->Permissions;
     foreach ($permissions as $key => $permission) {
         // Split permission name in pieces.
         if (!is_array($permission)) {
             $suffix = substr($permission, strrpos($permission, '.') + 1);
         } else {
             $suffix = substr($key, strrpos($key, '.') + 1);
         }
         // Delete all restricted permissions.
         if (in_array($suffix, $restrictions)) {
             unset($permissions[$key]);
         }
     }
     // Overwrite the reduced permission array to the session user.
     $args['User']->Permissions = $permissions;
 }