Ejemplo n.º 1
0
 public function afterSave($event)
 {
     if (Yii::app() instanceof CWebApplication) {
         if (Yii::app()->user->getState(UserIdentity::STATE_AUDIT_TRAIL, true)) {
             $isNewRecord = $this->getOwner()->getIsNewRecord();
             UserActivityLog::model()->addRecord(array('user_id' => Yii::app()->user->id, 'ip' => Common::getIp(), 'action' => $isNewRecord ? 'create' : 'update', 'activity' => $this->prepareString($isNewRecord ? $this->createTemplate : $this->updateTemplate)));
         }
     }
     return parent::afterSave($event);
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     //获取用户名和密码
     $name = Yii::app()->request->getParam('name');
     $password = Yii::app()->request->getParam('password');
     if (!$name) {
         Error::output(Error::ERR_NO_USER_NAME);
     }
     if (!$password) {
         Error::output(Error::ERR_NO_PASSWORD);
     }
     //获取用户模型
     $userinfo = Members::model()->find('name=:name', array(':name' => $name));
     if (!$userinfo) {
         Error::output(Error::ERR_NO_USER);
     } else {
         $_password = md5($userinfo->salt . $password);
         if ($_password != $userinfo->password) {
             Error::output(Error::ERR_INVALID_PASSWORD);
         }
     }
     //登陆成功生成user_login
     $userLogin = UserLogin::model()->find('user_id = :user_id', array(':user_id' => $userinfo->id));
     if (!$userLogin) {
         //不存在就创建
         $userLogin = new UserLogin();
         $userLogin->user_id = $userinfo->id;
         $userLogin->username = $name;
     }
     $userLogin->login_time = time();
     $userLogin->token = md5(time() . Common::getGenerateSalt());
     $userLogin->visit_client = Common::getClientType();
     $userLogin->ip = Common::getIp();
     $userLogin->save();
     $member = CJSON::decode(CJSON::encode($userinfo));
     $member['token'] = $userLogin->token;
     unset($member['password'], $member['salt']);
     //返回数据
     //如果存在头像,就返回
     if ($member['avatar']) {
         //取图片数据
         $material = Material::model()->findByPk($member['avatar']);
         $member['avatar'] = array('host' => Yii::app()->params['img_url'], 'filepath' => $material->filepath, 'filename' => $material->filename);
     }
     Out::jsonOutput($member);
 }
Ejemplo n.º 3
0
 public function add($type = 'orders', $item_id = '', $action = 'exchange', $result = 'failure', $message = '', $data = array())
 {
     $data += array('user_id' => $this->user->id ? $this->user->id : 0, 'user_name' => $this->user->name ? $this->user->name : '', 'user_ip' => Common::getIp());
     $sql = "INSERT INTO {{user_logs}}\n\t\t\t\tVALUES(:log_id, :user_id, :log_type, :log_item_id, :log_action, :log_result, :log_message, :log_data, :user_ip, :lasttime)";
     $this->db->prepare($sql);
     $this->db->bindValue(':log_id', 0, PDO::PARAM_INT);
     $this->db->bindValue(':user_id', $this->user->isLogin() ? $this->user->id : 0, PDO::PARAM_INT);
     $this->db->bindValue(':log_type', $type, PDO::PARAM_STR);
     $this->db->bindValue(':log_item_id', $item_id, PDO::PARAM_INT);
     $this->db->bindValue(':log_action', $action, PDO::PARAM_STR);
     $this->db->bindValue(':log_result', $result, PDO::PARAM_STR);
     $this->db->bindValue(':log_message', $message, PDO::PARAM_STR);
     $this->db->bindValue(':log_data', json_encode($data), PDO::PARAM_STR);
     $this->db->bindValue(':user_ip', Common::getIp(true), PDO::PARAM_INT);
     $this->db->bindValue(':lasttime', $_SERVER['REQUEST_TIME'], PDO::PARAM_INT);
     if (!$this->db->execute()) {
         //
     }
 }
Ejemplo n.º 4
0
 /**
  * Add login log for Admin/Staff users
  */
 protected function addLogInLog()
 {
     UserLoginLog::model()->addRecord(array('user_id' => $this->_id, 'ip' => Common::getIp()));
 }
