예제 #1
0
<?php

namespace Craft;

/**
 * Craft by Pixel & Tonic
 *
 * @package   Craft
 * @author    Pixel & Tonic, Inc.
 * @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
 * @license   http://buildwithcraft.com/license1.0.html Craft License
 * @link      http://buildwithcraft.com
 */
Craft::requirePackage(CraftPackage::Users);
/**
 *
 */
class UserGroupRecord extends BaseRecord
{
    /**
     * @return string
     */
    public function getTableName()
    {
        return 'usergroups';
    }
    /**
     * @access protected
     * @return array
     */
    protected function defineAttributes()
예제 #2
0
 /**
  * Registers a new user, or saves an existing user's account settings.
  */
 public function actionSaveUser()
 {
     $this->requirePostRequest();
     if (Craft::hasPackage(CraftPackage::Users)) {
         $userId = craft()->request->getPost('userId');
         if ($userId) {
             craft()->userSession->requireLogin();
         }
     } else {
         craft()->userSession->requireLogin();
         $userId = craft()->userSession->getUser()->id;
     }
     $publicRegistration = false;
     $canRegisterUsers = false;
     // Are we editing an existing user?
     if ($userId) {
         if ($userId != craft()->userSession->getUser()->id) {
             craft()->userSession->requirePermission('editUsers');
         }
         $user = craft()->users->getUserById($userId);
         if (!$user) {
             throw new Exception(Craft::t('No user exists with the ID “{id}”.', array('id' => $userId)));
         }
     } else {
         // Users package is required
         Craft::requirePackage(CraftPackage::Users);
         // Are they already logged in?
         if (craft()->userSession->getUser()) {
             // Make sure they have permission to register users, regardless of if public registration is enabled or not.
             craft()->userSession->requirePermission('registerUsers');
             $canRegisterUsers = true;
         } else {
             // Is public registration enabled?
             if (craft()->systemSettings->getSetting('users', 'allowPublicRegistration', false)) {
                 $publicRegistration = true;
             }
         }
         // If there is no public registration and the current user can't register users, complain loudly.
         if (!$publicRegistration && !$canRegisterUsers) {
             // Sorry pal.
             throw new HttpException(403);
         }
         $user = new UserModel();
     }
     // Can only change sensitive fields if you are an admin or this is your account.
     if (craft()->userSession->isAdmin() || $user->isCurrent()) {
         // Validate stuff.
         $valid = $this->_validateSensitiveFields($userId, $user, $publicRegistration || $canRegisterUsers);
     } else {
         $valid = true;
     }
     if ($valid) {
         $userName = craft()->request->getPost('username');
         if (!$userId) {
             $user->email = craft()->request->getPost('email');
             // If it is a new user, grab the password from post.
             if (!$userId && !craft()->request->isCpRequest()) {
                 $user->newPassword = craft()->request->getPost('password');
             }
         }
         // If no username was provided, set it to the email.
         $userName = $userName == null ? $user->email : $userName;
         $user->username = $userName;
         $user->firstName = craft()->request->getPost('firstName');
         $user->lastName = craft()->request->getPost('lastName');
         $user->preferredLocale = craft()->request->getPost('preferredLocale');
         // If it's a new user, set the verificationRequired bit.
         if (!$user->id) {
             $user->verificationRequired = true;
         }
         // Only admins can require users to reset their passwords
         if (craft()->userSession->isAdmin()) {
             $user->passwordResetRequired = (bool) craft()->request->getPost('passwordResetRequired');
         }
         try {
             if (craft()->users->saveUser($user)) {
                 if ($publicRegistration) {
                     $this->_assignDefaultGroupToUser($user->id);
                 }
                 craft()->userSession->setNotice(Craft::t('User saved.'));
                 // TODO: Remove for 2.0
                 if (isset($_POST['redirect']) && strpos($_POST['redirect'], '{userId}') !== false) {
                     Craft::log('The {userId} token within the ‘redirect’ param on users/saveUser requests has been deprecated. Use {id} instead.', LogLevel::Warning);
                     $_POST['redirect'] = str_replace('{userId}', '{id}', $_POST['redirect']);
                 }
                 $this->redirectToPostedUrl($user);
             } else {
                 craft()->userSession->setError(Craft::t('Couldn’t save user.'));
             }
         } catch (\phpmailerException $e) {
             craft()->userSession->setError(Craft::t('Registered user, but couldn’t send activation email. Check your email settings.'));
             // Still assign the default group
             if (($publicRegistration || $canRegisterUsers) && !craft()->request->isCpRequest()) {
                 $this->_assignDefaultGroupToUser($user->id);
             }
         }
     }
     // Send the account back to the template
     craft()->urlManager->setRouteVariables(array('account' => $user));
 }
예제 #3
0
<?php

namespace Craft;

/**
 * Craft by Pixel & Tonic
 *
 * @package   Craft
 * @author    Pixel & Tonic, Inc.
 * @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
 * @license   http://buildwithcraft.com/license Craft License Agreement
 * @link      http://buildwithcraft.com
 */
Craft::requirePackage(CraftPackage::PublishPro);
/**
 *
 */
class EntryVersionModel extends EntryModel
{
    /**
     * @access protected
     * @return array
     */
    protected function defineAttributes()
    {
        $attributes = parent::defineAttributes();
        $attributes['versionId'] = AttributeType::Number;
        $attributes['creatorId'] = AttributeType::Number;
        $attributes['notes'] = AttributeType::String;
        $attributes['dateCreated'] = AttributeType::DateTime;
        return $attributes;
예제 #4
0
<?php

namespace Craft;

/**
 * Craft by Pixel & Tonic
 *
 * @package   Craft
 * @author    Pixel & Tonic, Inc.
 * @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
 * @license   http://buildwithcraft.com/license Craft License Agreement
 * @link      http://buildwithcraft.com
 */
Craft::requirePackage(CraftPackage::Cloud);
/**
 * S3 source type class
 */
class S3AssetSourceType extends BaseAssetSourceType
{
    /**
     * A list of predefined endpoints.
     *
     * @var array
     */
    private static $_predefinedEndpoints = array('US' => 's3.amazonaws.com', 'EU' => 's3-eu-west-1.amazonaws.com');
    /**
     * @var \S3
     */
    private $_s3;
    /**
     * Returns the name of the source type.
<?php

namespace Craft;

/**
 * Craft by Pixel & Tonic
 *
 * @package   Craft
 * @author    Pixel & Tonic, Inc.
 * @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
 * @license   http://buildwithcraft.com/license1.0.html Craft License
 * @link      http://buildwithcraft.com
 */
Craft::requirePackage(CraftPackage::Rebrand);
/**
 *
 */
class EmailMessageRecord extends BaseRecord
{
    /**
     * @return string
     */
    public function getTableName()
    {
        return 'emailmessages';
    }
    /**
     * @access protected
     * @return array
     */
    protected function defineAttributes()
예제 #6
0
 /**
  * Saves a user's profile.
  *
  * @param UserModel $user
  * @return bool
  */
 public function saveProfile(UserModel $user)
 {
     Craft::requirePackage(CraftPackage::Users);
     $fieldLayout = craft()->fields->getLayoutByType(ElementType::User);
     if (craft()->content->saveElementContent($user, $fieldLayout)) {
         // Fire an 'onSaveProfile' event
         $this->onSaveProfile(new Event($this, array('user' => $user)));
         return true;
     } else {
         return false;
     }
 }
<?php

namespace Craft;

/**
 * Craft by Pixel & Tonic
 *
 * @package   Craft
 * @author    Pixel & Tonic, Inc.
 * @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
 * @license   http://buildwithcraft.com/license1.0.html Craft License
 * @link      http://buildwithcraft.com
 */
Craft::requirePackage(CraftPackage::Localize);
/**
 * Handles localization actions.
 */
class LocalizationController extends BaseController
{
    /**
     * Adds a new a locale.
     */
    public function actionAddLocale()
    {
        $this->requirePostRequest();
        $this->requireAjaxRequest();
        $locale = craft()->request->getRequiredPost('id');
        $success = craft()->i18n->addSiteLocale($locale);
        $this->returnJson(array('success' => $success));
    }
    /**
 /**
  * Get Google Cloud Storage buckets.
  */
 public function actionGetGoogleCloudBuckets()
 {
     craft()->userSession->requireAdmin();
     Craft::requirePackage(CraftPackage::Cloud);
     $keyId = craft()->request->getRequiredPost('keyId');
     $secret = craft()->request->getRequiredPost('secret');
     try {
         $this->returnJson(GoogleCloudAssetSourceType::getBucketList($keyId, $secret));
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
 }