コード例 #1
0
 /**
  * sendVerify 发送验证码
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function sendVerify()
 {
     $aAccount = $cUsername = I('post.account', '', 'op_t');
     $aType = I('post.type', '', 'op_t');
     $aType = $aType == 'mobile' ? 'mobile' : 'email';
     $aAction = I('post.action', 'config', 'op_t');
     if (!check_reg_type($aType)) {
         $str = $aType == 'mobile' ? L('_PHONE_') : L('_EMAIL_');
         $this->error($str . L('_ERROR_OPTIONS_CLOSED_') . L('_EXCLAMATION_'));
     }
     if (empty($aAccount)) {
         $this->error(L('_ERROR_ACCOUNT_CANNOT_EMPTY_'));
     }
     check_username($cUsername, $cEmail, $cMobile);
     $time = time();
     if ($aType == 'mobile') {
         $resend_time = modC('SMS_RESEND', '60', 'USERCONFIG');
         if ($time <= session('verify_time') + $resend_time) {
             $this->error(L('_ERROR_WAIT_1_') . ($resend_time - ($time - session('verify_time'))) . L('_ERROR_WAIT_2_'));
         }
     }
     if ($aType == 'email' && empty($cEmail)) {
         $this->error(L('_ERROR__EMAIL_'));
     }
     if ($aType == 'mobile' && empty($cMobile)) {
         $this->error(L('_ERROR_PHONE_'));
     }
     $checkIsExist = UCenterMember()->where(array($aType => $aAccount))->find();
     if ($checkIsExist) {
         $str = $aType == 'mobile' ? L('_PHONE_') : L('_EMAIL_');
         $this->error(L('_ERROR_USED_1_') . $str . L('_ERROR_USED_2_') . L('_EXCLAMATION_'));
     }
     $verify = D('Verify')->addVerify($aAccount, $aType);
     if (!$verify) {
         $this->error(L('_ERROR_FAIL_SEND_') . L('_EXCLAMATION_'));
     }
     $res = A(ucfirst($aAction))->doSendVerify($aAccount, $verify, $aType);
     if ($res === true) {
         if ($aType == 'mobile') {
             session('verify_time', $time);
         }
         $this->success(L('_ERROR_SUCCESS_SEND_'));
     } else {
         $this->error($res);
     }
 }
コード例 #2
0
 /**
  * sendVerify 发送验证码
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function sendVerify()
 {
     $aAccount = $cUsername = I('post.account', '', 'op_t');
     $aType = I('post.type', '', 'op_t');
     $aType = $aType == 'mobile' ? 'mobile' : 'email';
     $aAction = I('post.action', 'config', 'op_t');
     if (!check_reg_type($aType)) {
         $str = $aType == 'mobile' ? '手机' : '邮箱';
         $this->error($str . '选项已关闭!');
     }
     if (empty($aAccount)) {
         $this->error('帐号不能为空');
     }
     check_username($cUsername, $cEmail, $cMobile);
     $time = time();
     if ($aType == 'mobile') {
         $resend_time = modC('SMS_RESEND', '60', 'USERCONFIG');
         if ($time <= session('verify_time') + $resend_time) {
             $this->error('请' . ($resend_time - ($time - session('verify_time'))) . '秒后再发');
         }
     }
     if ($aType == 'email' && empty($cEmail)) {
         $this->error('请验证邮箱格式是否正确');
     }
     if ($aType == 'mobile' && empty($cMobile)) {
         $this->error('请验证手机格式是否正确');
     }
     $checkIsExist = UCenterMember()->where(array($aType => $aAccount))->find();
     if ($checkIsExist) {
         $str = $aType == 'mobile' ? '手机' : '邮箱';
         $this->error('该' . $str . '已被其他用户使用!');
     }
     $verify = D('Verify')->addVerify($aAccount, $aType);
     if (!$verify) {
         $this->error('发送失败!');
     }
     $res = A(ucfirst($aAction))->doSendVerify($aAccount, $verify, $aType);
     if ($res === true) {
         if ($aType == 'mobile') {
             session('verify_time', $time);
         }
         $this->success('发送成功,请查收');
     } else {
         $this->error($res);
     }
 }
コード例 #3
0
 /**
  * 后台首页
  * @author 麦当苗儿 <*****@*****.**>
  */
 public function index()
 {
     if (UID) {
         //判断用户是否登陆
         if (IS_POST) {
             /*修改默认的用户统计天数*/
             $count_day = I('post.count_day', C('COUNT_DAY'), 'intval');
             if (M('Config')->where(array('name' => 'COUNT_DAY'))->setField('value', $count_day) === false) {
                 $this->error('设置失败。');
             } else {
                 S('DB_CONFIG_DATA', null);
                 $this->success('设置成功。', 'refresh');
             }
         } else {
             /*首页显示的统计数据*/
             $this->meta_title = '管理首页';
             $today = date('Y-m-d', time());
             $today = strtotime($today);
             $count_day = C('COUNT_DAY');
             $count['count_day'] = $count_day;
             for ($i = $count_day; $i--; $i >= 0) {
                 $day = $today - $i * 86400;
                 $day_after = $today - ($i - 1) * 86400;
                 $week[] = date('m月d日', $day);
                 $user = UCenterMember()->where('status=1 and reg_time >=' . $day . ' and reg_time < ' . $day_after)->count() * 1;
                 $registeredMemeberCount[] = $user;
                 if ($i == 0) {
                     $count['today_user'] = $user;
                 }
             }
             $week = json_encode($week);
             $this->assign('week', $week);
             $count['total_user'] = $userCount = UCenterMember()->where(array('status' => 1))->count();
             $count['today_action_log'] = M('ActionLog')->where('status=1 and create_time>=' . $today)->count();
             $count['last_day']['days'] = $week;
             $count['last_day']['data'] = json_encode($registeredMemeberCount);
             // dump($count);exit;
             $this->assign('count', $count);
             $this->display();
         }
     } else {
         $this->redirect('Public/login');
     }
 }