Ejemplo n.º 5
0
require '../include/init.inc.php';
$user_name = $password = $remember = $verify_code = '';
extract($_POST, EXTR_IF_EXISTS);
if (Common::isPost()) {
    //	去掉验证码 if(strtolower($verify_code) != strtolower($_SESSION['osa_verify_code'])){
    if (0) {
        OSAdmin::alert("error", ErrorMessage::VERIFY_CODE_WRONG);
    } else {
        $user_info = User::checkPassword($user_name, $password);
        if ($user_info) {
            if ($user_info['status'] == 1) {
                User::loginDoSomething($user_info['user_id']);
                if ($remember) {
                    $encrypted = OSAEncrypt::encrypt($user_info['user_id']);
                    User::setCookieRemember(urlencode($encrypted), 30);
                }
                $ip = Common::getIp();
                SysLog::addLog($user_name, 'LOGIN', 'User', UserSession::getUserId(), json_encode(array("IP" => $ip)));
                Common::jumpUrl('panel/index.php');
            } else {
                OSAdmin::alert("error", ErrorMessage::BE_PAUSED);
            }
        } else {
            OSAdmin::alert("error", ErrorMessage::USER_OR_PWD_WRONG);
            SysLog::addLog($user_name, 'LOGIN', 'User', '', json_encode(ErrorMessage::USER_OR_PWD_WRONG));
        }
    }
}
Template::assign('_POST', $_POST);
Template::assign('page_title', '登入');
Template::Display('login.tpl');
Ejemplo n.º 6
0
 public static function loginDoSomething($user_id)
 {
     $user_info = User::getUserById($user_id);
     if ($user_info['status'] != 1) {
         Common::jumpUrl("login.php");
         return;
     }
     //读取该用户所属用户组将该组的权限保存在$_SESSION中
     $user_group = UserGroup::getGroupById($user_info['user_group']);
     $user_info['group_id'] = $user_group['group_id'];
     $user_info['user_role'] = $user_group['group_role'];
     $user_info['shortcuts_arr'] = explode(',', $user_info['shortcuts']);
     $menu = MenuUrl::getMenuByUrl('/admin/setting.php');
     if (strpos($user_group['group_role'], $menu['menu_id'])) {
         $user_info['setting'] = 1;
     }
     $login_time = time();
     $login_ip = Common::getIp();
     $update_data = array('login_ip' => $login_ip, 'login_time' => $login_time);
     User::updateUser($user_info['user_id'], $update_data);
     $user_info['login_ip'] = $login_ip;
     $user_info['login_time'] = Common::getDateTime($login_time);
     UserSession::setSessionInfo($user_info);
 }
Ejemplo n.º 7
0
            <div style="margin:10px 0 10px 10px;">
                <table class="tb_1" style="border:1px solid #cfe1ee; color:#666; border-collapse:collapse; width:700px; " >
                    <tr>
                        <th  colspan="2">管理员详细信息</th>
                    </tr>
                    <tr>
                        <td>登陆名:<strong style="color:#FF6600; font-weight:normal">
                                <?php 
session_start();
if (isset($_SESSION["username"])) {
    echo $_SESSION["username"];
}
?>
</strong></td>
                        <td>IP地址:<?php 
echo Common::getIp();
?>
</td>
                    </tr>
                    <tr>
                        <td>操作系统:<?php 
echo Common::GetOs();
?>
</td>
                        <td>浏览器:<?php 
echo Common::GetBrowser();
?>
</td>
                    </tr>
                    <tr>
                        <td>支持 CSS:</td>
Ejemplo n.º 8
0
 /**
  * Add activity
  * @param integer $user_id
  * @param string $type
  * @param string $description
  */
 public function addActivity($user_id, $type, $description)
 {
     return Yii::app()->db->createCommand()->insert($this->tableName(), array('user_id' => $user_id, 'type' => $type, 'description' => $description, 'ip_address' => Common::getIp(), 'datetime' => new CDbExpression('NOW()')));
 }