public function actionRegistration()
 {
     // When we override the registrationUrl, this one should not be accessible
     // anymore
     if (Yum::module('registration')->registrationUrl != array('//registration/registration/registration')) {
         throw new CHttpException(403);
     }
     Yii::import('user.profile.models.*');
     $form = new YumRegistrationForm();
     $profile = new YumProfile();
     $this->performAjaxValidation('YumRegistrationForm', $form);
     if (isset($_POST['YumRegistrationForm'])) {
         $form->attributes = $_POST['YumRegistrationForm'];
         $profile->attributes = $_POST['YumProfile'];
         if (Yum::module('registration')->registration_by_email) {
             $form->username = $profile->email;
         }
         $form->validate();
         $profile->validate();
         if (!$form->hasErrors() && !$profile->hasErrors()) {
             $user = new YumUser();
             $user->register($form->username, $form->password, $profile);
             $user->profile = $profile;
             $this->sendRegistrationEmail($user);
             Yum::setFlash('Thank you for your registration. Please check your email.');
             $this->redirect(Yum::module()->loginUrl);
         }
     }
     $this->render(Yum::module('registration')->registrationView, array('form' => $form, 'profile' => $profile));
 }
	public function actionCreate($mode)
	{
		switch($mode)
		{
			case 'user':
				$model = new YumUser;
				$profile = new YumProfile;
				break;
			default:
		}
		$username = $_POST['username'] or $this->_sendResponse(
				501, 'Username missing');
		$password = $_POST['password'] or $this->_sendResponse(
				501, 'Password missing');

		foreach($_POST as $key => $value)
			if($profile->hasAttribute($key))
				$profile->$key = $value;

		if($profile->validate() && $model->register($username, $password, $profile))
			$this->_sendResponse(200, 
					CJSON::encode(array($model, $profile)));	
		else {
			$msg = "<h1>Error</h1>";
			$msg .= sprintf("Couldn't create %s", $mode);
			$msg .= "<ul>";
			foreach($model->errors as $attribute => $attr_errors) {
				$msg .= "<li>Attribute: $attribute</li>";
				$msg .= "<ul>";
				foreach($attr_errors as $attr_error)
					$msg .= "<li>$attr_error</li>";
				$msg .= "</ul>";
			}

			foreach($profile->errors as $attribute => $attr_errors) {
				$msg .= "<li>Attribute: $attribute</li>";
				$msg .= "<ul>";
				foreach($attr_errors as $attr_error)
					$msg .= "<li>$attr_error</li>";
				$msg .= "</ul>";
			}
			$msg .= "</ul>";
			$this->_sendResponse(500, $msg );

		}
	}
	public function actionRegistration() {
		// When we overrie the registrationUrl, this one is not valid anymore!
		if(Yum::module('registration')->registrationUrl != array(
					'//registration/registration/registration'))
			throw new CHttpException(403);

		Yii::import('application.modules.profile.models.*');
		$form = new YumRegistrationForm;
		$profile = new YumProfile;

		$this->performAjaxValidation('YumRegistrationForm', $form);

		if (isset($_POST['YumRegistrationForm'])) { 
			$form->attributes = $_POST['YumRegistrationForm'];
			$profile->attributes = $_POST['YumProfile'];

			$form->validate();
			$profile->validate();

			if(!$form->hasErrors() && !$profile->hasErrors()) {
				$user = new YumUser;
				
				$user->register($form->username, $form->password, $profile->email);
				$profile->user_id = $user->id;
				$profile->save();

				$this->sendRegistrationEmail($user);
				Yum::setFlash('Thank you for your registration. Please check your email.');
				$this->redirect(Yum::module()->loginUrl);
			}
		} 

		$this->render(Yum::module()->registrationView, array(
					'form' => $form,
					'profile' => $profile,
					)
				);  
	}