コード例 #4
0
 /**
  * 后台首页
  * @author 麦当苗儿 <*****@*****.**>
  */
 public function index()
 {
     if (UID) {
         if (IS_POST) {
             $count_day = I('post.count_day', C('COUNT_DAY'), 'intval', 7);
             if (M('Config')->where(array('name' => 'COUNT_DAY'))->setField('value', $count_day) === false) {
                 $this->error(L('_ERROR_SETTING_') . L('_PERIOD_'));
             } else {
                 S('DB_CONFIG_DATA', null);
                 $this->success(L('_SUCCESS_SETTING_') . L('_PERIOD_'), 'refresh');
             }
         } else {
             $this->meta_title = L('_INDEX_MANAGE_');
             $today = date('Y-m-d', time());
             $today = strtotime($today);
             $count_day = C('COUNT_DAY', null, 7);
             $count['count_day'] = $count_day;
             for ($i = $count_day; $i--; $i >= 0) {
                 $day = $today - $i * 86400;
                 $day_after = $today - ($i - 1) * 86400;
                 $week_map = array('Mon' => L('_MON_'), 'Tue' => L('_TUES_'), 'Wed' => L('_WEDNES_'), 'Thu' => L('_THURS_'), 'Fri' => L('_FRI_'), 'Sat' => '<strong>' . L('_SATUR_') . '</strong>', 'Sun' => '<strong>' . L('_SUN_') . '</strong>');
                 $week[] = date('m月d日 ', $day) . $week_map[date('D', $day)];
                 $user = UCenterMember()->where('status=1 and reg_time >=' . $day . ' and reg_time < ' . $day_after)->count() * 1;
                 $registeredMemeberCount[] = $user;
                 if ($i == 0) {
                     $count['today_user'] = $user;
                 }
             }
             $week = json_encode($week);
             $this->assign('week', $week);
             $count['total_user'] = $userCount = UCenterMember()->where(array('status' => 1))->count();
             $count['today_action_log'] = M('ActionLog')->where('status=1 and create_time>=' . $today)->count();
             $count['last_day']['days'] = $week;
             $count['last_day']['data'] = json_encode($registeredMemeberCount);
             // dump($count);exit;
             $this->assign('count', $count);
             $this->display();
         }
     } else {
         $this->redirect('Public/login');
     }
 }
コード例 #5
0
 /**
  * sendVerify 发送验证码
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function sendVerify()
 {
     $aAccount = $cUsername = I('post.account', '', 'op_t');
     #=》获取邮件地址或是手机号码
     $aType = I('post.type', '', 'op_t');
     $aType = $aType == 'mobile' ? 'mobile' : 'email';
     #=》获取注册的方式,邮件或是手机
     $aAction = I('post.action', 'config', 'op_t');
     if (!check_reg_type($aType)) {
         $str = $aType == 'mobile' ? '手机' : '邮箱';
         $this->error($str . '选项已关闭!');
     }
     if (empty($aAccount)) {
         $this->error('帐号不能为空');
     }
     check_username($cUsername, $cEmail, $cMobile, $cCompany);
     if ($aType == 'email' && empty($cEmail)) {
         $this->error('请验证邮箱格式是否正确');
     }
     if ($aType == 'mobile' && empty($cMobile)) {
         $this->error('请验证手机格式是否正确');
     }
     $checkIsExist = UCenterMember()->where(array($aType => $aAccount))->find();
     if ($checkIsExist) {
         $str = $aType == 'mobile' ? '手机' : '邮箱';
         $this->error('该' . $str . '已被其他用户使用!');
     }
     #=>添加一条验证记录,并返回产生的随机数
     $verify = D('Verify')->addVerify($aAccount, $aType);
     if (!$verify) {
         $this->error('发送失败!');
     }
     #=> 实例化当前模块的控制器
     $res = A(ucfirst($aAction))->doSendVerify($aAccount, $verify, $aType);
     if ($res === true) {
         $this->success('发送成功,请查收');
     } else {
         $this->error($res);
     }
 }
コード例 #6
0
 public function newAccount()
 {
     $aUsername = I('post.username');
     $aNickname = I('post.nickname');
     $aPassword = I('post.password');
     // 行为限制
     $return = check_action_limit('reg', 'ucenter_member', 1, 1, true);
     if ($return && !$return['state']) {
         $this->error($return['info'], $return['url']);
     }
     $ucenterModel = UCenterMember();
     $uid = $ucenterModel->register($aUsername, $aNickname, $aPassword);
     if (0 < $uid) {
         //注册成功
         $this->addSyncLoginData($uid);
         $this->initRoleUser(1, $uid);
         //初始化角色用户
         $uid = $ucenterModel->login($aUsername, $aPassword, 1);
         //通过账号密码取到uid
         $this->doLogin($uid);
         $this->success('绑定成功!', session('login_http_referer'));
     } else {
         //注册失败,显示错误信息
         $this->error(A('Ucenter/Member')->showRegError($uid));
     }
 }
コード例 #7
0
 public function unbind()
 {
     $this->checkIsBind();
     $access_token = session('SYNCLOGIN_ACCESS_TOKEN');
     $openid = session('SYNCLOGIN_OPENID');
     $type = session('SYNCLOGIN_TYPE');
     $token = session('SYNCLOGIN_TOKEN');
     $user_info = D('Addons://SyncLogin/Info')->{$type}($token);
     if ($info1 = D('sync_login')->where("`type_uid`='" . $openid . "' AND type='" . $type . "'")->find()) {
         $user = UCenterMember()->where("id=" . $info1['uid'])->find();
         if (empty($user)) {
             D('sync_login')->where("type_uid=" . $openid . " AND type='" . $type . "'")->delete();
             //已经绑定过,执行登录操作,设置token
         } else {
             if ($info1['oauth_token'] == '') {
                 $syncdata['id'] = $info1['id'];
                 $syncdata['oauth_token'] = $access_token;
                 $syncdata['oauth_token_secret'] = $openid;
                 D('sync_login')->save($syncdata);
             }
             $uid = $info1['uid'];
         }
     } else {
         $Api = new UserApi();
         //usercenter表新增数据
         $uid = $Api->addSyncData();
         //member表新增数据
         D('Home/Member')->addSyncData($uid, $user_info);
         // 记录数据到sync_login表中
         $this->addSyncLoginData($uid, $access_token, $openid, $type, $openid);
         //保存头像
         $this->saveAvatar($user_info['head'], $openid, $uid, $type);
         $config = D('Config')->where(array('name' => 'USER_REG_WEIBO_CONTENT'))->find();
         $reg_weibo = $config['value'];
         //用户注册的微博内容
         if ($reg_weibo != '' && $config) {
             //为空不发微博
             //                D('Weibo/Weibo')->addWeibo($uid, $reg_weibo);
         }
     }
     $this->loginWithoutpwd($uid);
 }
コード例 #8
0
 public function doLogin()
 {
     $aUsername = $username = I('post.username', '', 'op_t');
     $aPassword = I('post.password', '', 'op_t');
     $aVerify = I('post.verify', '', 'op_t');
     $aRemember = I('post.remember', 0, 'intval');
     /* 检测验证码 */
     if (check_verify_open('login')) {
         if (!check_verify($aVerify)) {
             $res['info'] = L('_INFO_VERIFY_CODE_INPUT_ERROR_') . L('_PERIOD_');
             return $res;
         }
     }
     /* 调用UC登录接口登录 */
     check_username($aUsername, $email, $mobile, $aUnType);
     if (!check_reg_type($aUnType)) {
         $res['info'] = L('_INFO_TYPE_NOT_OPENED_') . L('_PERIOD_');
     }
     $uid = UCenterMember()->login($username, $aPassword, $aUnType);
     if (0 < $uid) {
         //UC登录成功
         /* 登录用户 */
         $Member = D('Member');
         $args['uid'] = $uid;
         $args = array('uid' => $uid, 'nickname' => $username);
         check_and_add($args);
         if ($Member->login($uid, $aRemember == 1)) {
             //登录用户
             //TODO:跳转到登录前页面
             $html_uc = '';
             if (UC_SYNC && $uid != 1) {
                 include_once './api/uc_client/client.php';
                 //同步登录到UC
                 $ref = M('ucenter_user_link')->where(array('uid' => $uid))->find();
                 $html_uc = uc_user_synlogin($ref['uc_uid']);
             }
             $oc_config = (include_once './OcApi/oc_config.php');
             if ($oc_config['SSO_SWITCH']) {
                 include_once './OcApi/OCenter/OCenter.php';
                 $OCApi = new \OCApi();
                 $html_oc = $OCApi->ocSynLogin($uid);
             }
             $html = empty($html_oc) ? $html_uc : $html_oc;
             $res['status'] = 1;
             $res['info'] = $html;
             //$this->success($html, get_nav_url(C('AFTER_LOGIN_JUMP_URL')));
         } else {
             $res['info'] = $Member->getError();
         }
     } else {
         //登录失败
         switch ($uid) {
             case -1:
                 $res['info'] = L('_INFO_USER_FORBIDDEN_');
                 break;
                 //系统级别禁用
             //系统级别禁用
             case -2:
                 $res['info'] = L('_INFO_PW_ERROR_') . L('_EXCLAMATION_');
                 break;
             default:
                 $res['info'] = $uid;
                 break;
                 // 0-接口参数错误(调试阶段使用)
         }
     }
     return $res;
 }
