/** * Initiates the password reset process on behalf of the user * Generates a unique hash and an expiration time that the hash is valid up until (defaults to 15 minutes) * This key will internally expire (but not be expunged) after that time */ public function initPasswordResetProcess() { if (!$this->validate()) { return false; } $hash = Cii::generateSafeHash(); $expires = strtotime("+15 minutes"); $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->_user->id, 'key' => 'passwordResetCode')); if ($meta === NULL) { $meta = new UserMetadata(); } $meta->user_id = $this->_user->id; $meta->key = 'passwordResetCode'; $meta->value = $hash; $meta->save(); $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->_user->id, 'key' => 'passwordResetExpires')); if ($meta === NULL) { $meta = new UserMetadata(); } $meta->user_id = $this->_user->id; $meta->key = 'passwordResetExpires'; $meta->value = $expires; $meta->save(); $emailSettings = new EmailSettings(); $emailSettings->send($this->_user, Yii::t('ciims.email', 'Your Password Reset Information'), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); // Set success flash Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array('{{email}}' => $this->email))); return true; }
/** * Sends an invite to a new user * @return boolean */ public function invite() { if (!$this->validate()) { return false; } $user = new Users(); $user->attributes = array('email' => $this->email, 'firstName' => null, 'lastName' => null, 'displayName' => null, 'password' => null, 'user_role' => 5, 'status' => Users::PENDING_INVITATION); // Create a new user, but bypass validation if ($user->save(false)) { $meta = new UserMetadata(); $meta->attributes = array('user_id' => $user->id, 'key' => 'invitationKey', 'value' => Cii::generateSafeHash()); // If the key was savedm send the email out if ($meta->save()) { $emailSettings = new EmailSettings(); $emailSettings->send($user, Yii::t('ciims.models.InvitationForm', "You've Been Invited..."), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.invite', array('user' => $user, 'hash' => $meta->value), true, true); return true; } $user->delete(); } return false; }
/** * Sends the verification email to the user. This is broken to it's own method to allow for the resending email to be resent * @return boolean */ public function sendVerificationEmail() { $emailSettings = new EmailSettings(); return $emailSettings->send($this->_user, Yii::t('ciims.models.Users', 'CiiMS Email Change Notification'), 'base.themes.' . Cii::getConfig('theme', 'default') . '.views.email.email-change', array('key' => $this->setNewEmailChangeKey(), 'user' => $this->_user)); }
/** * Creates a new user, and sends the appropriate messaging out * @return boolean */ public function save($sendEmail = true) { if (!$this->validate()) { return false; } $this->_user = new Users(); // Set the model attributes $this->_user->attributes = array('email' => $this->email, 'password' => $this->password, 'username' => $this->username, 'user_role' => 1, 'status' => $sendEmail ? Users::PENDING_INVITATION : Users::ACTIVE); // If we saved the user model, return true if ($this->_user->save()) { // This class my be extended by other modules, in which case we don't need to send an activation form if we don't want need it to. if ($sendEmail) { $meta = new UserMetadata(); $meta->attributes = array('user_id' => $this->_user->id, 'key' => 'activationKey', 'value' => Cii::generateSafeHash()); $meta->save(); // Send the registration email $emailSettings = new EmailSettings(); $emailSettings->send($this->_user, Yii::t('ciims.email', 'Activate Your Account'), 'base.themes.' . Cii::getConfig('theme', 'default') . '.views.email.register', array('user' => $this->_user, 'hash' => $meta->value), true, true); } return true; } return false; }
/** * Sets some default values for the user record. * TODO: This should have been moved to CiiModel * @see CActiveRecord::beforeValidate() **/ public function beforeValidate() { // If the password is nulled, or unchanged if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) { if (!$this->isNewRecord) { $this->password = $this->_oldAttributes['password']; } } else { $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost())); if (!$this->isNewRecord) { $emailSettings = new EmailSettings(); $emailSettings->send($this, Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.passwordchange', array('user' => $this)); } } return parent::beforeValidate(); }
/** * Generic method for sending an email. Instead of having to call a bunch of code all over over the place * This method can be called which should be able to handle almost anything. * @deprecated, @todo: Deprecate usage of this method * @see models/settings/EmailSettings::send * @return boolean */ public function sendEmail($user, $subject = "", $viewFile, $content = array(), $return = true, $processOutput = true, $debug = false) { Yii::log(Yii::t('ciims.core', 'Use of CiiController::sendEmail is deprecated, and will be dropped in a future version. Use EmailSettings::send instead'), 'warning', 'ciims.core'); $email = new EmailSettings(); return $email->send($user, $subject, $viewFile, $content, $return, $processOutput, YII_DEBUG); }