Пример #4
0
	/**
	 * Creates a new User.
	 */
	public function actionCreate() {
		$model = new YumUser;
		if(Yum::hasModule('profile'))
			$profile = new YumProfile;
		$passwordform = new YumUserChangePassword;

		// When opening a empty user creation mask, we most probably want to
		// insert an _active_ user
		if(!isset($model->status))
			$model->status = 1;

		if(isset($_POST['YumUser'])) {
			$model->attributes=$_POST['YumUser'];

			if(Yum::hasModule('role'))
				$model->roles = Relation::retrieveValues($_POST);

			if(Yum::hasModule('profile') && isset($_POST['YumProfile']) )
				$profile->attributes = $_POST['YumProfile'];

			if(isset($_POST['YumUserChangePassword'])) {
				if($_POST['YumUserChangePassword']['password'] == '') {
					$password = YumUser::generatePassword();
					$model->setPassword($password);
					Yum::setFlash(Yum::t('The generated Password is {password}', array(
									'{password}' => $password)));
				} else {
					$passwordform->attributes = $_POST['YumUserChangePassword'];

					if($passwordform->validate())
						$model->setPassword($_POST['YumUserChangePassword']['password']);
				}
			}

			$model->activationKey = YumUser::encrypt(microtime() . $model->password);

			if($model->username == '' && isset($profile))
				$model->username = $profile->email;

			$model->validate();

			if(isset($profile))
				$profile->validate();

			if(!$model->hasErrors()
					&& !$passwordform->hasErrors()) {
				$model->save();
				if(isset($profile)) {
					$profile->user_id = $model->id;
					$profile->save(array('user_id'), false);
				}
			        Yii::import('application.modules.registration.controllers.YumRegistrationController');
				YumRegistrationController::sendRegistrationEmail($model);
				$this->redirect(array('view', 'id'=>$model->id));
			}
		}

		$this->render('create',array(
					'model' => $model,
					'passwordform' => $passwordform,
					'profile' => isset($profile) ? $profile : null,
					));
	}
 /**
  * Creates a new User.
  */
 public function actionCreate()
 {
     $user = new YumUser();
     if (Yum::hasModule('profile')) {
         $profile = new YumProfile();
     }
     $passwordform = new YumUserChangePassword();
     // When opening a empty user creation mask, we most probably want to
     // insert an _active_ user
     if (!$user->status) {
         $user->status = 1;
     }
     if (isset($_POST['YumUser'])) {
         $user->attributes = $_POST['YumUser'];
         if (isset($_POST['YumUserChangePassword'])) {
             if ($_POST['YumUserChangePassword']['password'] == '') {
                 Yii::import('user.components.EPasswordGenerator');
                 $generatorOptions = Yum::module()->passwordGeneratorOptions;
                 $password = EPasswordGenerator::generate($generatorOptions['length'], $generatorOptions['capitals'], $generatorOptions['numerals'], $generatorOptions['symbols']);
                 $user->setPassword($password);
                 Yum::setFlash(Yum::t('The generated Password is {password}', array('{password}' => $password)));
             } else {
                 $passwordform->attributes = $_POST['YumUserChangePassword'];
                 if ($passwordform->validate()) {
                     $user->setPassword($_POST['YumUserChangePassword']['password']);
                 }
             }
         }
         $user->validate();
         if (Yum::hasModule('profile') && isset($_POST['YumProfile'])) {
             $profile->attributes = $_POST['YumProfile'];
         }
         if (!$user->hasErrors()) {
             $user->activationKey = CPasswordHelper::hashPassword(microtime() . $user->password, Yum::module()->passwordHashCost);
             if ($user->username == '' && isset($profile)) {
                 $user->username = $profile->email;
             }
             if (isset($profile)) {
                 $profile->validate();
             }
             if (!$user->hasErrors() && !$passwordform->hasErrors()) {
                 $user->save();
                 if (isset($_POST['YumUser']['roles'])) {
                     $user->syncRoles($_POST['YumUser']['roles']);
                 } else {
                     $user->syncRoles();
                 }
                 if (isset($profile)) {
                     $profile->user_id = $user->id;
                     $profile->save(array('user_id'), false);
                 }
                 $this->redirect(array('view', 'id' => $user->id));
             }
         }
     }
     $this->render('create', array('user' => $user, 'passwordform' => $passwordform, 'profile' => isset($profile) ? $profile : null));
 }