コード例 #9
0
 /**
  * checkVerify  验证验证码
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function checkVerify()
 {
     $aAccount = I('account', '', 'op_t');
     $aType = I('type', '', 'op_t');
     $aVerify = I('verify', '', 'intval');
     $aUid = I('uid', 0, 'intval');
     if (!is_login() || $aUid != is_login()) {
         $this->error('验证失败');
     }
     $aType = $aType == 'mobile' ? 'mobile' : 'email';
     $res = D('Verify')->checkVerify($aAccount, $aType, $aVerify, $aUid);
     if (!$res) {
         $this->error('验证失败');
     }
     UCenterMember()->where(array('id' => $aUid))->save(array($aType => $aAccount));
     $this->success('验证成功', U('ucenter/config/index'));
 }
コード例 #10
0
 public function doLogin()
 {
     $aUsername = $username = I('post.username', '', 'op_t');
     $aPassword = I('post.password', '', 'op_t');
     $aVerify = I('post.verify', '', 'op_t');
     $aRemember = I('post.remember', 0, 'intval');
     /* 检测验证码 */
     if (check_verify_open('login')) {
         if (!check_verify($aVerify)) {
             $res['info'] = "验证码输入错误。";
             return $res;
         }
     }
     /* 调用UC登录接口登录 */
     check_username($aUsername, $email, $mobile, $aUnType);
     if (!check_reg_type($aUnType)) {
         $res['info'] = "该类型未开放登录。";
     }
     $uid = UCenterMember()->login($username, $aPassword, $aUnType);
     if (0 < $uid) {
         //UC登录成功
         /* 登录用户 */
         $Member = D('Member');
         $args['uid'] = $uid;
         $args = array('uid' => $uid, 'nickname' => $username);
         check_and_add($args);
         if ($Member->login($uid, $aRemember == 1)) {
             //登录用户
             //TODO:跳转到登录前页面
             if (UC_SYNC && $uid != 1) {
                 //同步登录到UC
                 $ref = M('ucenter_user_link')->where(array('uid' => $uid))->find();
                 $html = '';
                 $html = uc_user_synlogin($ref['uc_uid']);
             }
             $oc_config = (include_once './OcApi/oc_config.php');
             if ($oc_config['SSO_SWITCH']) {
                 include_once './OcApi/OCenter/OCenter.php';
                 $OCApi = new \OCApi();
                 $html = $OCApi->ocSynLogin($uid);
             }
             $res['status'] = 1;
             $res['info'] = $html;
             //$this->success($html, get_nav_url(C('AFTER_LOGIN_JUMP_URL')));
         } else {
             $res['info'] = $Member->getError();
         }
     } else {
         //登录失败
         switch ($uid) {
             case -1:
                 $res['info'] = '用户不存在或被禁用!';
                 break;
                 //系统级别禁用
             //系统级别禁用
             case -2:
                 $res['info'] = '密码错误!';
                 break;
             default:
                 $res['info'] = $uid;
                 break;
                 // 0-接口参数错误(调试阶段使用)
         }
     }
     return $res;
 }
