Exemplo n.º 1
0
 public function checkUc()
 {
     try {
         $identifierUserSystem = new identifierUserSystem();
         $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier();
         //多用户系统
         $check_Bind = new check_Bind();
         if ($this->input['platform_id']) {
             $platform_id = $this->input['platform_id'];
             $type = $this->input['type'];
         } elseif ($this->input['member_name']) {
             $user_name = trim($this->input['member_name']);
             $member_id = $check_Bind->bind_to_memberid($user_name, 'uc', false, $identifier);
             //优先检测uc类型
             $type = 'uc';
             if (empty($member_id)) {
                 $member_id = $check_Bind->bind_to_memberid($user_name, 'm2o', false, $identifier);
                 $type = 'm2o';
             }
             if (empty($member_id)) {
                 $member_id = $check_Bind->bind_to_memberid($user_name, 'shouji', false, $identifier);
                 $type = 'shouji';
             }
             if (empty($member_id)) {
                 $platform_id = $this->input['member_name'];
                 $type = $this->input['type'];
             }
         }
         $is_bind = 0;
         if (empty($member_id)) {
             $member_id = $check_Bind->bind_to_memberid($platform_id, $type, true, $identifier);
         }
         $is_bind = $check_Bind->check_uc($member_id, $type);
         $this->addItem_withkey('is_bind', $is_bind);
         $this->output();
     } catch (Exception $e) {
         $this->errorOutput($e->getMessage(), $e->getCode());
     }
 }
Exemplo n.º 2
0
 public function uc_user_edit($username, $oldpw, $newpw, $email, $ignoreoldpw = 0, $questionid = '', $answer = '')
 {
     if (empty($this->input['member_name'])) {
         $this->input['member_name'] = $username;
     }
     $check_Bind = new check_Bind();
     if (hg_check_email_format($username)) {
         $type = 'email';
         $member_id = $check_Bind->bind_to_memberid($username, $type, true);
         //如果用户名为邮箱则检测邮箱类型
         if ($member_id) {
             $sql = 'SELECT member_name FROM ' . DB_PREFIX . 'member AS m WHERE member_id = \'' . $member_id . '\'';
             $row = $this->db->query_first($sql);
             $this->input['member_name'] = $username = $row['member_name'];
         }
     } else {
         if (hg_verify_mobile($username)) {
             $type = 'shouji';
             $member_id = $check_Bind->bind_to_memberid($username, $type, true);
             //如果用户名为邮箱则检测邮箱类型
             if ($member_id) {
                 $sql = 'SELECT member_name FROM ' . DB_PREFIX . 'member AS m WHERE member_id = \'' . $member_id . '\'';
                 $row = $this->db->query_first($sql);
                 $this->input['member_name'] = $username = $row['member_name'];
             }
         }
     }
     if (empty($member_id)) {
         $member_id = $check_Bind->bind_to_memberid($username, 'uc');
         //优先检测uc类型
         $type = 'uc';
     }
     if (empty($member_id)) {
         $member_id = $check_Bind->bind_to_memberid($username, 'm2o');
         $type = 'm2o';
     }
     $is_ucid = 0;
     if ($member_id) {
         $is_ucid = $check_Bind->check_uc($member_id, $type);
     }
     include_once CUR_CONF_PATH . 'uc_client/client.php';
     $uc_userinfo = uc_get_user($this->input['member_name']);
     if ($is_ucid && $is_ucid == $uc_userinfo[0]) {
         return uc_user_edit($username, $oldpw, $newpw, $email, $ignoreoldpw, $questionid, $answer);
     }
     return 0;
     //UC信息未修改
 }
