Наследование: extends Illuminate\Database\Eloquent\Model
Пример #1
0
 /**
  * Login
  *
  * @JSON
  */
 public function login()
 {
     /**
      * 1. 判断用户是否已经登录,
      *      若已经登录,则直接跳转到控制面板(仪表盘)中.
      * 2. 加载登录页面模板,进入登录页面.
      */
     $user = User::getCurrent();
     if ($user->uid) {
         header("Location:/member");
     } else {
         if (isset($_REQUEST['email']) && isset($_REQUEST['passwd'])) {
             $result = array('error' => 1, 'message' => '账户不存在啊喂!');
             $email = htmlspecialchars(trim($_REQUEST['email']));
             $passwd = htmlspecialchars(trim($_REQUEST['passwd']));
             $remember_me = htmlspecialchars(trim($_REQUEST['remember_me']));
             $user = User::getUserByEmail($email);
             if ($user) {
                 if ($user->verifyPassword($passwd)) {
                     $result['error'] = 0;
                     $result['message'] = '登录成功,即将跳转到 >仪表盘';
                     $remember_me == 'week' ? $ext = 3600 * 24 * 7 : ($ext = 3600);
                     $expire = time() + $ext;
                     $token = md5($user->uid . ":" . $user->email . ":" . $user->passwd . ":" . $expire . ":" . COOKIE_KEY);
                     setcookie("uid", base64_encode(Encrypt::encode($user->uid, ENCRYPT_KEY)), $expire, "/");
                     setcookie("expire", base64_encode(Encrypt::encode($expire, ENCRYPT_KEY)), $expire, "/");
                     setcookie("token", base64_encode(Encrypt::encode($token, ENCRYPT_KEY)), $expire, "/");
                     $_SESSION['currentUser'] = $user;
                     Logger::getInstance()->info('user [' . $user->email . '] Login success');
                 } else {
                     $result['message'] = "账户名或密码错误, 请检查后再试!";
                     Logger::getInstance()->info('user [' . $user->email . '] Login failed! wrong password');
                 }
             }
             return $result;
         } else {
             $data['globalMessage'] = MessageModel::getGlobalMessage();
             Template::setContext($data);
             Template::setView('panel/login');
         }
     }
 }
Пример #2
0
    /**
     * 获取下拉菜单
     */
    public static function getNavDropdown()
    {
        $user = \Model\User::getCurrentUser();
        $msgCount = \Model\Message::getMsgCount();
        return !$user ? '' : <<<Dropdown
\t\t\t\t\t\t\t<ul class="nav pull-right">
\t\t\t\t\t\t\t\t<li class="dropdown">
\t\t\t\t\t\t\t\t\t<a href="javacript:;" class="dropdown-toggle" data-toggle="dropdown">{$user->user_name}<b class="caret"></b></a>
\t\t\t\t\t\t\t\t\t<ul class="dropdown-menu">
\t\t\t\t\t\t\t\t\t\t<li><a href="/app/user/index.php">用户中心</a></li>
\t\t\t\t\t\t\t\t\t\t<li><a href="/app/user/index.php#user-msg" id="msgbox" title="你有 {$msgCount} 条未读消息">消息( <b>{$msgCount}</b> )</a></i>\t\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t\t\t<li class="divider"></li>
\t\t\t\t\t\t\t\t\t\t<li><a href="/app/unuse/new.php">发表新闲置物品</a></li>
\t\t\t\t\t\t\t\t\t\t<li><a href="/app/require/new.php">发表新的需求</a></li>
\t\t\t\t\t\t\t\t\t\t<li class="divider"></li>
\t\t\t\t\t\t\t\t\t\t<li><a href="javascript:;" id="yike_logout">注销</a></li>
\t\t\t\t\t\t\t\t\t</ul>
\t\t\t\t\t\t\t\t</li>
\t\t\t\t\t\t\t</ul>
Dropdown;
    }
Пример #3
0
 /**
  * 主页面 仪表盘
  */
 public function index()
 {
     $user = User::getUserByUserId(User::getCurrent()->uid);
     $data['user'] = $user;
     $data['online'] = Stats::countOnline();
     $data['userCount'] = Stats::countUser();
     $data['useUserCount'] = Stats::countUseUser();
     // 使用过服务的用户数
     $data['checkCount'] = Stats::countSignUser();
     $data['onlineNum'] = 0.0;
     // default online number.
     if ($data['online'] !== 0 && $data['userCount'] !== 0) {
         $data['onlineNum'] = round($data['online'] / $data['userCount'], 2) * 100;
     }
     $data['allTransfer'] = Utils::flowAutoShow($user->transfer);
     $data['useTransfer'] = $user->flow_up + $user->flow_down;
     // round(() / Utils::mb(), 2);
     $data['slaTransfer'] = Utils::flowAutoShow($user->transfer - $data['useTransfer']);
     $data['pctTransfer'] = 0.0;
     if (is_numeric($data['useTransfer']) && $data['useTransfer'] > 0 && is_numeric($user->transfer) && $user->transfer > 0) {
         $data['pctTransfer'] = round($data['useTransfer'] / $user->transfer, 2) * 100;
     }
     $data['useTransfer'] = Utils::flowAutoShow($data['useTransfer'], 1);
     $tmp = explode(" ", $data['useTransfer']);
     $data['useTransfer'] = $tmp[0];
     $data['useTransferUnit'] = count($tmp) > 1 ? $tmp[1] : 'KB';
     $data['systemTransfer'] = round(Stats::countTransfer() / Utils::gb(), 2);
     // 全部用户产生的流量
     $data['checkedTime'] = date('m-d H:i', $user->lastCheckinTime);
     $data['lastOnlineTime'] = date('Y-m-d H:i:s', $user->lastConnTime);
     $data['checked'] = strtotime(date('Y-m-d 00:00:00', time())) > strtotime(date('Y-m-d H:i:s', $user->lastCheckinTime));
     $data['userIp'] = Utils::getUserIP();
     // Message
     $data['globalMessage'] = Message::getGlobalMessage();
     $data['allNode'] = Stats::countNode();
     Template::setContext($data);
     Template::setView('panel/member');
 }
Пример #4
0
 /**
  * 查询
  * @JSON
  */
 public function query()
 {
     $result = array('error' => 1, 'message' => 'Request failed');
     $result['message_id'] = $_GET['message_id'];
     if ($_GET['message_id'] != null) {
         $rs = MessageModel::getMessageById(trim($_GET['message_id']));
         $rs->pushTime = date('Y-m-d H:i:s', $rs->pushTime);
         $rs->pushEndTime = date('Y-m-d H:i:s', $rs->pushEndTime);
         $rs->content = Utils::br2nl($rs->content);
         if ($rs) {
             $result = array('error' => 0, 'message' => 'success', 'modal' => $rs);
         }
     }
     return $result;
 }