コード例 #1
0
 public function afterSave()
 {
     // If the user has activated email receiving, send a email
     if ($user = $this->profile->user) {
         if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_profilecomment) {
             Yii::import('application.modules.messages.models.YumMessage');
             YumMessage::write($user, $this->user_id, Yum::t('New profile comment from {username}', array('{username}' => $this->user->username)), YumTextSettings::getText('text_profilecomment_new', array('{username}' => $this->user->username, '{message}' => $this->comment, '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'))));
         }
     }
     return parent::afterSave();
 }
コード例 #2
0
	public static function getText($column, $trans = array(), $language = NULL) {
		if(!is_array($trans))
			return false;

		if(is_null($language))
			$language = Yii::app()->language;

		if($text = YumTextSettings::model()->find('language = :language', array(
						':language' => $language)));

		if(isset($text->$column))
			return strtr($text->$column, $trans);

		return false;
	}
コード例 #3
0
 public function beforeSave()
 {
     $this->updatetime = time();
     // If the user has activated email receiving, send a email
     if ($this->isNewRecord) {
         if ($user = YumUser::model()->findByPk($this->friend_id)) {
             if (Yum::hasModule('messages') && $user->privacy && $user->privacy->message_new_friendship) {
                 Yii::import('application.modules.messages.models.YumMessage');
                 YumMessage::write($user, $this->inviter, Yum::t('New friendship request from {username}', array('{username}' => $this->inviter->username)), YumTextSettings::getText('text_friendship_new', array('{username}' => $this->inviter->username, '{link_friends}' => Yii::app()->controller->createUrl('//friendship/friendship/index'), '{link_profile}' => Yii::app()->controller->createUrl('//profile/profile/view'), '{message}' => $this->message)));
             }
         }
     }
     return parent::beforeSave();
 }
コード例 #4
0
	/**
	 * Password recovery routine. The User will receive an email with an
	 * activation link. If clicked, he will be prompted to enter his new
	 * password.
	 */
	public function actionRecovery($email = null, $key = null) {
		$form = new YumPasswordRecoveryForm;

		if ($email != null && $key != null) {
			if($profile = YumProfile::model()->find('email = :email', array(
							'email' =>  $email))) {
				$user = $profile->user;
				if($user->activationKey == $key) {
					$passwordform = new YumUserChangePassword;
					if (isset($_POST['YumUserChangePassword'])) {
						$passwordform->attributes = $_POST['YumUserChangePassword'];
						if ($passwordform->validate()) {
							$user->password = YumUser::encrypt($passwordform->password);
							$user->activationKey = YumUser::encrypt(microtime() . $passwordform->password);
							$user->save();
							Yum::setFlash('Your new password has been saved.');
							$this->redirect(Yum::module()->loginUrl);
						}
					}
					$this->render(
							Yum::module('registration')->changePasswordView, array(
								'form' => $passwordform));
					Yii::app()->end();
				} else {
					$form->addError('login_or_email', Yum::t('Invalid recovery key'));
					Yum::log(Yum::t(
								'Someone tried to recover a password, but entered a wrong recovery key. Email is {email}, associated user is {username} (id: {uid})', array(
									'{email}' => $email,
									'{uid}' => $user->id,
									'{username}' => $user->username)));
				}
			}
		} else {
			if (isset($_POST['YumPasswordRecoveryForm'])) {
				$form->attributes = $_POST['YumPasswordRecoveryForm'];

				if ($form->validate()) {
					Yum::setFlash(
							'Instructions have been sent to you. Please check your email.');

					if($form->user instanceof YumUser) {
						$form->user->generateActivationKey();
						$recovery_url = $this->createAbsoluteUrl(
								Yum::module('registration')->recoveryUrl[0], array(
									'key' => $form->user->activationKey,
									'email' => $form->user->profile->email));

						Yum::log(Yum::t(
									'{username} successfully requested a new password in the password recovery form. A email with the password recovery url {recovery_url} has been sent to {email}', array(
										'{email}' => $form->user->profile->email,
										'{recovery_url}' => $recovery_url,
										'{username}' => $form->user->username)));

						$content = YumTextSettings::model()->find(
								'language = :lang', array('lang' => Yii::app()->language));
						$sent = null;

						if (is_object($content)) {
							$mail = array(
									'from' => Yii::app()->params['adminEmail'],
									'to' => $form->user->profile->email,
									'subject' => $content->subject_email_registration,
									'body' => strtr($content->text_email_recovery, array(
											'{recovery_url}' => $recovery_url)),
									);
							$sent = YumMailer::send($mail);
						} else {
							throw new CException(Yum::t('The messages for your application language are not defined.'));
						}
					} else
						Yum::log(Yum::t(
									'A password has been requested, but no associated user was found in the database. Requested user/email is: {username}', array(
										'{username}' => $form->login_or_email)));
					$this->redirect(Yum::module()->loginUrl);
				}
			}
		}
		$this->render(Yum::module('registration')->recoverPasswordView, array(
					'form' => $form));

	}
コード例 #5
0
ファイル: YumUser.php プロジェクト: CODEPAC/codepac
	/**
	 * Activation of an user account.
	 * If everything is set properly, and the emails exists in the database,
	 * and is associated with a correct user, and this user has the status
	 * NOTACTIVE and the given activationKey is identical to the one in the
	 * database then generate a new Activation key to avoid double activation,
	 * set the status to ACTIVATED and save the data
	 * Error Codes:
	 * -1 : User is not inactive, it can not be activated
	 * -2 : Wrong activation key
	 * -3 : Profile found, but no user - database inconsistency?
	 */
	public static function activate($email, $key)
	{
		Yii::import('application.modules.profile.models.*');

		if ($profile = YumProfile::model()->find("email = :email", array(
						':email' => $email))
			 ) {
			if ($user = $profile->user) {
				if ($user->status != self::STATUS_INACTIVE)
					return -1;
				if ($user->activationKey == $key) {
					$user->activationKey = $user->generateActivationKey(true);
					$user->status = self::STATUS_ACTIVE;
					if ($user->save(false, array('activationKey', 'status'))) {
						Yum::log(Yum::t('User {username} has been activated', array(
										'{username}' => $user->username)));
						if (Yum::hasModule('messages')
								&& Yum::module('registration')->enableActivationConfirmation
							 ) {
							Yii::import('application.modules.messages.models.YumMessage');
							YumMessage::write($user, 1,
									Yum::t('Your activation succeeded'),
									YumTextSettings::getText('text_email_activation', array(
											'{username}' => $user->username,
											'{link_login}' =>
											Yii::app()->controller->createUrl('//user/user/login'))));
						}

						return $user;
					}
				} else return -2;
			} else return -3;
		}
		return false;
	}
コード例 #6
0
 public function sendPaymentConfirmation()
 {
     Yii::import('application.modules.message.models.*');
     return YumMessage::write($this->user, 1, Yum::t('Payment arrived'), YumTextSettings::getText('text_payment_arrived', array('{payment_date}' => date(Yum::module()->dateTimeFormat, $this->payment_date), '{id}' => $this->id)));
 }