/** * 设置最后登录信息 * @param User $user * @throws \Exception */ public static function setLastLoginInfo($user) { cookie()->set("LoginFlag", date("Y-m-d")); $user->set(array('last_login_ip' => Ip::getInstance()->realip(), 'last_login_time' => date("Y-m-d H:i:s"))); }
/** * 构造方法,使用评论的信息和对应的用户类 * @param array $set_info * @param int $user_id */ function __construct($set_info, $user_id) { $this->ip_c = Ip::getInstance(); $this->user = User::getUser($user_id); if (is_array($set_info) && isset($set_info['comment_id'])) { static $names = []; if (count($names) === 0) { $ref = new \ReflectionClass($this); foreach ($ref->getProperties() as $ro) { $names[] = $ro->getName(); } $names = array_flip($names); unset($names['ip_c'], $names['user'], $names['sub_node']); } if (isset($set_info['comment_ip'])) { $set_info['comment_ip'] = $this->ip_c->bin2ip($set_info['comment_ip']); } foreach ($set_info as $k => $v) { if (isset($names[$k])) { $this->{$k} = $v; } } self::$comment_stack[$this->getCommentId()] = $this; } else { Log::write(_("Comment class construct error"), Log::ALERT); } }
/** * @param $list array * @throws \Exception */ public function set($list) { $data = []; $update = []; foreach ($list as $name => $value) { $name = trim($name); if ($name !== 'id' && in_array($name, self::$column_list)) { $data[$name] = $value; $update["user_" . $name] = $value; if (substr($name, -3) === '_ip') { $update["user_" . $name] = Ip::getInstance()->ip2bin($value); } } } lib()->load('UserCheck'); if (isset($update['user_aliases']) && empty($update['user_aliases'])) { throw new \Exception(_("Aliases can't set empty.")); } if (isset($update['user_email']) && !UserCheck::CheckEmailChar($update['user_email'])) { throw new \Exception(_("Email verify check Error")); } if (isset($update['user_name']) && !UserCheck::CheckUsernameChar($update['user_name'])) { throw new \Exception(_("Username verify check Error")); } if (isset($update['user_password']) && !UserCheck::CheckPasswordChar($update['user_password'])) { throw new \Exception(_("Password verify check Error")); } if (isset($update['user_url']) && $update['user_url'] != "" && !filter_var($update['user_url'], FILTER_VALIDATE_URL)) { throw new \Exception(_("Url check error")); } if (count($update) > 0) { if (db()->update("users", $update, ['id' => $this->id]) === false) { throw new \Exception(_("Can't update User info.") . debug("SQL msg:" . implode(",", db()->error()['write']))); } foreach ($data as $n => $v) { $this->{$n} = $v; } } }