/** * 检查cookie中是否有用户信息 */ public static function userCheckCookie() { $ret = false; //cookie和session 有一个不存在就退出 if (!isset($_COOKIE['userinfo']) || !isset($_SESSION['userid']) || empty($_SESSION['userid'])) { self::userLoginOut(); //退出登陆 } else { if (!empty($_SESSION['userid'])) { //如果session存在 表示当前帐号已登录 需要更新帐号最后操作时间 //echo 2; $status = permission::userSeleteStatus($_SESSION['userid']); //print_r($status); if ($status['status'] == 0) { //说明可登录 //更新临时表的时间 permission::usermodelUpdateByUserid($_SESSION['userid'], 2); $ret = true; } else { self::userLoginOut(); //退出登陆 } } else { $ret = true; } } if ($ret) { $auth = usercookie::daddslashes(explode("\t", usercookie::authcode($_COOKIE['userinfo'], 'DECODE'))); // list($cookieUserid, $cookieUsername, $cookiePassword) = empty($auth) || count($auth) < 3 ? array('', '', '') : $auth; //赋值auth至userid和username和密码 usercookie::userSet($cookieUserid, $cookieUsername, $cookiePassword); } return $ret; }
/** *用户登录 * @param $username用户名 * @param $password密码 * 返回"true"为成功,不为true返回失败信息 */ public static function userLogin($username = NULL, $password = NULL) { $ret = array('status' => 0, 'msg' => ''); $ret_num = 2; try { if (!empty($_SESSION['user_id'])) { } if (empty($username) || empty($password)) { throw new Exception("用户名或密码输入有误"); } $password = md5("beubeu" . md5($password)); $users = self::userSelectByParm("", $username, $password); //查询用户表用户名和密码是否正确 if (empty($users)) { //大于0说明数据库查询有数据 $ret_num = 2; //用户名密码错误 throw new Exception('用户名密码错误'); } $currenttime = time(); ///echo $currenttime." ".$users['endtime'];exit(); if ($currenttime > strtotime($users['endtime'])) { //如果当前时间大于到期时间说明已过期 $ret_num = 3; throw new Exception('帐号过期'); } self::usermodelUpdateByUserid($users['id'], 2); //$ret_status=self::userSeleteStatus($users['id']); //print_r($ret_status);exit(); //if($ret_status['status']==1){//说明可登录 // $ret_num=8; // throw new Exception('帐号已登陆'); //} //设置seesion和cookie if (!empty($users["type"]) && $users["type"] == Yii::app()->params['sub_type']) { $ret_num = 6; throw new Exception('用户访问权限不够'); } //用户需要进行IP验证的就验证 if ($users['ip_limit'] == 1) { $sel = Yii::app()->db->createCommand(); $ipp2 = $sel->select('IP')->from('beu_user_ip_limit')->where('status=1 and userid=' . $users['id'])->queryAll(); if (count($ipp2) == 0) { $ret_num = 5; throw new Exception('IP未设置'); } $is_bool = false; foreach ($ipp2 as $value) { if ($value['IP'] == Comm::getSourceIp()) { $is_bool = true; break; } } if (!$is_bool) { $ret_num = 5; throw new Exception('当前访问IP不在设置范围内'); } } $users['type'] = self::userTypeChange($users['type'], $users['ERP3_status']); //权限转换 if ($users['type'] > 70 || $users['type'] < 51) { //用户权限级别不再范围表示其权限不可访问后台 $ret_num = 6; throw new Exception('用户访问权限不够'); } //$_SESSION ['type'] = $users['type']; //$_SESSION ['touchid'] = json_decode ( $userinfo ['touchid'], true ); //$_SESSION ['permissions'] = json_decode ( $userinfo ['permissions'], true ); $_SESSION['user_id'] = $users['id']; $_SESSION['userid'] = $users['id']; $_SESSION['user'] = $users['username']; //用户名 $_SESSION['type'] = $users['type']; //用户类型,2为管理员,5为品牌,10为普通用户 $_SESSION['istotalaccount'] = $users['istotalaccount']; //是非品牌总管理 1.是 0.否 $_SESSION['account'] = isset($users['account']) && !empty($users['account']) ? $users['account'] : 0; //对应的账户类型 beu_useraccount.id $_SESSION['touchidd'] = isset($users['touchid']) && !empty($users['touchid']) ? implode(',', json_decode($users['touchid'], true)) : ''; $_SESSION['xiazai_v'] = 1; //是有可下载图片 $_SESSION['brandid'] = isset($users['brandid']) && !empty($users['brandid']) ? $users['brandid'] : 0; /************* 总分屏配置 start ********************/ $_SESSION['clothes_table'] = 'touch_clothes'; $_SESSION['table_where'] = ''; $_SESSION['is_push'] = 0; $_SESSION['sub_id'] = 0; /************* 总分屏配置 end ********************/ Yii::app()->cache->delete(CacheName::getCacheName('user_action_Info') . $users['id']); //清除用户的可访问页面列表缓存 usercookie::userSet($users['id'], $username, $password); //删除该用户临时数据 //self::usermodeDeleteByUserid($users['id']); //将该用户添加到临时表中 //self::usermodeForAdd($users['id']); $ret_num = 4; $ret['status'] = 1; } catch (Exception $e) { $ret['msg'] = $e->getMessage(); } $ret['data'] = $ret_num; return $ret; }