Esempio n. 1
0
 public function actionUpdate()
 {
     $profileField = array("birthday", "bio", "telephone", "address", "qq");
     $userField = array("mobile", "email");
     $model = array();
     foreach ($_POST as $key => $value) {
         if (in_array($key, $profileField)) {
             if ($key == "birthday" && !empty($value)) {
                 $value = strtotime($value);
             }
             $model["UserProfile"][$key] = StringUtil::filterCleanHtml($value);
         } elseif (in_array($key, $userField)) {
             $model["User"][$key] = StringUtil::filterCleanHtml($value);
         }
     }
     foreach ($model as $modelObject => $value) {
         $modelObject::model()->modify(Yii::app()->user->uid, $value);
     }
     UserUtil::cleanCache(Yii::app()->user->uid);
     exit;
 }
Esempio n. 2
0
 public function checkUserGroup($uid)
 {
     $uid = intval($uid);
     $user = User::model()->fetchByUid($uid);
     if (empty($user)) {
         return 0;
     }
     $credits = $this->countCredit($uid, false);
     $updateArray = array();
     $groupId = $user["groupid"];
     if (0 < $user["groupid"]) {
         $group = UserGroup::model()->fetchByPk($user["groupid"]);
     } else {
         $group = array();
     }
     if ($user["credits"] != $credits) {
         $updateArray["credits"] = $credits;
         $user["credits"] = $credits;
     }
     $user["credits"] = $user["credits"] == "" ? 0 : $user["credits"];
     $sendNotify = false;
     if (empty($group) || !($group["creditshigher"] <= $user["credits"]) && $user["credits"] < $group["creditslower"]) {
         $newGroup = UserGroup::model()->fetchByCredits($user["credits"]);
         if (!empty($newGroup)) {
             if ($user["groupid"] != $newGroup["gid"]) {
                 $updateArray["groupid"] = $groupId = $newGroup["gid"];
                 $sendNotify = true;
             }
         }
     }
     if ($updateArray) {
         User::model()->modify($uid, $updateArray);
         UserUtil::cleanCache($uid);
     }
     if ($sendNotify) {
         Notify::model()->sendNotify($uid, "user_group_upgrade", array("{groupname}" => $newGroup["title"], "{url}" => Ibos::app()->urlManager->createUrl("user/home/credit", array("op" => "level", "uid" => $uid))));
     }
     return $groupId;
 }
Esempio n. 3
0
 public function actionPersonal()
 {
     $op = EnvUtil::getRequest("op");
     if (!in_array($op, array("profile", "avatar", "history", "password", "skin", "remind"))) {
         $op = "profile";
     }
     if (EnvUtil::submitCheck("userSubmit")) {
         if (!$this->getIsMe()) {
             throw new EnvException(Ibos::lang("Parameters error", "error"));
         }
         $data = $_POST;
         if ($op == "profile") {
             $profileField = array("birthday", "bio", "telephone", "address", "qq");
             $userField = array("mobile", "email");
             $model = array();
             foreach ($_POST as $key => $value) {
                 if (in_array($key, $profileField)) {
                     if ($key == "birthday" && !empty($value)) {
                         $value = strtotime($value);
                     }
                     $model["UserProfile"][$key] = StringUtil::filterCleanHtml($value);
                 } elseif (in_array($key, $userField)) {
                     $model["User"][$key] = StringUtil::filterCleanHtml($value);
                 }
             }
             foreach ($model as $modelObject => $value) {
                 $modelObject::model()->modify($this->getUid(), $value);
             }
         } elseif ($op == "password") {
             $user = $this->getUser();
             $update = false;
             if ($data["originalpass"] == "") {
                 $this->error(Ibos::lang("Original password require"));
             } elseif (strcasecmp(md5(md5($data["originalpass"]) . $user["salt"]), $user["password"]) !== 0) {
                 $this->error(Ibos::lang("Password is not correct"));
             } else {
                 if (!empty($data["newpass"]) && strcasecmp($data["newpass"], $data["newpass_confirm"]) !== 0) {
                     $this->error(Ibos::lang("Confirm password is not correct"));
                 } else {
                     $password = md5(md5($data["newpass"]) . $user["salt"]);
                     $update = User::model()->updateByUid($this->getUid(), array("password" => $password, "lastchangepass" => TIMESTAMP));
                 }
             }
         } elseif ($op == "remind") {
             $remindSetting = array();
             foreach (array("email", "sms", "app") as $field) {
                 if (!empty($data[$field])) {
                     foreach ($data[$field] as $id => $value) {
                         $remindSetting[$id][$field] = $value;
                     }
                 }
             }
             if (!empty($remindSetting)) {
                 $remindSetting = serialize($remindSetting);
             } else {
                 $remindSetting = "";
             }
             UserProfile::model()->updateByPk($this->getUid(), array("remindsetting" => $remindSetting));
         }
         UserUtil::cleanCache($this->getUid());
         $this->success(Ibos::lang("Save succeed", "message"), $this->createUrl("home/personal", array("op" => $op)));
     } else {
         if (in_array($op, array("avatar", "history", "password", "remind"))) {
             if (!$this->getIsMe()) {
                 $this->error(Ibos::lang("Parameters error", "error"), $this->createUrl("home/index"));
             }
         }
         $dataProvider = "get" . ucfirst($op);
         $data = array("user" => $this->getUser());
         if (method_exists($this, $dataProvider)) {
             $data = array_merge($data, $this->{$dataProvider}());
         }
         $data["op"] = $op;
         $this->setPageState("breadCrumbs", array(array("name" => Ibos::lang("Home"), "url" => $this->createUrl("home/index")), array("name" => Ibos::lang("Profile"))));
         $this->render($op, $data);
     }
 }