コード例 #11
0
ファイル: weixin.php プロジェクト: fishling/chatPro
function get_ucuser_uid($uid = 0)
{
    $mp_id = get_mpid();
    if ($uid !== NULL) {
        session('uid_' . $mp_id, $uid);
    } elseif (!empty($_REQUEST['uid'])) {
        session('uid_' . $mp_id, $_REQUEST['uid']);
    }
    //以上是带uid参数调用函数时设置session中的uid
    $uid = session('uid_' . $mp_id);
    $isWeixinBrowser = isWeixinBrowser();
    if (!$isWeixinBrowser) {
        //非微信浏览器返回false,调用此函数必须对false结果进行判断,非微信浏览器不可访问调用的controller
        return false;
    }
    //下面这段应该逻辑没问题,如果公众号配置信息错误或者没有snsapi_base作用域的获取信息权限可能会出现死循环,注释掉以下if可治愈
    if ($uid <= 0 && $isWeixinBrowser) {
        $map['openid'] = get_openid();
        $map['mp_id'] = $mp_id;
        $ucuser = D('Ucuser');
        $data = $ucuser->where($map)->find();
        if (!$data) {
            //公众号没有这个粉丝信息,就注册一个
            //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
            //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
            $aUsername = $aNickname = $map['openid'];
            //以openid作为默认UcenterMember用户名和Member昵称
            $aPassword = UCenterMember()->create_rand();
            //随机密码,用户未通过公众号注册,就不可登录网站
            $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com';
            //以openid@mpid123.com作为默认邮箱
            $mobile = arr2str(UCenterMember()->rand_mobile());
            //生成随机手机号以通过model校验,不实际使用,准确手机以微信绑定的为准
            $aUnType = 5;
            //微信公众号粉丝注册
            $aRole = 3;
            //默认公众号粉丝用户角色
            /* 注册用户 */
            $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType);
            if (0 < $uid) {
                //注册成功
                initRoleUser($aRole, $uid);
                //初始化角色用户
                set_user_status($uid, 1);
                //微信注册的用户状态直接设置为1
            } else {
                //注册失败,显示错误信息
            }
            $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']);
            //用注册member获取的统一uid注册微信粉丝
            session('uid_' . $mp_id, $uid);
        } else {
            $uid = $data['uid'];
            session('uid_' . $mp_id, $uid);
        }
    }
    if (empty($uid)) {
        return -1;
    }
    return $uid;
}
コード例 #12
0
 protected function unbind($syncData = null)
 {
     //$this->checkIsBind($syncData);
     $access_token = session('SYNCLOGIN_ACCESS_TOKEN');
     $openid = session('SYNCLOGIN_OPENID');
     $type = session('SYNCLOGIN_TYPE');
     $token = session('SYNCLOGIN_TOKEN');
     $user_info = D('Addons://SyncLogin/Info')->{$type}($token);
     $syncData === null && ($syncData = D('sync_login')->where(array('type_uid' => $openid, 'type' => $type))->find());
     if ($syncData) {
         $uid = $syncData['uid'];
         $user = UCenterMember()->where(array('id' => $syncData['uid']))->find();
         if (empty($user)) {
             $this->clearSyncLoginSession();
             //用户已经不存在,删除绑定记录
             D('sync_login')->where(array('type_uid' => $openid, 'type' => $type))->delete();
             return redirect(homeUrl());
         } else {
             //已经绑定过,执行登录操作,设置token
             if (!$syncData['oauth_token'] || $syncData['oauth_token'] != $access_token) {
                 $data = array();
                 $data['id'] = $syncData['id'];
                 $data['oauth_token'] = $access_token;
                 $data['oauth_token_secret'] = $openid;
                 D('sync_login')->save($data);
             }
         }
     } else {
         $Api = new UserApi();
         //usercenter表新增数据
         $uid = $Api->addSyncData();
         //member表新增数据
         D('Common/Member')->addSyncData($uid, $user_info);
         // 记录数据到sync_login表中
         $this->addSyncLoginData($uid, $access_token, $openid, $type, $openid);
         //保存头像
         $this->saveAvatar($user_info['head'], $openid, $uid, $type);
         $config = D('Config')->where(array('name' => 'USER_REG_WEIBO_CONTENT'))->find();
         $reg_weibo = $config['value'];
         //用户注册的微博内容
         if ($reg_weibo != '' && $config) {
             //为空不发微博
             D('Weibo/Weibo')->addWeibo($uid, $reg_weibo);
         }
     }
     $this->loginWithoutpwd($uid);
 }
コード例 #13
0
 /**
  * 集团用户登录
  */
 public function company_dologin()
 {
     $aUsername = I('post.username', '', 'op_t');
     $aUnType = 5;
     $aPassword = null;
     if (empty($aUsername)) {
         $res['info'] = '用户名不能为空';
     } else {
         $uid = UCenterMember()->cLogin($aUsername);
         $sessid = UCenterMember()->sessid($aUsername, $aPassword, $aUnType);
         // 登录成功
         if ($uid > 0) {
             $Member = D('Member');
             $args['uid'] = $uid;
             $args = array('uid' => $uid, 'nickname' => $aUsername);
             //判断用户IP和集团IP是否一致
             $user = $Member->where($args)->find();
             if (!empty($user)) {
                 $cmap['id'] = $user['cid'];
                 $company = M('Company')->where($cmap)->find();
                 if (!empty($company)) {
                     $checkIp = new \Expend\CheckIP($company['cip']);
                     //如果客户端IP是集团IP
                     if (TRUE === $checkIp->check(get_client_ip()) || ip2long(get_client_ip()) === ip2long($company['cip'])) {
                         //登录用户
                         if ($Member->login($uid, $aRemember == 1)) {
                             $res['sessid'] = $sessid;
                             $res['status'] = 1;
                         } else {
                             $res['info'] = $Member->getError();
                         }
                     } else {
                         $res['info'] = '用户名与集团IP不匹配';
                     }
                 } else {
                     $res['info'] = '用户名与集团IP不匹配';
                 }
             }
         } else {
             switch ($uid) {
                 case -1:
                     $res['info'] = '用户不存在或被禁用';
                     break;
                 case -3:
                     $res['info'] = '用户不为集团用户';
                     break;
                 default:
                     $res['info'] = $uid;
                     break;
                     // 0-接口参数错误(调试阶段使用)
             }
         }
     }
     return $res;
 }