Exemplo n.º 3
0
 /**
  * 产生邀请信息.目前仅支持手机邀请.
  */
 public function generate_invite()
 {
     if ($this->user['user_id']) {
         $member_id = intval($this->user['user_id']);
     }
     $re['status'] = 0;
     $re['msg'] = '您未登陆,请登陆后再次邀请!';
     if ($member_id) {
         $select = array();
         $sendto = '';
         if ($mobile = intval($this->input['mobile'])) {
             $checkBind = new check_Bind();
             $check_info = $checkBind->bind_to_memberid($mobile, 'shouji', true);
             if (empty($check_info)) {
                 $sendto = $code = $mobile;
                 if ($code) {
                     $condition['code'] = $code;
                 }
                 $condition['type'] = $type = 1;
                 $select = $this->invite->select($condition);
                 $send_status = $this->send_sms();
                 if ($send_status) {
                     $re['status'] = $status = 3;
                     //发送成功
                     $re['msg'] = '短信通知成功';
                 } else {
                     $re['status'] = $status = 4;
                     //发送失败
                     $re['msg'] = '短信通知失败,您可以主动通知好友或者重新尝试发送邀请!';
                 }
             } else {
                 $re['msg'] = '您邀请的好友已经是会员,无需邀请!';
             }
         } elseif ($email = trim($this->input['email'])) {
             $check_info = $this->Members->get_member_id($email, true, false);
             if (empty($check_info)) {
                 $sendto = $code = $email;
                 if ($code) {
                     $condition['code'] = $code;
                 }
                 $condition['type'] = $type = 2;
                 $select = $this->invite->select($condition);
             } else {
                 $re['msg'] = '您邀请的好友已经是会员,无需邀请!';
             }
         } else {
             $code = strtolower(random(6));
             $condition['type'] = $type = 0;
             $status = 1;
             //不发送
             $re['status'] = $status = 1;
             //未发送邀请
             $re['msg'] = '您的邀请码为:' . $code . ',请复制邀请码并通过QQ,E-mail,论坛告知您的好友!';
         }
         if (empty($check_info)) {
             $setarr = array('member_id' => $member_id, 'code' => $code, 'type' => $type, 'sendto' => $sendto, 'inviteip' => hg_getip(), 'dateline' => TIMENOW, 'status' => $status, 'endtime' => $this->settings['member_invite']['invite_endtime'] ? TIMENOW + $this->settings['member_invite']['invite_endtime'] * 3600 : 0);
             if (empty($select)) {
                 $ret = $this->invite->insert($setarr);
             } else {
                 $ret = $this->invite->update($setarr, $condition);
             }
             $re['code'] = $code;
         }
     }
     if ($re & is_array($re)) {
         foreach ($re as $k => $v) {
             $this->addItem_withkey($k, $v);
         }
     }
     $this->output();
 }
