public function onBeforeSend(Postmaster_TransportModel $model, $debug = false) { // Get the user results as an array straight from the db $results = $this->_getUsers(); // Set $this->totalResults and return false if no results if (($this->totalResults = count($results)) == 0) { // Return false to prevent the notification from sending return false; } // Create a user model from the first results. // Other users will be handled later in the script $user = UserModel::populateModel($results[0]); // Set the senderId to Postmaster_TransportModel instance $model->senderId = $user->id; // If the action is to fire on unchanged password if ($this->settings->action == 'changePassword') { // If the notification type is set to force password resets // then update the user model in the db if ((int) $this->settings->forcePasswordReset == 1) { $user->passwordResetRequired = true; $this->craft()->users->saveUser($user); } } $this->parse(array('user' => $user)); // Return true, as the notification should send return true; }
/** * Get users definition. * * @param UserModel $user * * @return array */ private function getUsersDefinition(UserModel $user) { return ['fieldLayout' => Craft::app()->schematic_fields->getFieldLayoutDefinition($user->getFieldLayout())]; }
/** * Validate Craft Auth * * @param Request $request Request * @param UserModel $user User * * @return boolean */ public function validateCraftAuth(Request $request, UserModel $user) { $craft_auth = \Craft\craft()->config->get('auth', 'restfulApi')['craft']; if (in_array($user->username, $craft_auth['users'])) { return true; } foreach ($craft_auth['permissions'] as $permission) { if (\Craft\craft()->userPermissions->doesUserHavePermission($user->id, $permission)) { return true; } } foreach ($craft_auth['groups'] as $group) { if ($user->isInGroup($group)) { return true; } } return false; }