コード例 #14
0
 /**
  * 将用户添加到用户组,入参uid,group_id
  * @author 朱亚杰 <*****@*****.**>
  */
 public function addToGroup()
 {
     $uid = I('uid');
     $gid = I('group_id');
     if (empty($uid)) {
         $this->error('参数有误');
     }
     $AuthGroup = D('AuthGroup');
     if (is_numeric($uid)) {
         if (is_administrator($uid)) {
             $this->error('该用户为超级管理员');
         }
         if (!M('Member')->where(array('uid' => $uid))->find()) {
             $this->error('管理员用户不存在');
         }
     }
     if ($gid && !$AuthGroup->checkGroupId($gid)) {
         $this->error($AuthGroup->error);
     }
     if ($AuthGroup->addToGroup($uid, $gid)) {
         if ($gid['0'] == 2) {
             $email = UCenterMember()->where(array('id' => $uid))->getField('email');
             $this->sendEmail($email);
         }
         $this->success('操作成功');
     } else {
         $this->error($AuthGroup->getError());
     }
 }
コード例 #15
0
 /**
  * 修改密码提交
  * @author huajie <*****@*****.**>
  */
 public function submitPassword()
 {
     //获取参数
     $password = I('post.old');
     empty($password) && $this->error('请输入原密码');
     $data['password'] = I('post.password');
     empty($data['password']) && $this->error('请输入新密码');
     $repassword = I('post.repassword');
     empty($repassword) && $this->error('请输入确认密码');
     if ($data['password'] !== $repassword) {
         $this->error('您输入的新密码与确认密码不一致');
     }
     $Api = new UserApi();
     $res = $Api->updateInfo(UID, $password, $data);
     if ($res['status']) {
         $this->success('修改密码成功!');
     } else {
         $this->error(UCenterMember()->getErrorMessage($res['info']));
     }
 }
コード例 #16
0
ファイル: query_user.php プロジェクト: fishling/chatPro
/**
 * 支持的字段有
 * member表中的所有字段,ucenter_member表中的所有字段
 * 等级:title
 * 头像:avatar32 avatar64 avatar128 avatar256 avatar512
 * 个人中心地址:space_url
 * 认证图标:icons_html
 *
 * @param      $fields array|string 如果是数组,则返回数组。如果不是数组,则返回对应的值
 * @param null $uid
 * @return array|null
 */