Exemplo n.º 4
0
 /**
 * 会员登录
 * $member_name
 * $password
 * $type
 * $type_name
 * $appid
 * $appkey
 *
 * 返回
 * member_id
 * member_name
 * type
 * avatar
 * access_token
 *
 * 绑定表
 *  member_id 会员id
 		platform_id 第三方平台会员id char
 		nick_name 昵称
 		type 会员类型
 		type_name 会员类型名称
 		avatar_url 头像地址
 		bind_time 绑定时间
 		bind_ip 绑定ip
 */
 public function login()
 {
     try {
         $member_name = $this->checkUserName(trimall($this->input['member_name']));
         $password = trim($this->input['password']);
         $ip = hg_getip();
         $type = $this->input['type'];
         $this->checkLoginTypeSwitch();
         $this->checkLoginTypeError($member_name, $type);
         $this->checkLoginPassword($password, $type);
         $this->check_verifycode($type);
         //验证码
         $_type = '';
         //防止本地M2O同步至UC后,再次验证本地密码BUG。
         $platform_id = trim($this->input['platform_id']);
         $identifierUserSystem = new identifierUserSystem();
         $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier();
         //多用户系统
         $appid = intval($this->input['appid']);
         $appkey = trim($this->input['appkey']);
         $device_token = $this->Members->check_device_token(trim($this->input['device_token']));
         $udid = $this->Members->check_udid(trim($this->input['uuid']));
         //唯一设备号
         if ($device_token === 0) {
             $this->errorOutput(ERROR_DEVICE_TOKEN);
         }
         if ($udid === 0) {
             $this->errorOutput(ERROR_UDID);
         }
         //验证设备号和ip是否在黑名单
         if ($udid) {
             $device_res = $this->Blacklist->detailDeviceBlacklist(array('device_token' => $udid, 'identifier' => $identifier));
             if ($device_res[0]['deadline'] == -1 && $device_res[0]['type'] == 2) {
                 $this->errorOutput(DEVICE_BLACKLIST_FOREVER);
             } elseif ($device_res[0]['deadline'] == -1) {
                 $this->errorOutput(DEVICE_BLACKLIST);
             }
         }
         if ($ip) {
             $ip_res = $this->Blacklist->detailIpBlacklist(array('ip' => ip2long($ip), 'identifier' => $identifier));
             if ($ip_res[0]['deadline'] == -1 && $ip_res[0]['type'] == 2) {
                 $this->errorOutput(IP_BLACKLIST_FOREVER);
             } elseif ($ip_res[0]['deadline'] == -1) {
                 $this->errorOutput(IP_BLACKLIST);
             }
         }
         //登陆类型 shouji、sina、txweibo、qq、renren、douban
         if (!$type) {
             $this->errorOutput(NO_EXTERNAL_TYPE);
         }
         if ($type == 'uc' && $identifier) {
             $this->input['type'] = '';
             $this->checkUserName($member_name, 1);
             $this->input['type'] && ($type = $this->input['type']);
         }
         if ($type == 'm2o' && $this->settings['ucenter']['open'] && !$identifier) {
             $check_login = $this->oAuthUc(true, true);
             //修复手机端传m2o类型,但是帐号属于UC类型,登陆失败问题
             if ($check_login > 0) {
                 $type = 'uc';
             }
         }
         if ($type == 'uc' && $this->settings['ucenter']['open'] && !$identifier) {
             $uc_user = $this->oAuthUc(true);
             if ($uc_user['user_id'] == -1) {
                 $type = 'm2o';
             }
         } elseif ($type == 'uc' && !$this->settings['ucenter']['open'] && !$identifier) {
             $this->errorOutput(UC_LOGIN_ERROR);
         }
         $check_Bind = new check_Bind();
         //所有类型的邮箱登陆
         if ($member_name && $type == 'email') {
             $platform_id = $platform_id ? $platform_id : $member_name;
             if (!$check_Bind->bind_to_memberid($member_name, $type, true, $identifier)) {
                 $this->errorOutput(LOGIN_NOMEMBER_ERROR);
             }
         } else {
             if ($type == 'shouji') {
                 //会员名
                 if (!$member_name) {
                     $this->errorOutput(NO_MEMBER_NAME);
                 }
                 $platform_id = $platform_id ? $platform_id : $member_name;
                 if (!$check_Bind->bind_to_memberid($member_name, $type, true, $identifier)) {
                     $this->errorOutput(LOGIN_NOMEMBER_ERROR);
                 }
             } else {
                 if ($type == 'm2o') {
                     $is_mobile_login = false;
                     $where = ' AND member_name="' . $member_name . '" AND type="m2o" AND identifier = \'' . $identifier . '\'';
                     $sql = 'SELECT member_id FROM ' . DB_PREFIX . 'member WHERE 1';
                     $memberinfo = $this->db->query_first($sql . $where);
                     if (!$memberinfo) {
                         if (hg_verify_mobile($member_name)) {
                             $where = ' AND member_name=\'' . $member_name . '\' AND type=\'shouji\' AND identifier = \'' . $identifier . '\'';
                             $memberinfo = $this->db->query_first($sql . $where);
                             if ($memberinfo) {
                                 $type = 'shouji';
                                 $platform_id = $check_Bind->check_uc($memberinfo['member_id'], $type);
                                 //修复同步UC后,登陆密码错误的bug
                                 $platform_id = $platform_id ? $platform_id : $member_name;
                             }
                             if (empty($memberinfo)) {
                                 $type = 'shouji';
                                 $member_id = $check_Bind->bind_to_memberid($member_name, $type, true, $identifier);
                                 if ($member_id) {
                                     $memberinfo = array('member_id' => $member_id);
                                     $platform_id = $member_name;
                                 }
                             }
                         }
                         $memberinfo ? $memberinfo : $this->errorOutput(LOGIN_NOMEMBER_ERROR);
                     }
                     if ($type != 'shouji') {
                         $bindinfo = $this->db->query_first('SELECT inuc FROM ' . DB_PREFIX . 'member_bind WHERE member_id=' . $memberinfo['member_id'] . ' AND type="m2o"');
                         $platform_id = $bindinfo['inuc'] ? $bindinfo['inuc'] : $memberinfo['member_id'];
                     }
                 } else {
                     //新浪微博、腾讯微博、QQ、人人网、豆瓣 uc等
                     $nick_name = trimall($this->input['nick_name']);
                     $type_name = trim($this->input['type_name']);
                     $avatar_url = trim($this->input['avatar_url']);
                     if ($type == 'uc' && $uc_user) {
                         //$platform_id = $uc_user['user_id'];
                         //手机 m2o注册至uc之后登陆类型使用“uc”导致的bug
                         $sql = 'SELECT * FROM ' . DB_PREFIX . 'member_bind WHERE type=\'m2o\' AND inuc=' . $uc_user['user_id'];
                         $bind_uc = $this->db->query_first($sql);
                         if ($bind_uc) {
                             $platform_id = $bind_uc['platform_id'];
                             $nick_name = $bind_uc['nick_name'];
                             $type_name = $bind_uc['type_name'];
                             $avatar_url = $bind_uc['avatar_url'];
                             $_type = $type;
                             $type = $bind_uc['type'];
                         } else {
                             $platform_id = $uc_user['user_id'];
                             $nick_name = $uc_user['user_name'];
                             $type_name = 'UC会员';
                             $avatar_url = $uc_user['avatar'];
                             $email = $uc_user['email'];
                         }
                     }
                     if (!$platform_id) {
                         $this->errorOutput(NO_MEMBER_ID);
                     }
                     if (!$nick_name) {
                         $this->errorOutput(NO_NICKNAME);
                     }
                     $member_name = $nick_name;
                     $condition = " AND mb.platform_id = '" . $platform_id . "' AND mb.type = '" . $type . "' AND mb.identifier = '" . $identifier . '\'';
                     $bind = $this->mMember->get_bind_info($condition);
                     $bind = $bind[0];
                     if (empty($type_name)) {
                         $platformInfo = $this->Members->get_platform_name($type);
                         if (empty($platformInfo)) {
                             $this->errorOutput(LOGIN_MEMBER_TYPE_ERROR);
                         } else {
                             if (!$platformInfo['status']) {
                                 $this->errorOutput(LOGIN_MEMBER_TYPE_CLOSE);
                             }
                         }
                         $type_name = $platformInfo['name'];
                     }
                     $avatar_array = array();
                     $avatar_array = $this->mMember->update_avatar($avatar_url, $bind);
                     //会员表
                     $data = array('member_name' => $nick_name, 'email' => $email, 'type' => $type, 'type_name' => $type_name, 'update_time' => TIMENOW, 'avatar' => daddslashes(serialize($avatar_array)), 'guid' => guid());
                     //绑定表
                     $bind_data = array('platform_id' => $platform_id, 'type' => $type, 'avatar_url' => $avatar_url, 'reg_device_token' => $device_token, 'reg_udid' => $udid);
                     if (empty($bind)) {
                         if ($type == 'uc') {
                             $isBindUc = 0;
                             if ($memberId = $this->mMember->verifyPassword($member_name, $password, 'm2o')) {
                                 $isBindUc = $this->mMember->bind_uc($memberId, $uc_user['user_id']);
                             }
                             if (!$isBindUc && $password) {
                                 //随机串
                                 $salt = hg_generate_salt();
                                 $data['salt'] = $salt;
                                 //密码md5
                                 $data['password'] = md5(md5($password) . $salt);
                             }
                         }
                         if ($type != 'uc' || !$isBindUc) {
                             //新增会员
                             $groupInfo = $this->Members->checkgroup_credits(0);
                             $gradeInfo = $this->Members->checkgrade_credits(0);
                             $data['gid'] = $groupInfo['gid'];
                             $data['gradeid'] = $gradeInfo['gradeid'];
                             $data['status'] = $this->settings['member_status'];
                             $data['identifier'] = $identifier;
                             $data['appid'] = intval($this->user['appid']);
                             $data['appname'] = trim($this->user['display_name']);
                             $data['create_time'] = TIMENOW;
                             $data['ip'] = $ip;
                             $data['reg_device_token'] = $device_token;
                             $data['reg_udid'] = $udid;
                             //会员数据入库
                             $ret = $this->mMember->create($data);
                             if (!$ret['member_id']) {
                                 $this->errorOutput(MEMBER_DATA_ADD_FAILED);
                             }
                             $member_id = $ret['member_id'];
                             //绑定表
                             $bind_data['nick_name'] = $nick_name;
                             $bind_data['member_id'] = $member_id;
                             $bind_data['type_name'] = $type_name;
                             $bind_data['bind_time'] = TIMENOW;
                             $bind_data['bind_ip'] = $ip;
                             $bind_data['is_primary'] = 1;
                             $bind_data['identifier'] = $identifier;
                             if ($bind_data['type'] == 'uc') {
                                 $bind_data['inuc'] = $bind_data['platform_id'];
                             }
                             $ret_bind = $this->mMember->bind_create($bind_data);
                             if (empty($ret_bind)) {
                                 $this->errorOutput(BIND_DATA_ADD_FAILED);
                             }
                             $this->registerCreditRules($member_id, $type);
                             //新注册会员积分规则
                         } else {
                             if ($type == 'uc' && $isBindUc) {
                                 $type = 'm2o';
                             }
                         }
                     } else {
                         //更新会员
                         $member_id = $bind['member_id'];
                         //验证会员是否存在
                         $condition = " AND m.member_id = " . $member_id;
                         $ret_member = $this->mMember->get_member_info($condition);
                         $ret_member = $ret_member[0];
                         if (empty($ret_member)) {
                             $this->errorOutput(LOGIN_NOMEMBER_ERROR);
                         }
                         $update_bind_data = array('member_id' => $member_id, 'platform_id' => $platform_id, 'type' => $type, 'avatar_url' => $avatar_url);
                         $ret_bind = $this->mMember->bind_update($update_bind_data);
                         if (empty($ret_bind)) {
                             $this->errorOutput(BIND_DATA_UPDATE_FAILED);
                         }
                     }
                 }
             }
         }
         //到auth接口取access_token
         $encryptPassword = urlencode(passport_encrypt($password, CUSTOM_APPKEY));
         $callback = 'http://' . $this->settings['App_members']['host'] . '/' . $this->settings['App_members']['dir'] . 'login.php?';
         $func = 'a=verify_member&appid=' . $appid . '&appkey=' . $appkey;
         $callback .= urlencode($func);
         $extend = 'platform_id=' . $platform_id . '&password='******'&encrypt=1&type=' . $type . '&_type=' . $_type . '&identifier=' . $identifier;
         $auth_data = array('user_name' => $member_name, 'appid' => $appid, 'appkey' => $appkey, 'ip' => $ip, 'verify_user_cb' => $callback, 'extend' => urlencode($extend));
         $auth = $this->mMember->get_access_token($auth_data);
         if (!$auth['token']) {
             $this->errorOutput(MEMBERS_LOGIN_ERROR);
         }
         //黑名单用户判断
         $blacklist = $this->Members->blacklist($auth['user_id']);
         if ($blacklist[$auth['user_id']]['isblack']) {
             $this->errorOutput(MEMBER_BLACKLIST);
         }
         //判断结束
         //权限判断
         //判断结束
         //编辑扩展信息
         $this->mMemberInfo->extension_edit($auth['user_id'], $this->input['member_info'], $_FILES);
         //获取扩展信息
         $extension = $this->getExtensionInfo($auth['user_id'], $identifier);
         //会员痕迹
         $member_trace_data = array('member_id' => $auth['user_id'], 'member_name' => $member_name, 'content_id' => $auth['user_id'], 'title' => $member_name, 'type' => 'login', 'op_type' => '登陆', 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'ip' => hg_getip(), 'device_token' => $device_token, 'udid' => $udid);
         $memberTrace = $this->mMember->getMemberTrace(array('member_id' => $auth['user_id'], 'type' => 'login'), 'create_time');
         $this->mMember->member_trace_create($member_trace_data);
         $return = array('member_id' => $auth['user_id'], 'platform_id' => $auth['platform_id'], 'inuc' => $auth['inuc'] ? $auth['inuc'] : 0, 'member_name' => $auth['user_name'], 'nick_name' => $auth['nick_name'], 'type' => $auth['type'], 'type_name' => $auth['type_name'], 'avatar' => $auth['avatar'] ? $auth['avatar'] : '', 'access_token' => $auth['token'], 'guid' => $auth['guid'], 'gid' => $auth['gid'], 'gradeid' => $auth['gradeid'], 'copywriting_credit' => $auth['copywriting_credit'], 'copywriting' => $auth['copywriting'], 'signature' => $auth['signature'], 'mobile' => $auth['mobile'], 'email' => $auth['email'], 'extension' => $extension ? $extension : array(), 'isVerify' => $auth['isVerify'], 'isComplete' => $auth['isComplete'], 'identifier' => $auth['identifier'], 'last_login_device' => $auth['last_login_device'], 'last_login_time' => date('Y-m-d H:i:s', $memberTrace['create_time']));
         //记录登陆信息
         $loginInfoRecord = array('last_login_device' => $member_trace_data['device_token'], 'final_login_time' => $member_trace_data['create_time'], 'last_login_time' => $memberTrace['create_time'], 'last_login_udid' => $member_trace_data['udid']);
         $this->mMember->loginInfoRecord($return['member_id'], $loginInfoRecord);
         $return = hg_mermber2members_compatible(array('member_name' => 'nick_name', 'access_token' => 'token'), $return, false);
         $this->addItem($return);
         $this->output();
     } catch (Exception $e) {
         $this->errorOutput($e->getMessage(), $e->getCode());
     }
 }