/** * It only updates the password column whenever a new password flag is set to true and the model is not new. * @see CActiveRecord::save() */ public function save($runValidation = true, $attributes = null, $transaction = true) { if ($runValidation && !$this->validate($attributes)) { return false; } if ($this->isNewRecord) { $this->date_created = new CDbExpression('NOW()'); if (!$this->hasErrors('password')) { $this->password = crypt($this->password, Randomness::blowfishSalt()); } } else { $this->date_updated = new CDbExpression('NOW()'); if ($this->isNewPassword) { $this->password = crypt($this->password, Randomness::blowfishSalt()); } } $saveWithProfileImage = false; if ($transaction) { $tr = Yii::app()->db->beginTransaction(); try { $saveWithProfileImage = $this->saveWithProfileImage($runValidation, $attributes); $tr->commit(); } catch (Exception $e) { $tr->rollback(); throw $e; } } else { $saveWithProfileImage = $this->saveWithProfileImage($runValidation, $attributes); } //null indicates there is no profile image uploaded, so we perform a normal save if ($saveWithProfileImage == null) { return parent::save($runValidation, $attributes); } else { return $saveWithProfileImage; } }
/** * @return hash string. */ public static function encrypting($string="", $salt="") { $hash = Yii::app()->getModule('user')->hash; if ($hash=="md5") return md5($string); if ($hash=="sha1") return sha1($string); if ($hash=='blowfish' && $salt=='') return crypt($string, Randomness::blowfishSalt()); if ($hash=='blowfish' && !empty($salt)) return crypt($string, $salt); else return hash($hash,$string); }
protected function beforeSave() { if (parent::beforeSave()) { $time = new Datetime(); if ($this->isNewRecord) { $this->created = $time->format('Y-m-d-h-m-s'); if (isset($_POST['User']['password'])) { $password = $_POST['User']['password']; } else { $password = rand(9999, 999999); } $this->password = crypt($password, Randomness::blowfishSalt()); } else { $this->last_activity = $time->format('Y-m-d-h-m-s'); } return true; } else { return false; } }