function query_user($fields = null, $uid = null)
{
    if ($fields === null) {
        $fields = array('nickname', 'space_url', 'avatar64', 'avatar128', 'uid');
    }
    //如果fields不是数组,则返回值也不是数组
    if (!is_array($fields)) {
        $result = query_user(array($fields), $uid);
        return $result[$fields];
    }
    if (in_array('score', $fields)) {
        $fields[] = 'score1';
    }
    //默认获取自己的资料
    $uid = $uid ? $uid : is_login();
    if (!$uid) {
        return null;
    }
    //查询缓存,过滤掉已缓存的字段
    $cachedFields = array();
    $cacheResult = array();
    foreach ($fields as $field) {
        if (in_array($field, array('icons_html', 'title', 'score'))) {
            continue;
        }
        $cache = read_query_user_cache($uid, $field);
        if (!empty($cache)) {
            $cacheResult[$field] = $cache;
            $cachedFields[] = $field;
        }
    }
    //去除已经缓存的字段
    $fields = array_diff($fields, $cachedFields);
    //获取两张用户表格中的所有字段
    $homeModel = M('Member');
    $ucenterModel = UCenterMember();
    $homeFields = $homeModel->getDbFields();
    $ucenterFields = $ucenterModel->getDbFields();
    //分析每个表格分别要读取哪些字段
    $avatarFields = array('avatar32', 'avatar64', 'avatar128', 'avatar256', 'avatar512');
    $avatarFields = array_intersect($avatarFields, $fields);
    $homeFields = array_intersect($homeFields, $fields);
    $ucenterFields = array_intersect($ucenterFields, $fields);
    //查询需要的字段
    $homeResult = array();
    $ucenterResult = array();
    if ($homeFields) {
        $homeResult = D('Home/Member')->where(array('uid' => $uid))->field($homeFields)->find();
    }
    if ($ucenterFields) {
        $model = UCenterMember();
        $ucenterResult = $model->where(array('id' => $uid))->field($ucenterFields)->find();
    }
    //读取头像数据
    $result = array();
    $avatarObject = new \Ucenter\Widget\UploadAvatarWidget();
    foreach ($avatarFields as $e) {
        $avatarSize = intval(substr($e, 6));
        $avatarUrl = $avatarObject->getAvatar($uid, $avatarSize);
        $check = file_exists('./api/uc_login.lock');
        if ($check) {
            include_once './api/uc_client/client.php';
            $avatarUrl = UC_API . '/avatar.php?uid=' . $uid . '&size=big';
        }
        $result[$e] = $avatarUrl;
    }
    //读取等级数据
    if (in_array('title', $fields)) {
        $titleModel = D('Ucenter/Title');
        $title = $titleModel->getTitle($uid);
        $result['title'] = $title;
    }
    //读取用户名拼音
    if (in_array('pinyin', $fields)) {
        $result['pinyin'] = D('Pinyin')->pinYin($result['nickname']);
    }
    //获取个人中心地址
    $spaceUrlResult = array();
    if (in_array('space_url', $fields)) {
        $result['space_url'] = U('Ucenter/Index/index', array('uid' => $uid));
    }
    if (in_array('nickname', $fields)) {
        $ucenterResult['nickname'] = op_t($ucenterResult['nickname']);
    }
    //获取昵称链接
    if (in_array('space_link', $fields)) {
        if (!$ucenterResult['nickname']) {
            $res = query_user(array('nickname'), $uid);
            $ucenterResult['nickname'] = $res['nickname'];
        }
        $result['space_link'] = '<a ucard="' . $uid . '" target="_blank" href="' . U('Ucenter/Index/index', array('uid' => $uid)) . '">' . $ucenterResult['nickname'] . '</a>';
    }
    //获取用户头衔链接
    if (in_array('rank_link', $fields)) {
        $rank_List = D('rank_user')->where(array('uid' => $uid, 'status' => 1))->select();
        $num = 0;
        foreach ($rank_List as &$val) {
            $rank = D('rank')->where('id=' . $val['rank_id'])->find();
            $val['title'] = $rank['title'];
            $val['logo_url'] = fixAttachUrl(D('picture')->where('id=' . $rank['logo'])->getField('path'));
            if ($val['is_show']) {
                $num = 1;
            }
        }
        if ($rank_List) {
            $rank_List[0]['num'] = $num;
            $result['rank_link'] = $rank_List;
        } else {
            $result['rank_link'] = array();
        }
    }
    //获取用户认证图标
    if (in_array('icons_html', $fields)) {
        //判断是否有手机图标
        $static = C('TMPL_PARSE_STRING.__STATIC__');
        $iconUrls = array();
        $user = query_user(array('mobile'), $uid);
        if ($user['mobile']) {
            $iconUrls[] = "{$static}/oneplus/images/mobile-bind.png";
        }
        //生成结果
        $result['icons_html'] = '<span class="usercenter-verify-icon-list">';
        foreach ($iconUrls as $e) {
            $result['icons_html'] .= "<img src=\"{$e}\" title=\"对方已绑定手机\"/>";
        }
        $result['icons_html'] .= '</span>';
    }
    //expand_info:用户扩展字段信息
    if (in_array('expand_info', $fields)) {
        $map['status'] = 1;
        $field_group = D('field_group')->where($map)->select();
        $field_group_ids = array_column($field_group, 'id');
        $map['profile_group_id'] = array('in', $field_group_ids);
        $fields_list = D('field_setting')->where($map)->getField('id,field_name,form_type,visiable');
        $fields_list = array_combine(array_column($fields_list, 'field_name'), $fields_list);
        $map_field['uid'] = $uid;
        foreach ($fields_list as $key => $val) {
            $map_field['field_id'] = $val['id'];
            $field_data = D('field')->where($map_field)->getField('field_data');
            if ($field_data == null || $field_data == '') {
                unset($fields_list[$key]);
            } else {
                if ($val['form_type'] == "checkbox") {
                    $field_data = explode('|', $field_data);
                }
                $fields_list[$key]['data'] = $field_data;
            }
        }
        $result['expand_info'] = $fields_list;
    }
    //粉丝数、关注数、微博数
    if (in_array('fans', $fields)) {
        $result['fans'] = D('Follow')->where('follow_who=' . $uid)->count();
    }
    if (in_array('following', $fields)) {
        $result['following'] = D('Follow')->where('who_follow=' . $uid)->count();
    }
    //是否关注、是否被关注
    if (in_array('is_following', $fields)) {
        $follow = D('Follow')->where(array('who_follow' => get_uid(), 'follow_who' => $uid))->find();
        $result['is_following'] = $follow ? true : false;
    }
    if (in_array('is_followed', $fields)) {
        $follow = D('Follow')->where(array('who_follow' => $uid, 'follow_who' => get_uid()))->find();
        $result['is_followed'] = $follow ? true : false;
    }
    //TODO 在此加入扩展字段的处理钩子
    //↑↑↑ 新增字段应该写在在这行注释以上 ↑↑↑
    //合并结果,不包括缓存
    $result = array_merge($ucenterResult, $homeResult, $spaceUrlResult, $result);
    //写入缓存
    foreach ($result as $field => $value) {
        if (in_array($field, array('icons_html', 'title', 'score', 'tox_money'))) {
            continue;
        }
        if (!in_array($field, array('rank_link', 'icons_html', 'space_link', 'expand_info'))) {
            $value = str_replace('"', '', op_t($value));
        }
        $result[$field] = $value;
        write_query_user_cache($uid, $field, str_replace('"', '', $value));
    }
    //合并结果,包括缓存
    $result = array_merge($result, $cacheResult);
    $result['score'] = $result['score1'];
    //返回结果
    return $result;
}
コード例 #17
0
 /**
  * 持有新身份
  * @author 郑钟良<*****@*****.**>
  */
 public function registerRole()
 {
     $aRoleId = I('post.role_id', 0, 'intval');
     $uid = is_login();
     $data['status'] = 0;
     if ($uid > 0 && $aRoleId != get_login_role()) {
         $roleUser = D('UserRole')->where(array('uid' => $uid, 'role_id' => $aRoleId))->find();
         if ($roleUser) {
             $data['info'] = L('_INFO_INV_ROLE_POSSESS_');
             $this->ajaxReturn($data);
         } else {
             $memberModel = D('Common/Member');
             $memberModel->logout();
             UCenterMember()->initRoleUser($aRoleId, $uid);
             clean_query_user_cache($uid, array('avatar64', 'avatar128', 'avatar32', 'avatar256', 'avatar512', 'rank_link'));
             $memberModel->login($uid, false, $aRoleId);
             //登陆
         }
     } else {
         $data['info'] = L('_ERROR_ILLEGAL_OPERATE_');
         $this->ajaxReturn($data);
     }
 }
