Beispiel #1
0
 public function beforeSave()
 {
     $randKey = tools::randMykeys(8);
     $this->hash = $randKey;
     $this->password = md5($this->password . $randKey);
     if ($this->classify == Users::CLASSIFY_COMMON_USER) {
         $this->status = Common::STATUS_PASSED;
     } else {
         $this->status = Common::STATUS_STAYCHECK;
     }
     if ($this->classify == Users::CLASSIFY_HOSPITAL) {
         if (!$this->areaid) {
             $this->addError('areaid', '请选择所在城市省份');
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Find AND Add
  * @param type $url
  * @return boolean|\Urls
  */
 public static function FAA($url)
 {
     $url = trim(htmlspecialchars_decode($url));
     if (!$url) {
         return false;
     }
     if (substr($url, -1) == '/') {
         $url = substr($url, 0, -1);
     }
     $hash = md5($url);
     $info = Urls::model()->find('hash=:hash', array(':hash' => $hash));
     if ($info) {
         return $info;
     }
     $code = '';
     $len = zmf::config('shortUrlsLen');
     $len = intval($len);
     if (!$len) {
         $len = 4;
     }
     for ($i = 0; $i < 10; $i++) {
         $code = tools::randMykeys($len);
         $codeInfo = Urls::model()->find('code=:code', array(':code' => $code));
         if (!$codeInfo) {
             break;
         }
     }
     if (!$code) {
         return false;
     }
     $attr = array('code' => $code, 'url' => $url, 'hash' => $hash);
     $model = new Urls();
     $model->attributes = $attr;
     if ($model->save()) {
         return $model;
     } else {
         return false;
     }
 }