コード例 #18
0
 public function forget()
 {
     $params['mp_id'] = $map['mp_id'] = get_mpid();
     $this->assign('mp_id', $params['mp_id']);
     $map['id'] = I('id');
     $uid = get_ucuser_uid();
     //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝
     if ($uid === false) {
         $this->error('只可在微信中访问');
     }
     if (IS_POST) {
         $aMobile = I('post.mobile', '', 'op_t');
         $verify = I('post.verify', '', 'op_t');
         $password = I('post.password', '', 'op_t');
         $repassword = I('post.repassword', '', 'op_t');
         //确认两次输入的密码正确
         if ($password != $repassword) {
             $this->error('两次输入的密码不一致');
         }
         //读取SESSION中的验证信息
         $mobile = session('reset_password_mobile');
         //提交修改密码和接收验证码的手机号码不一致
         if ($aMobile != $mobile) {
             $this->error('提交修改密码和接收验证码的手机号码不一致');
         }
         $res = D('Verify')->checkVerify($aMobile, "mobile", $verify, 0);
         //确认验证信息正确
         if (!$res) {
             echo '验证码错误';
             return false;
         } else {
             echo true;
         }
         //将新的密码写入数据库
         $data1 = array('uid' => $uid, 'mobile' => $aMobile, 'password' => $password);
         $model = D('Common/Ucuser');
         $data1 = $model->create($data1);
         if (!$data1) {
             $this->error('密码格式不正确');
         }
         $result = $model->where(array('uid' => $uid))->save($data1);
         if ($result === false) {
             $this->error('数据库写入错误');
         }
         //将新的密码写入数据库
         $data = array('id' => $uid, 'mobile' => $aMobile, 'password' => $password);
         $model = UCenterMember();
         $data = $model->create($data);
         if (!$data) {
             $this->error('密码格式不正确');
         }
         $result = $model->where(array('id' => $uid))->save($data);
         if ($result === false) {
             $this->error('数据库写入错误');
         }
         //显示成功消息
         $this->success('密码重置成功', addons_url('Ucuser://Ucuser/login'));
     }
     $this->display();
 }
コード例 #19
0
 /**
  * 实现的init_ucuser钩子方法,对公众号粉丝进行初始化,在需要初始化粉丝信息的地方通过 hook('init_ucuser',$params); 调用
  * @params string $mp_id   公众号在系统中的唯一标识,member_public表的id,必填
  * @params string $weObj   公众号实例
  * @return void      hook函数木有返回值
  * 注意:
  */
 public function init_ucuser($params)
 {
     if ($params['mp_id'] && $params['weObj'] instanceof TPWechat) {
         //带有公众号在系统中唯一ID,存在公众号实例,例如weixincontroller中的被动响应
         $map['openid'] = get_openid();
         $map['mp_id'] = $params['mp_id'];
         $ucuser = D('Ucuser');
         $data = $ucuser->where($map)->find();
         if (!$data) {
             //公众号没有这个粉丝信息,就注册一个
             //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
             $aUsername = $aNickname = $map['openid'];
             //substr(,20);          //以openid作为默认UcenterMember用户名和Member昵称
             $aPassword = UCenterMember()->create_rand();
             //随机密码,用户未通过公众号注册,就不可登录网站
             $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com';
             //以openid@mpid123.com作为默认邮箱
             $mobile = arr2str(UCenterMember()->rand_mobile());
             //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准
             $aUnType = 5;
             //微信公众号粉丝注册
             $aRole = 3;
             //默认公众号粉丝用户角色
             /* 注册用户 */
             $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType);
             if (0 < $uid) {
                 //注册成功
                 initRoleUser($aRole, $uid);
                 //初始化角色用户
                 set_user_status($uid, 1);
                 //微信注册的用户状态直接设置为1
             } else {
                 //注册失败,显示错误信息
             }
             $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']);
             //用注册member获取的统一uid注册微信粉丝
             get_ucuser_uid($uid);
             //设置session中uid
         } else {
             get_ucuser_uid($data['uid']);
             //设置session中uid
         }
     } else {
         //不存在公众号实例或没显式传mp_id参数,例如分享到朋友圈的内容,访问参数中必须带有公众号在系统中唯一标识mp_id
         $umap['openid'] = get_openid();
         //只存在公众号信息的,在get_openid中通过oauth获取用户openid
         $umap['mp_id'] = I('mp_id');
         //从controller的访问请求中获取mp_id
         if (!empty($umap['mp_id'])) {
             $ucuser = D('Ucuser');
             $data = $ucuser->where($umap)->find();
             if (!$data) {
                 //公众号没有这个粉丝信息,就注册一个
                 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
                 $aUsername = $aNickname = $umap['openid'];
                 //以openid作为默认UcenterMember用户名和Member昵称
                 $aPassword = UCenterMember()->create_rand();
                 //随机密码,用户未通过公众号注册,就不可登录网站
                 $email = $aUsername . '@mp_id' . $umap['mp_id'] . 'com';
                 //以openid@mpid123.com作为默认邮箱
                 $mobile = arr2str(UCenterMember()->rand_mobile());
                 //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准
                 $aUnType = 5;
                 //微信公众号粉丝注册
                 $aRole = 3;
                 //默认公众号粉丝用户角色
                 /* 注册用户 */
                 $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType);
                 if (0 < $uid) {
                     //注册成功
                     initRoleUser($aRole, $uid);
                     //初始化角色用户
                     set_user_status($uid, 1);
                     //微信注册的用户状态直接设置为1
                 } else {
                     //注册失败,显示错误信息
                 }
                 $uid = $ucuser->registerUser($uid, $umap['mp_id'], $umap['openid']);
                 //用注册member获取的统一uid注册微信粉丝
                 get_ucuser_uid($uid);
                 //设置session中uid
             } else {
                 get_ucuser_uid($data['uid']);
                 //设置session中uid
             }
         } else {
             //没有公众号信息,未能初始化粉丝
         }
     }
 }
コード例 #20
0
 /**
  * checkAccount  ajax验证用户帐号是否符合要求
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 public function checkAccount()
 {
     $aAccount = I('post.account', '', 'op_t');
     $aType = I('post.type', '', 'op_t');
     if (empty($aAccount)) {
         $this->error('不能为空!');
     }
     check_username($aAccount, $email, $mobile, $aUnType);
     $mUcenter = UCenterMember();
     switch ($aType) {
         case 'username':
             empty($aAccount) && $this->error('用户名格式不正确!');
             $length = mb_strlen($aAccount, 'utf-8');
             // 当前数据长度
             if ($length < 4 || $length > 30) {
                 $this->error('用户名长度在4-30之间');
             }
             $id = $mUcenter->where(array('username' => $aAccount))->getField('id');
             if ($id) {
                 $this->error('该用户名已经存在!');
             }
             preg_match("/^[a-zA-Z0-9_]{1,30}\$/", $aAccount, $result);
             if (!$result) {
                 $this->error('只允许字母和数字和下划线!');
             }
             break;
         case 'email':
             empty($email) && $this->error('邮箱格式不正确!');
             $length = mb_strlen($email, 'utf-8');
             // 当前数据长度
             if ($length < 4 || $length > 32) {
                 $this->error('邮箱长度在4-32之间');
             }
             $id = $mUcenter->where(array('email' => $email))->getField('id');
             if ($id) {
                 $this->error('该邮箱已经存在!');
             }
             break;
         case 'mobile':
             empty($mobile) && $this->error('手机格式不正确!');
             $id = $mUcenter->where(array('mobile' => $mobile))->getField('id');
             if ($id) {
                 $this->error('该手机号已经存在!');
             }
             break;
     }
     $this->success('验证成功');
 }
コード例 #21
0
 public function register()
 {
     $aUser_name = I('post.user_name', '', 'op_t');
     $aPassword = I('post.password', '', 'op_t');
     $aNickname = I('post.nickname', '', 'op_t');
     $aEmail = I('post.email', '', 'op_t');
     $aFromUserName = I('post.FromUserName', '', 'op_t');
     $result['type'] = 0;
     /* 调用注册接口注册用户 */
     $User = UCenterMember();
     $uid = $User->register($aUser_name, $aNickname, $aPassword, $aEmail);
     if (0 < $uid) {
         //注册成功
         $uid = $User->login($aUser_name, $aPassword);
         //通过账号密码取到uid
         D('Home/Member')->login($uid, false);
         //登陆
         $reg_weibo = C('USER_REG_WEIBO_CONTENT');
         //用户注册的微博内容
         if ($reg_weibo != '') {
             //为空不发微博
             D('Weibo/Weibo')->addWeibo($uid, $reg_weibo);
         }
         //绑定微信
         $data['uid'] = $uid;
         $data['openid'] = $aFromUserName;
         $res = D('App/UserWeixin')->bindUser($data);
         if ($res) {
             $result['type'] = 1;
             $user_info = query_user(array('uid', 'nickname', 'avatar256', 'avatar128'), is_login());
             $result['user_info'] = $user_info;
             $result['uid'] = is_login();
         } else {
             $result['info'] = '绑定失败,请进行绑定操作!';
             $result['type'] = -1;
         }
     } else {
         //注册失败,显示错误信息
         $result['info'] = $this->showRegError($uid);
     }
     $this->ajaxReturn($result);
 }
コード例 #22
0
 /**
  * 修改密码提交
  * @author huajie <*****@*****.**>
  */
 public function submitPassword()
 {
     //获取参数
     $password = I('post.old');
     empty($password) && $this->error(L('_PLEASE_ENTER_THE_ORIGINAL_PASSWORD_'));
     $data['password'] = I('post.password');
     empty($data['password']) && $this->error(L('_PLEASE_ENTER_A_NEW_PASSWORD_'));
     $repassword = I('post.repassword');
     empty($repassword) && $this->error(L('_PLEASE_ENTER_THE_CONFIRMATION_PASSWORD_'));
     if ($data['password'] !== $repassword) {
         $this->error(L('_YOUR_NEW_PASSWORD_IS_NOT_CONSISTENT_WITH_THE_CONFIRMATION_PASSWORD_'));
     }
     $Api = new UserApi();
     $res = $Api->updateInfo(UID, $password, $data);
     if ($res['status']) {
         $this->success(L('_CHANGE_PASSWORD_SUCCESS_'));
     } else {
         $this->error(UCenterMember()->getErrorMessage($res['info']));
     }
 }
コード例 #23
0
ファイル: user.php プロジェクト: suhanyujie/digitalOceanVps
/**
 * set_user_status   设置用户状态
 * @param $uid
 * @param $status
 * @return bool
 * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
 */
function set_user_status($uid, $status)
{
    D('Member')->where(array('uid' => $uid))->setField('status', $status);
    UCenterMember()->where(array('id' => $uid))->setField('status', $status);
    return true;
}
コード例 #24
0
ファイル: user.php プロジェクト: smartymoon/e-anjia
/**
 * set_users_status   批量设置用户状态
 * @param $map
 * @param $status
 * @return bool
 * @author 郑钟良<*****@*****.**>
 */
function set_users_status($map, $status)
{
    D('Member')->where($map)->setField('status', $status);
    UCenterMember()->where($map)->setField('status', $status);
    return true;
}
コード例 #25
0
 /**
  * 注册一个新用户,其实已经注册了只是完善用户信息
  * @param  integer $uid 用户UID
  * @param  string $nickname 昵称
  * @param  string $password 用户密码
  * @param  string $email 用户邮箱
  * @param  string $mobile 用户手机号码
  * @return integer          注册成功-用户信息,注册失败-错误编号
  */
 public function register($uid, $password, $mobile)
 {
     $user = $this->find($uid);
     $data = array('uid' => $uid, 'password' => $password, 'mobile' => $mobile);
     $data1 = array('id' => $uid, 'password' => $password, 'mobile' => $mobile);
     /* 完善用户信息 */
     if ($this->create($data) && $this->save()) {
         if (UCenterMember()->create($data1) && UCenterMember()->save()) {
             //更新UcenterMember中的手机和密码
             return true;
         }
     } else {
         return $this->getError();
         //错误详情见自动验证注释
     }
 }