Ejemplo n.º 1
0
function sortTags($tags)
{
    //分类数组
    $sort = array('A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
    //分类
    for ($i = 0; $i < count($tags); ++$i) {
        array_push($sort[getFirstLetter($tags[$i]['name'])], $tags[$i]);
    }
    return $sort;
}
Ejemplo n.º 2
0
 public function syncTags(Article $article, $tags = array(), $isNew = false)
 {
     $tagall = Tag::all()->toArray();
     $newTagIds = $updateTagIds = $existingSlug = $existingTag = [];
     if (!empty($tagall)) {
         foreach ($tagall as $tag) {
             $existingSlug[] = $tag['slug'];
             $existingTag[$tag['slug']] = $tag;
         }
     }
     unset($tagall);
     if ($tags) {
         foreach ($tags as $tag) {
             if (!in_array(mb_strtolower($tag, 'UTF-8'), $existingSlug)) {
                 $name = filter_allowed_words($tag);
                 $slug = preg_replace('/\\s+/', '-', mb_strtolower($name, 'UTF-8'));
                 if (in_array($slug, $existingSlug)) {
                     if ($isNew) {
                         Tag::whereSlug($slug)->increment('count');
                     }
                     $updateTagIds[] = $existingTag[$slug]['id'];
                 } else {
                     $firstLetter = getFirstLetter($name);
                     $newtag = Tag::create(array('name' => $name, 'slug' => $slug, 'letter' => $firstLetter));
                     $newId = $newtag->id;
                     $newTagIds[] = $newId;
                     $updateTagIds[] = $newId;
                 }
             } else {
                 if ($isNew) {
                     Tag::whereSlug($tag)->increment('count');
                 }
                 $updateTagIds[] = $existingTag[$tag]['id'];
             }
         }
     }
     $updateTagIds = array_unique($updateTagIds);
     if (!$isNew) {
         $oldTagIds = $article->tags->lists('id')->toArray();
         $delTagIds = array_diff($oldTagIds, $updateTagIds);
         $addTagIds = array_diff($updateTagIds, $oldTagIds);
         if (!empty($delTagIds)) {
             Tag::whereIn('id', $delTagIds)->decrement('count');
         }
         if (!empty($addTagIds)) {
             foreach ($addTagIds as $addId) {
                 if (!in_array($addId, $newTagIds)) {
                     Tag::whereId($addId)->increment('count');
                 }
             }
         }
     }
     $article->tags()->sync($updateTagIds);
     unset($newTagIds, $updateTagIds, $existingSlug, $existingTag);
 }
Ejemplo n.º 3
0
 /**
  * 以邮箱方式注册
  *
  * @request string email 邮箱地址
  * @request strin username 用户名
  * @request string password 用户密码
  * @request int code 验证码
  * @return array
  * @author Medz Seven <*****@*****.**>
  * @link http://medz.cn
  **/
 public function signUp2Email()
 {
     /*
      * 邮箱地址
      */
     $email = $this->data['email'];
     $email = addslashes($email);
     /*
      * 验证码
      */
     $code = $this->data['code'];
     $code = intval($code);
     /*
      * 用户名
      */
     $username = $this->data['username'];
     $username = addslashes($username);
     /*
      * 用户密码
      */
     $password = $this->data['password'];
     $password = addslashes($password);
     /* # 用户头像信息 */
     $avatar = array('picurl' => $this->data['picurl'], 'picwidth' => $this->data['picwidth'], 'picheight' => $this->data['picheight']);
     /* # 性别 */
     $sex = intval($this->data['sex']);
     /*
      * 验证邮箱是否是不合法邮箱地址
      */
     if (!$this->isEmail($email)) {
         return array('status' => 0, 'message' => '不合法的E-mail地址');
         /*
          * 验证验证码是否为空
          */
     } elseif (!$code) {
         return array('status' => -1, 'message' => '验证码不能为空');
         /* # 判断性别是否不符合 */
     } elseif (!in_array($sex, array(0, 1, 2))) {
         return array('status' => 0, 'message' => '性别参数错误');
         /*
          * 验证邮箱是否已经注册过了
          */
     } elseif (model('User')->hasUser($email)) {
         return array('status' => -2, 'message' => '该邮箱用户已经存在,无法注册');
         /*
          * 验证username是否已经被注册了
          */
     } elseif (model('User')->hasUser($username)) {
         return array('status' => -3, 'message' => '该用户名已经被注册');
         /*
          * 验证密码格式是否非法
          */
     } elseif (!preg_match('/^[a-zA-Z0-9]+$/', $password)) {
         return array('status' => -4, 'message' => '密码非法,只能是大小写英文和数字组成');
         /*
          * 验证密码是否过短
          */
     } elseif ($plen = strlen($password) and $plen < 6) {
         return array('status' => -5, 'message' => '密码太短,最少需要6位');
         /*
          * 验证密码是否太长
          */
     } elseif ($plen > 15) {
         return array('status' => -6, 'message' => '密码太长,最多15位');
         /* # 判断是否没有上传头像 */
     } elseif (!$avatar['picurl']) {
         return array('status' => 0, 'message' => '请上传头像');
         /*
          * 验证验证码是否正确
          */
     } elseif ($sms = model('Sms') and !$sms->checkEmailCaptcha($email, $code)) {
         return array('status' => -7, 'message' => $sms->getMessage());
     }
     unset($sms);
     /*
      * 用户数据
      * @var array
      */
     $userData = array();
     /*
      * 用户邮箱地址
      * @var string
      */
     $userData['email'] = $email;
     /*
      * 用户名
      * @var string
      */
     $userData['uname'] = $username;
     /*
      * 用户盐值
      * @var int
      */
     $userData['login_salt'] = rand(10000, 99999);
     /*
      * 用户密码
      * @var string
      */
     $userData['password'] = model('User')->encryptPassword($password, $userData['login_salt']);
     /*
      * 用户注册时间
      * @var int
      */
     $userData['ctime'] = time();
     /*
      * 是否通过审核
      * @var int
      */
     $userData['is_audit'] = 1;
     /*
      * 是否激活
      * @var int
      */
     $userData['is_active'] = 1;
     /*
      * 是否初始化
      * @var int
      */
     $userData['is_init'] = 1;
     /*
      * 注册IP
      * @var string
      */
     $userData['reg_ip'] = get_client_ip();
     /*
      * 用户名首字母
      * @var string
      */
     $userData['first_letter'] = getFirstLetter($username);
     /*
      * 用户搜索字段
      * @var sring
      */
     $userData['search_key'] = $username;
     preg_match('/[\\x7f-\\xff]+/', $username) and $userData['search_key'] .= model('PinYin')->Pinyin($username);
     /*
      * 用户性别
      * @var int
      */
     $userData['sex'] = $sex;
     /*
      * 添加用户到数据库
      */
     if ($uid = model('User')->add($userData)) {
         unset($userData);
         /*
          * 注册配置信息
          * @var array
          */
         $registerConfig = model('Xdata')->get('admin_Config:register');
         /*
          * 默认用户组
          * @var int|array
          */
         $defaultUserGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         $defaultUserGroup = is_array($defaultUserGroup) ? implode(',', $defaultUserGroup) : $defaultUserGroup;
         /*
          * 将用户移动到用户组
          */
         model('UserGroupLink')->domoveUsergroup($uid, $defaultUserGroup);
         unset($defaultUserGroup);
         /*
          * 添加双向关注用户
          */
         empty($registerConfig['each_follow']) or model('Follow')->eachDoFollow($uid, $registerConfig['each_follow']);
         /*
          * 添加默认关注用户
          */
         $defaultFollow = $registerConfig['default_follow'];
         /* # 去重 */
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $registerConfig['each_follow']));
         /* # 执行关注 */
         empty($defaultFollow) or model('Follow')->bulkDoFollow($uid, $defaultFollow);
         unset($defaultFollow);
         /* # 保存用户头像 */
         if ($avatar['picurl'] && $avatar['picwidth'] && $avatar['picheight']) {
             $dAvatar = model('Avatar');
             $dAvatar->init($uid);
             $data['picurl'] = $avatar['picurl'];
             $data['picwidth'] = $avatar['picwidth'];
             $scaling = 5;
             $data['w'] = $avatar['picwidth'] * $scaling;
             $data['h'] = $avatar['picheight'] * $scaling;
             $data['x1'] = $data['y1'] = 0;
             $data['x2'] = $data['w'];
             $data['y2'] = $data['h'];
             $dAvatar->dosave($data, true);
             unset($dAvatar, $data);
         }
         /*
          * 添加邮箱到login参数,保证登陆成功
          */
         $_POST['login'] = $email;
         /*
          * 执行登陆流程
          */
         return $this->authorize();
     }
     unset($userData);
     return array('status' => -8, 'message' => '注册失败');
 }
Ejemplo n.º 4
0
 /**
  * 完善第三方登录用户信息
  * @return [type] [description]
  */
 public function ologinPrefect()
 {
     $post = I('post.');
     // 验证手机号
     $mobile = I('post.mobile');
     if (strlen($mobile) != 11) {
         $this->return['code'] = 1001;
         $this->return['message'] = L('mobile_error');
         $this->goJson($this->return);
     }
     if ($this->checkMobile($mobile)) {
         $this->return['code'] = 1002;
         $this->return['message'] = L('mobile_has');
         $this->goJson($this->return);
     }
     // 验证昵称
     if (!$post['uname']) {
         $this->return['code'] = 1003;
         $this->return['message'] = L('uname_null');
         $this->goJson($this->return);
     }
     // 验证性别
     if ($post['sex'] != 1 && $post['sex'] != 2) {
         $this->return['code'] = 1004;
         $this->return['message'] = L('sex_error');
         $this->goJson($this->return);
     }
     load("@.user");
     $post['first_letter'] = getFirstLetter($post['uname']);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) {
         import("Common.Util.PinYin");
         $pinyinClass = new \PinYin();
         $pinyin = $pinyinClass->Pinyin($post['uname']);
         //昵称和呢称拼音保存到搜索字段
         $post['search_key'] = $post['uname'] . ' ' . $pinyin;
     } else {
         $post['search_key'] = $post['uname'];
     }
     // 密码
     if (!$post['password']) {
         $this->return['code'] = 1004;
         $this->return['message'] = L('pwd_null');
         $this->goJson($this->return);
     }
     $post['login_salt'] = rand(11111, 99999);
     $post['password'] = md5(md5($post['password']) . $post['login_salt']);
     $post['ctime'] = time();
     $post['level'] = $post['self_level'];
     $post['cur_language'] = $post['lid'];
     D('userinfo')->where('uid=' . $this->mid)->save($post);
     $language_info['uid'] = $this->mid;
     $language_info['lid'] = $post['lid'];
     $language_info['type'] = 4;
     $language_info['self_level'] = $post['self_level'];
     D('userLanguage')->add($language_info);
     $this->redis->Sadd('User:sex' . $post['sex'], $this->mid);
     $this->redis->SADD('Userinfo:online', $this->mid);
     //在线用户列表
     $this->createSubAccount('yujia' . $this->mid, $this->mid);
     $res = D('userinfo')->getUserInfo($this->mid);
     $this->redis->HMSET('Userinfo:uid' . $this->mid, $res);
     $res['token'] = I('post.token');
     $tmp['headimg'] = json_decode($this->redis->HGET('Userinfo:uid' . $this->mid, 'headimg'), true);
     $tmp['headimg'] = $tmp['headimg'][0]['url'];
     $return = array('uid' => $this->mid, 'token' => $res['token'], 'voipaccount' => $res['voipaccount'], 'voippwd' => $res['voippwd'], 'subaccountid' => $res['subaccountid'], 'subtoken' => $res['subtoken'], 'uname' => $res['uname'], 'mobile' => $res['mobile'], 'sex' => $res['sex'], 'headimg' => $tmp['headimg']);
     $this->return['data'] = $return;
     $this->goJson($this->return);
 }
Ejemplo n.º 5
0
 /**
  * 插入Ts2.8用户信息
  * @return void
  */
 public function insertTsUser()
 {
     set_time_limit(0);
     // 获取插入用户数据
     $data = D('old_user')->field('email, password, sex, uname')->findAll();
     foreach ($data as $value) {
         $user['uname'] = $value['uname'];
         $salt = rand(11111, 99999);
         $user['login_salt'] = $salt;
         $user['login'] = $value['email'];
         $user['email'] = $value['email'];
         $user['password'] = md5($value['password'] . $salt);
         $user['ctime'] = time();
         $user['first_letter'] = getFirstLetter($value['uname']);
         $user['sex'] = $value['sex'] == 0 ? 1 : 2;
         $user['is_audit'] = 1;
         $user['is_active'] = 1;
         // 添加用户
         $result = model('User')->add($user);
         // 添加用户组
         model('UserGroupLink')->domoveUsergroup($result, 3);
     }
 }
 /**
  * 注册流程 - 执行第一步骤
  * @return void
  */
 public function doStep1()
 {
     $regType = t($_POST['regType']);
     if (!in_array($regType, array('email', 'phone'))) {
         $this->error('注册参数错误');
     }
     $invite = t($_POST['invate']);
     $inviteCode = t($_POST['invate_key']);
     $email = t($_POST['email']);
     $phone = t($_POST['phone']);
     $regCode = t($_POST['regCode']);
     $uname = t($_POST['uname']);
     $sex = 1 == $_POST['sex'] ? 1 : 2;
     $password = trim($_POST['password']);
     $repassword = trim($_POST['repassword']);
     if (!$this->_register_model->isValidPassword($password, $repassword)) {
         $this->error($this->_register_model->getLastError());
     }
     if ($regType === 'email') {
         //检查验证码
         if (md5(strtoupper($_POST['verify'])) != $_SESSION['verify'] && false) {
             //已关闭
             $this->error('验证码错误');
         }
         if (!$this->_register_model->isValidName($uname)) {
             $this->error($this->_register_model->getLastError());
         }
         if (!$this->_register_model->isValidEmail($email)) {
             $this->error($this->_register_model->getLastError());
         }
     } elseif ($regType === 'phone') {
         if (!model('Captcha')->checkRegisterCode($phone, $regCode)) {
             //已关闭
             $this->error('验证码错误,请检查验证码');
         }
         if (!$this->_register_model->isValidPhone($phone)) {
             $this->error($this->_register_model->getLastError());
         }
         if (!$this->_register_model->isValidName($uname)) {
             $this->error($this->_register_model->getLastError());
         }
         $this->_config['register_audit'] = 0;
         $this->_config['need_active'] = 0;
     }
     // $this->error($phone);
     $login_salt = rand(11111, 99999);
     $map['uname'] = $uname;
     $map['sex'] = $sex;
     $map['login_salt'] = $login_salt;
     $map['password'] = md5(md5($password) . $login_salt);
     if ($regType === 'email') {
         // $map['login'] = $map['email'] = $email;
         $map['email'] = $email;
         $login = $email;
     } elseif ($regType === 'phone') {
         // $map['login'] = $phone;
         $map['phone'] = $phone;
         $login = $phone;
     } else {
         $login = $uname;
     }
     $map['reg_ip'] = get_client_ip();
     $map['ctime'] = time();
     // $this->error(json_encode($map));
     // 添加地区信息
     /*		$map['location'] = t($_POST['city_names']);
     		$cityIds = t($_POST['city_ids']);
     		$cityIds = explode(',', $cityIds);
     		isset($cityIds[0]) && $map['province'] = intval($cityIds[0]);
     		isset($cityIds[1]) && $map['city'] = intval($cityIds[1]);
     		isset($cityIds[2]) && $map['area'] = intval($cityIds[2]);*/
     // 审核状态: 0-需要审核;1-通过审核
     $map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
     // 需求添加 - 若后台没有填写邮件配置,将直接过滤掉激活操作
     $isActive = $this->_config['need_active'] ? 0 : 1;
     if ($isActive == 0) {
         $emailConf = model('Xdata')->get('admin_Config:email');
         if (empty($emailConf['email_host']) || empty($emailConf['email_account']) || empty($emailConf['email_password'])) {
             $isActive = 1;
         }
     }
     $map['is_active'] = $isActive;
     $map['first_letter'] = getFirstLetter($uname);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //昵称和呢称拼音保存到搜索字段
         $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
     } else {
         $map['search_key'] = $map['uname'];
     }
     $uid = $this->_user_model->add($map);
     if ($uid) {
         // 添加积分
         model('Credit')->setUserCredit($uid, 'init_default');
         // 如果是邀请注册,则邀请码失效
         if ($invite) {
             $receiverInfo = model('User')->getUserInfo($uid);
             //验证码使用
             model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
             //添加用户邀请码字段
             model('User')->where('uid=' . $uid)->setField('invite_code', $inviteCode);
             //邀请人操作
             $codeInfo = model('Invite')->getInviteCodeInfo($inviteCode);
             $inviteUid = $codeInfo['inviter_uid'];
             //添加积分
             if ($this->_config['register_type'] == 'open') {
                 model('Credit')->setUserCredit($codeInfo['inviter_uid'], 'invite_friend');
             }
             // 相互关注操作
             model('Follow')->doFollow($uid, intval($inviteUid));
             model('Follow')->doFollow(intval($inviteUid), $uid);
             // 发送通知
             $config['name'] = $receiverInfo['uname'];
             $config['space_url'] = $receiverInfo['space_url'];
             model('Notify')->sendNotify($inviteUid, 'register_invate_ok', $config);
             if ($this->_config['welcome_notify']) {
                 model('Notify')->sendNotify($uid, 'register_welcome', $config);
             }
             //清除缓存
             $this->_user_model->cleanCache($uid);
         }
         // 添加至默认的用户组
         $userGroup = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         //注册来源-第三方帐号绑定
         if (isset($_POST['other_type'])) {
             $other['type'] = t($_POST['other_type']);
             $other['type_uid'] = t($_POST['other_uid']);
             $other['oauth_token'] = t($_POST['oauth_token']);
             $other['oauth_token_secret'] = t($_POST['oauth_token_secret']);
             $other['uid'] = $uid;
             D('login')->add($other);
         }
         //判断是否需要审核
         if ($this->_config['register_audit']) {
             $this->redirect('public/Register/waitForAudit', array('uid' => $uid));
         } else {
             if (!$isActive) {
                 $this->_register_model->sendActivationEmail($uid);
                 $this->redirect('public/Register/waitForActivation', array('uid' => $uid));
             } else {
                 D('Passport')->loginLocal($login, $password);
                 // //注册后需要登录
                 // $this->assign('jumpUrl', U('public/Passport/login'));
                 //直接跳到初始化页面
                 // $this->assign('jumpUrl', U('public/Register/step2'));
                 // $this->success('恭喜您,注册成功');
                 if ($this->_config['personal_open'] == 1) {
                     $this->redirect('public/Register/step2');
                 } else {
                     $this->assign('jumpUrl', U('public/Index/index'));
                     $this->success('恭喜您,注册成功');
                 }
             }
         }
     } else {
         $this->error(L('PUBLIC_REGISTER_FAIL'));
         // 注册失败
     }
 }
Ejemplo n.º 7
0
 /**
  * 注册流程 - 执行第一步骤
  * @return void
  */
 public function doStep1()
 {
     $invite = t($_POST['invate']);
     $inviteCode = t($_POST['invate_key']);
     $email = t($_POST['Reg_email']);
     $uname = t($_POST['Reg_name']);
     $utype = t($_POST['Reg_capacity']);
     $password = trim($_POST['Reg_pwd']);
     // $repassword = trim($_POST['repassword']);
     if (!$this->_register_model->isValidName($uname)) {
         $this->error($this->_register_model->getLastError());
     }
     //检查验证码
     /*
     if (md5(strtoupper($_POST['verify'])) != $_SESSION['verify']) {
     	$this->error('验证码错误');
     }		
     
     if(!$this->_register_model->isValidPassword($password, $repassword)){
     	$this->error($this->_register_model->getLastError());
     }
     
     // if (!$_POST['accept_service']) {
     // 	$this->error(L('PUBLIC_ACCEPT_SERVICE_TERMS'));
     // }
     */
     //验证邮箱唯一性
     if (!$this->_register_model->isValidEmail($email)) {
         $this->error($this->_register_model->getLastError());
     }
     $login_salt = rand(11111, 99999);
     $map['uname'] = $uname;
     $map['utype'] = $utype;
     $map['login_salt'] = $login_salt;
     $map['password'] = md5(md5($password) . $login_salt);
     $map['login'] = $map['email'] = $email;
     $map['reg_ip'] = get_client_ip();
     $map['ctime'] = time();
     /*
     		// 添加地区信息  暂不需要
     		$map['location'] = t($_POST['city_names']);
     		$cityIds = t($_POST['city_ids']);
     		$cityIds = explode(',', $cityIds);
     		isset($cityIds[0]) && $map['province'] = intval($cityIds[0]);
     		isset($cityIds[1]) && $map['city'] = intval($cityIds[1]);
     		isset($cityIds[2]) && $map['area'] = intval($cityIds[2]);
     */
     // 审核状态: 0-需要审核;1-通过审核
     $map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
     // 需求添加 - 若后台没有填写邮件配置,将直接过滤掉激活操作
     $isActive = $this->_config['need_active'] ? 0 : 1;
     if ($isActive == 0) {
         $emailConf = model('Xdata')->get('admin_Config:email');
         if (empty($emailConf['email_host']) || empty($emailConf['email_account']) || empty($emailConf['email_password'])) {
             $isActive = 1;
         }
     }
     $map['is_active'] = $isActive;
     $map['first_letter'] = getFirstLetter($uname);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //昵称和呢称拼音保存到搜索字段
         $map['PY'] = model('PinYin')->Pinyin($map['uname']);
         $map['search_key'] = $map['uname'] . ' ' . $map['PY'];
     } else {
         $map['PY'] = $map['search_key'] = $map['uname'];
     }
     $count_PY = $this->_user_model->where('PY="' . $map[PY] . '"')->count();
     if ($count_PY) {
         $map['domain'] = $map['PY'] . '-' . $count_PY;
     } else {
         $map['domain'] = $map['PY'];
     }
     $uid = $this->_user_model->add($map);
     if ($uid) {
         // 添加积分
         model('Credit')->setUserCredit($uid, 'init_default');
         // 如果是邀请注册,则邀请码失效
         if ($invite) {
             $receiverInfo = model('User')->getUserInfo($uid);
             // 验证码使用
             model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
             // 添加用户邀请码字段
             model('User')->where('uid=' . $uid)->setField('invite_code', $inviteCode);
             //给邀请人奖励
         }
         // 添加至默认的用户组
         $userGroup = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         //注册来源-第三方帐号绑定
         if (isset($_POST['other_type'])) {
             $other['type'] = t($_POST['other_type']);
             $other['type_uid'] = t($_POST['other_uid']);
             $other['oauth_token'] = t($_POST['oauth_token']);
             $other['oauth_token_secret'] = t($_POST['oauth_token_secret']);
             $other['uid'] = $uid;
             D('login')->add($other);
         }
         //判断是否需要审核
         if ($this->_config['register_audit']) {
             $this->redirect('public/Register/waitForAudit', array('uid' => $uid));
         } else {
             if (!$isActive) {
                 $this->_register_model->sendActivationEmail($uid);
                 $this->redirect('public/Register/waitForActivation', array('uid' => $uid));
             } else {
                 D('Passport')->loginLocal($email, $password);
                 $this->assign('jumpUrl', U('public/Passport/login'));
                 $this->redirect('public/Register/step2', array());
             }
         }
     } else {
         $this->error(L('PUBLIC_REGISTER_FAIL'));
         // 注册失败
     }
 }
Ejemplo n.º 8
0
 public function formatByFirstLetter($list)
 {
     $peoplelist = array('#' => array(), 'A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
     foreach ($list as $k => $v) {
         $first_letter = getFirstLetter($v['uname']);
         switch ($first_letter) {
             case '#':
                 $peoplelist['#'][] = $list[$k];
                 break;
             case 'A':
                 $peoplelist['A'][] = $list[$k];
                 break;
             case 'B':
                 $peoplelist['B'][] = $list[$k];
                 break;
             case 'C':
                 $peoplelist['C'][] = $list[$k];
                 break;
             case 'D':
                 $peoplelist['D'][] = $list[$k];
                 break;
             case 'E':
                 $peoplelist['E'][] = $list[$k];
                 break;
             case 'F':
                 $peoplelist['F'][] = $list[$k];
                 break;
             case 'G':
                 $peoplelist['G'][] = $list[$k];
                 break;
             case 'H':
                 $peoplelist['H'][] = $list[$k];
                 break;
             case 'I':
                 $peoplelist['I'][] = $list[$k];
                 break;
             case 'J':
                 $peoplelist['J'][] = $list[$k];
                 break;
             case 'K':
                 $peoplelist['K'][] = $list[$k];
                 break;
             case 'L':
                 $peoplelist['L'][] = $list[$k];
                 break;
             case 'M':
                 $peoplelist['M'][] = $list[$k];
                 break;
             case 'N':
                 $peoplelist['N'][] = $list[$k];
                 break;
             case 'O':
                 $peoplelist['O'][] = $list[$k];
                 break;
             case 'P':
                 $peoplelist['P'][] = $list[$k];
                 break;
             case 'Q':
                 $peoplelist['Q'][] = $list[$k];
                 break;
             case 'R':
                 $peoplelist['R'][] = $list[$k];
                 break;
             case 'S':
                 $peoplelist['S'][] = $list[$k];
                 break;
             case 'T':
                 $peoplelist['T'][] = $list[$k];
                 break;
             case 'U':
                 $peoplelist['U'][] = $list[$k];
                 break;
             case 'V':
                 $peoplelist['V'][] = $list[$k];
                 break;
             case 'W':
                 $peoplelist['W'][] = $list[$k];
                 break;
             case 'X':
                 $peoplelist['X'][] = $list[$k];
                 break;
             case 'Y':
                 $peoplelist['Y'][] = $list[$k];
                 break;
             case 'Z':
                 $peoplelist['Z'][] = $list[$k];
                 break;
         }
         unset($first_letter);
     }
     foreach ($peoplelist as $k => $v) {
         if (count($v) < 1) {
             unset($peoplelist[$k]);
         }
     }
     return $peoplelist;
 }
Ejemplo n.º 9
0
 /**
  * 添加用户
  *
  * @param array $user
  *        	新用户的相关信息|新用户对象
  * @return boolean 是否添加成功
  */
 public function addUser(array $user)
 {
     // # 判断用户名是否被注册
     if ($user['uname'] and !$this->isChangeUserName($user['uname'])) {
         $this->error = '用户昵称已存在,请使用其他昵称';
         return false;
         // # 判断手机号码是否被注册
     } elseif ($user['phone'] and !$this->isChangePhone($user['phone'])) {
         $this->error = '该手机号已经存在,请更换';
         return false;
         // # 判断邮箱是否被注册
     } elseif ($user['email'] and !$this->isChangeEmail($user['email'])) {
         $this->error = '该邮箱已经被注册,请更换';
         return false;
     }
     $user['login_salt'] = rand(10000, 99999);
     // # 用户盐值
     $user['ctime'] = time();
     // # 注册时间
     $user['reg_ip'] = get_client_ip();
     // # 用户客户端注册IP
     $user['password'] = $this->encryptPassword($user['password'], $user['login_salt']);
     $user['first_letter'] = getFirstLetter($user['uname']);
     $user['search_key'] = $user['uname'];
     preg_match('/[\\x7f-\\xff]/', $user['uname']) and $user['search_key'] .= '  ' . model('PinYin')->Pinyin($user['uname']);
     if ($uid = $this->add($user)) {
         // # 添加部门信息
         model('Department')->updateUserDepartById($uid, intval($_POST['department_id']));
         // # 添加用户组关联信息
         empty($_POST['user_group']) or model('UserGroupLink')->domoveUsergroup($uid, implode(',', $_POST['user_group']));
         // # 添加用户职业关联信息
         empty($_POST['user_category']) or model('UserCategory')->updateRelateUser($uid, $_POST['user_category']);
         return true;
     }
     $this->error = L('PUBLIC_ADD_USER_FAIL');
     return false;
     // // 验证用户名称是否重复
     // $map ['uname'] = t ( $user ['uname'] );
     // $map ['login'] = t ( $user ['login'] );
     // $isExist = $this->where ( $map )->count ();
     // if ($isExist > 0) {
     // 	$this->error = '用户昵称已存在,请使用其他昵称';
     // 	return false;
     // }
     // if (is_object ( $user )) {  // # 操,前面都按照数组操作了,这里来判断是不是对象,写这个方法的程序员是傻逼?
     // 	$salt = rand ( 11111, 99999 );
     // 	$user->login_salt = $salt;
     // 	$user->login = ! empty ( $map ['login'] ) ? $map ['login'] : $user->email;
     // 	$user->ctime = time ();
     // 	$user->reg_ip = get_client_ip ();
     // 	$user->password = $this->encryptPassword ( $user->password, $salt );
     // } else if (is_array ( $user )) {
     // 	$salt = rand ( 11111, 99999 );
     // 	$user ['login_salt'] = $salt;
     // 	$user ['login'] = ! empty ( $user ['login'] ) ? $user ['login'] : $user ['email'];
     // 	$user ['ctime'] = time ();
     // 	$user ['reg_ip'] = get_client_ip ();
     // 	$user ['password'] = $this->encryptPassword ( $user ['password'], $salt );
     // }
     // // 添加昵称拼音索引
     // $user ['first_letter'] = getFirstLetter ( $user ['uname'] );
     // // 如果包含中文将中文翻译成拼音
     // if (preg_match ( '/[\x7f-\xff]+/', $user ['uname'] )) {
     // 	// 昵称和呢称拼音保存到搜索字段
     // 	$user ['search_key'] = $user ['uname'] . ' ' . model ( 'PinYin' )->Pinyin ( $user ['uname'] );
     // } else {
     // 	$user ['search_key'] = $user ['uname'];
     // }
     // // 添加用户操作
     // $result = $this->add ( $user );
     // if (! $result) {
     // 	$this->error = L ( 'PUBLIC_ADD_USER_FAIL' ); // 添加用户失败
     // 	return false;
     // } else {
     // 	// 添加部门关联信息
     // 	model ( 'Department' )->updateUserDepartById ( $result, intval ( $_POST ['department_id'] ) );
     // 	// 添加用户组关联信息
     // 	if (! empty ( $_POST ['user_group'] )) {
     // 		model ( 'UserGroupLink' )->domoveUsergroup ( $result, implode ( ',', $_POST ['user_group'] ) );
     // 	}
     // 	// 添加用户职业关联信息
     // 	if (! empty ( $_POST ['user_category'] )) {
     // 		model ( 'UserCategory' )->updateRelateUser ( $result, $_POST ['user_category'] );
     // 	}
     // 	return true;
     // }
 }
Ejemplo n.º 10
0
 /**
  * 保存用户信息
  * @return [type] [description]
  */
 public function saveInfo()
 {
     $post = I('post.');
     $o_info = $this->redis->HGETALL('Userinfo:uid' . $this->mid);
     $info = array();
     //头像
     $o_headimg = json_decode($o_info['headimg'], true) ? json_decode($o_info['headimg'], true) : array();
     $o_headimg_ids = getSubByKey($o_headimg, 'rid');
     $o_headimg_str = $o_headimg_ids ? implode(',', $o_headimg_ids) : '';
     if ($o_headimg_str != trim($post['headimg'], ',') && isset($post['headimg'])) {
         $info['headimg'] = trim($post['headimg'], ',');
         $headimg_arr = explode(',', $info['headimg']);
         foreach ($headimg_arr as $v) {
             $photo_res = array();
             $photo_res['rid'] = $v;
             $photo_res['url'] = C('WEBSITE_URL') . D('picture')->where('id=' . $v)->getField('path');
             $photo[] = $photo_res;
         }
         $this->redis->HSET('Userinfo:uid' . $this->mid, 'headimg', json_encode($photo, JSON_UNESCAPED_UNICODE));
         $new_photo = explode(',', trim($post['headimg'], ',')) ? explode(',', trim($post['headimg'], ',')) : array();
         $o_headimg_ids = $o_headimg_ids ? $o_headimg_ids : array();
         $add_photo = array_diff($new_photo, $o_headimg_ids);
         if ($add_photo) {
             $sj_log['uid'] = $this->mid;
             $sj_log['type'] = 1;
             foreach ($add_photo as $v) {
                 $sj_log['url'] = D('picture')->where('id=' . $v)->getField('path');
                 D('shunjian')->add($sj_log);
             }
         }
     }
     //昵称
     if ($post['uname'] != $o_info['uname'] && isset($post['uname'])) {
         if ($post['uname'] == '') {
             $this->return['code'] == 1004;
             $this->return['message'] == L('uname_null');
             $this->goJson($this->return);
         }
         $info['uname'] = $post['uname'];
         load("@.user");
         $info['first_letter'] = getFirstLetter($post['uname']);
         //如果包含中文将中文翻译成拼音
         if (preg_match('/[\\x7f-\\xff]+/', $post['uname'])) {
             import("Common.Util.PinYin");
             $pinyinClass = new \PinYin();
             $pinyin = $pinyinClass->Pinyin($post['uname']);
             //昵称和呢称拼音保存到搜索字段
             $info['search_key'] = $post['uname'] . ' ' . $pinyin;
         } else {
             $info['search_key'] = $post['uname'];
         }
     }
     // 性别
     if ($post['sex'] != $o_info['sex'] && isset($post['sex'])) {
         if ($post['sex'] != 1 && $post['sex'] != 2) {
             $this->return['code'] == 1003;
             $this->return['message'] == L('sex_error');
             $this->goJson($this->return);
         }
         $info['sex'] = $post['sex'];
         $sex_flag = $post['sex'] == 1 ? 2 : 1;
         $this->redis->sRem('User:sex' . $sex_flag, $this->mid);
         $this->redis->sAdd('User:sex' . $info['sex'], $this->mid);
     }
     // 个性签名
     if ($post['intro'] != $o_info['intro'] && isset($post['intro'])) {
         $info['intro'] = $post['intro'];
     }
     // 视频介绍
     $o_info['video_profile'] = json_decode($o_info['video_profile'], true) ? json_decode($o_info['video_profile'], true) : array();
     if ($post['video_profile'] != $o_info['video_profile']['rid'] && isset($post['video_profile'])) {
         $info['video_profile'] = $post['video_profile'];
         $video = D('file')->field('savepath, savename')->where('id=' . $post['video_profile'])->find();
         $video_profile['rid'] = $post['video_profile'];
         $video_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $video['savepath'] . $video['savename'];
         $this->redis->HSET('Userinfo:uid' . $this->mid, 'video_profile', json_encode($video_profile, JSON_UNESCAPED_UNICODE));
         $video_profile_data['type'] = 2;
         $video_profile_data['url'] = '/Uploads/File/' . $video['savepath'] . $video['savename'];
         $video_profile_data['uid'] = $this->mid;
         D('shunjian')->add($video_profile_data);
         unset($video_profile_data);
     }
     // 音频介绍
     $o_info['audio_profile'] = json_decode($o_info['audio_profile'], true) ? json_decode($o_info['audio_profile'], true) : array();
     if ($post['audio_profile'] != $o_info['audio_profile']['rid'] && $post['audio_profile']) {
         $info['audio_profile'] = $post['audio_profile'];
         $audio = D('file')->field('savepath, savename')->where('id=' . $post['audio_profile'])->find();
         $audio_profile['rid'] = $post['audio_profile'];
         $audio_profile['url'] = C('WEBSITE_URL') . '/Uploads/File/' . $audio['savepath'] . $audio['savename'];
         $this->redis->HSET('Userinfo:uid' . $this->mid, 'audio_profile', json_encode($audio_profile, JSON_UNESCAPED_UNICODE));
     }
     // 国家,省,城市信息
     if (isset($post['country']) && $post['country'] != 0) {
         if ($post['country'] != $o_info['country']) {
             $info['country'] = $post['country'];
             $info['province'] = $post['province'];
             $info['city'] = $post['city'];
             $info['location'] = $post['location'];
         } elseif ($post['province'] != $o_info['province'] && isset($post['province'])) {
             $info['province'] = $post['province'];
             $info['city'] = $post['city'];
             $info['location'] = $post['location'];
         } elseif ($post['city'] != $o_info['city'] && isset($post['city'])) {
             $info['city'] = $post['city'];
             $info['location'] = $post['location'];
         }
     }
     //语言 更改
     $o_language = json_decode($o_info['language'], true) ? json_decode($o_info['language'], true) : array();
     if ($post['language']['lid'] != $o_language['lid'] && isset($post['language']['lid'])) {
         $info['cur_language'] = $language['lid'] = $post['language']['lid'];
     }
     if ($post['language']['self_level'] != $o_language['self_level'] && isset($post['language']['self_level'])) {
         $info['level'] = $language['self_level'] = $post['language']['self_level'];
     }
     if (count($language)) {
         D('userLanguage')->where('uid=' . $this->mid)->save($language);
         $language = D('userLanguage')->where('uid=' . $this->mid)->field('lid, type, sys_level, self_level')->select();
         $allLanguage = D('language')->getAllLanguage();
         foreach ($language as $k => $v) {
             $language[$k]['language_name'] = $allLanguage[$v['lid']];
         }
         $this->redis->HSET('Userinfo:uid' . $this->mid, 'language', json_encode($language, JSON_UNESCAPED_UNICODE));
     }
     if (count($info)) {
         D('userinfo')->where('uid=' . $this->mid)->save($info);
         unset($info['video_profile'], $info['headimg'], $info['audio_profile']);
         foreach ($info as $k => $v) {
             $this->redis->HSET('Userinfo:uid' . $this->mid, $k, $v);
         }
     }
     //标签
     if (isset($post['tags'])) {
         $o_tags = json_decode($o_info['tags']) ? json_decode($o_info['tags'], true) : array();
         $o_tag_ids = getSubByKey($o_tags, 'tid');
         $tags_post = explode(',', $post['tags']);
         if (!count($tags_post)) {
             D('userTags')->where('uid=' . $this->mid)->delete();
         } else {
             $tags['uid'] = $this->mid;
             //有新增标签
             $add_tags = array_diff($tags_post, $o_tag_ids);
             if (count($add_tags)) {
                 foreach ($add_tags as $v) {
                     $tags['tid'] = $v;
                     D('userTags')->add($tags);
                 }
             }
             //有删除标签
             $delete_tags = array_diff($o_tag_ids, $tags_post);
             if (count($delete_tags)) {
                 foreach ($delete_tags as $v) {
                     D('userTags')->where('uid=' . $this->mid . ' and tid=' . $v)->delete();
                 }
             }
             //如果有变化,取出该用户全部标签进行缓存
             if (count($delete_tags) || count($add_tags)) {
                 $allTags = D('tags')->getAllTags();
                 $tags_res = D('userTags')->field('tid')->where('uid=' . $this->mid)->select();
                 foreach ($tags_res as $k => $val) {
                     $tags_res[$k]['tag_name'] = $allTags[$val['tid']];
                 }
                 $this->redis->HSET('Userinfo:uid' . $this->mid, 'tags', json_encode($tags_res, JSON_UNESCAPED_UNICODE));
             }
         }
     }
     //$this->return['data'] = $this->getUserinfoData($this->mid);
     $this->goJson($this->return);
 }
Ejemplo n.º 11
0
 public function doRegister()
 {
     $service = model('Register');
     $email = $service->isValidEmail($_POST['email']);
     $uname = $service->isValidName($_POST['uname']);
     $password = $service->isValidPassword($_POST['password'], $_POST['password']);
     if (!$email && !$uname && !$password) {
         echo $service->getLastError();
     } else {
         if ($user = model('Passport')->getLocalUser($email, $password)) {
             if ($user['is_active'] == 0) {
                 redirect(U('w3g/Public/login'), 3, '帐号尚未激活,请激活后重新登录');
             }
         }
         $invite = t($_POST['invate']);
         $inviteCode = t($_POST['invate_key']);
         $email = t($_POST['email']);
         $uname = t($_POST['uname']);
         $sex = 1 == $_POST['sex'] ? 1 : 2;
         $password = trim($_POST['password']);
         $repassword = trim($_POST['repassword']);
         $login_salt = rand(11111, 99999);
         $map['uname'] = $uname;
         $map['sex'] = $sex;
         $map['login_salt'] = $login_salt;
         $map['password'] = md5(md5($password) . $login_salt);
         $map['login'] = $map['email'] = $email;
         $map['reg_ip'] = get_client_ip();
         $map['ctime'] = time();
         $map['first_letter'] = getFirstLetter($uname);
         $map['is_init'] = 1;
         // 审核状态: 0-需要审核;1-通过审核
         $map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
         // 需求添加 - 若后台没有填写邮件配置,将直接过滤掉激活操作
         $isActive = $this->_config['need_active'] ? 0 : 1;
         if ($isActive == 0) {
             $emailConf = model('Xdata')->get('admin_Config:email');
             if (empty($emailConf['email_host']) || empty($emailConf['email_account']) || empty($emailConf['email_password'])) {
                 $isActive = 1;
             }
         }
         $map['is_active'] = $isActive;
         $map['first_letter'] = getFirstLetter($uname);
         //如果包含中文将中文翻译成拼音
         if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
             //昵称和呢称拼音保存到搜索字段
             $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
         } else {
             $map['search_key'] = $map['uname'];
         }
         $uid = $this->_user_model->add($map);
         // dump($uid);
         if ($uid) {
             // 添加积分
             model('Credit')->setUserCredit($uid, 'init_default');
             // 如果是邀请注册,则邀请码失效
             if ($invite) {
                 // 验证码使用
                 $receiverInfo = model('User')->getUserInfo($uid);
                 // 添加用户邀请码字段
                 model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
                 //给邀请人奖励
                 model('User')->where('uid=' . $uid)->setField('invite_code', $inviteCode);
             }
             // 添加至默认的用户组
             $userGroup = model('Xdata')->get('admin_Config:register');
             $userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
             model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
             // //注册来源-第三方帐号绑定
             // if(isset($_POST['other_type'])){
             // 	$other['type'] = t($_POST['other_type']);
             // 	$other['type_uid'] = t($_POST['other_uid']);
             // 	$other['oauth_token'] = t($_POST['oauth_token']);
             // 	$other['oauth_token_secret'] = t($_POST['oauth_token_secret']);
             // 	$other['uid'] = $uid;
             // 	D('login')->add($other);
             // }
             // //判断是否需要审核
             // if($this->_config['register_audit']) {
             // 	$this->redirect('w3g/Register/waitForAudit', array('uid' => $uid));
             // } else {
             // 	if(!$isActive){
             // 		$this->_register_model->sendActivationEmail($uid);
             // 		$this->redirect('w3g/Register/waitForActivation', array('uid' => $uid));
             // 	}else{
             D('Passport')->loginLocal($email, $password);
             // $this->assign('jumpUrl', U('w3g/Index/login'));
             // $this->success('恭喜您,注册成功');
             echo '1';
             // 	}
             // }
         } else {
             // $this->error(L('PUBLIC_REGISTER_FAIL'));			// 注册失败
             echo '0';
         }
     }
     //    $uid     = $service->register($email, $uname, $password, true);
     //    if (!$uid){
     //        redirect(U('/Public/register', $_POST), 3, $service->getLastError());
     //    }else{
     //        //redirect(U('/Public/login'), 1, '注册成功');
     // 	if ($user = model('Passport')->getLocalUser($email, $password)) {
     // 		if ($user['is_active'] == 0) {
     // 			redirect(U('wap/Public/login'), 3, '帐号尚未激活,请激活后重新登录');
     // 		}
     // 		$result = model('Passport')->registerLogin($user);
     // 		redirect(U('wap/Index/index'));
     // 	} else {
     // 		redirect(U('wap/Public/login'), 3, '帐号或密码错误,请重新输入');
     // 	}
     // }
 }
Ejemplo n.º 12
0
 /**
  * 注册流程 - 执行第一步骤
  * @return void
  */
 public function doStep1()
 {
     $invite = t($_POST['invate']);
     $inviteCode = t($_POST['invate_key']);
     $email = t($_POST['email']);
     $uname = t($_POST['uname']);
     $sex = 1 == $_POST['sex'] ? 1 : 2;
     $password = trim($_POST['password']);
     $repassword = trim($_POST['repassword']);
     if (!$this->_register_model->isValidEmail($email)) {
         $this->error($this->_register_model->getLastError());
     }
     if (!$this->_register_model->isValidPassword($password, $repassword)) {
         $this->error($this->_register_model->getLastError());
     }
     /*		if (!$_POST['accept_service']) {
     			$this->error(L('PUBLIC_ACCEPT_SERVICE_TERMS'));
     		}*/
     $login_salt = rand(11111, 99999);
     $map['uname'] = $uname;
     $map['sex'] = $sex;
     $map['login_salt'] = $login_salt;
     $map['password'] = md5(md5($password) . $login_salt);
     $map['login'] = $map['email'] = $email;
     $map['regip'] = get_client_ip();
     $map['ctime'] = time();
     // 添加地区信息
     $map['location'] = t($_POST['city_names']);
     $cityIds = t($_POST['city_ids']);
     $cityIds = explode(',', $cityIds);
     isset($cityIds[0]) && ($map['province'] = intval($cityIds[0]));
     isset($cityIds[1]) && ($map['city'] = intval($cityIds[1]));
     isset($cityIds[2]) && ($map['area'] = intval($cityIds[2]));
     // 审核状态: 0-需要审核;1-通过审核
     $map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
     $map['is_active'] = $this->_config['need_active'] ? 0 : 1;
     $map['first_letter'] = getFirstLetter($uname);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //昵称和呢称拼音保存到搜索字段
         $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
     } else {
         $map['search_key'] = $map['uname'];
     }
     $uid = $this->_user_model->add($map);
     if ($uid) {
         // 如果是邀请注册,则邀请码失效
         if ($invite) {
             $receiverInfo = model('User')->getUserInfo($uid);
             // 验证码使用
             model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
             // 添加用户邀请码字段
             model('User')->where('uid=' . $uid)->setField('invite_code', $inviteCode);
         }
         // 添加至默认的用户组
         $userGroup = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         //注册来源-第三方帐号绑定
         if (isset($_POST['other_type'])) {
             $other['type'] = t($_POST['other_type']);
             $other['type_uid'] = intval($_POST['other_uid']);
             $other['oauth_token'] = t($_POST['oauth_token']);
             $other['oauth_token_secret'] = t($_POST['oauth_token_secret']);
             $other['uid'] = $uid;
             D('login')->add($other);
         }
         //判断是否需要审核
         if ($this->_config['register_audit']) {
             $this->redirect('public/Register/waitForAudit', array('uid' => $uid));
         } else {
             if ($this->_config['need_active']) {
                 $this->_register_model->sendActivationEmail($uid);
                 $this->redirect('public/Register/waitForActivation', array('uid' => $uid));
             } else {
                 D('Passport')->loginLocal($email, $password);
                 $this->assign('jumpUrl', U('public/Passport/login'));
                 $this->success('恭喜您,注册成功');
             }
         }
     } else {
         $this->error(L('PUBLIC_REGISTER_FAIL'));
         // 注册失败
     }
 }
Ejemplo n.º 13
0
 /**
  * 认证方法 --using
  * @param varchar oauth_token
  * @param varchar oauth_token_secret
  * @return array 状态+提示
  */
 public function register()
 {
     $phone = floatval($this->data['phone']);
     // 手机号码
     $username = '******' . t($this->data['username']);
     // 用户名
     $password = $this->data['password'];
     // 密码
     $sex = intval($this->data['sex']);
     in_array($sex, array(1, 2)) or $sex = 1;
     // 默认 男 1.男,2女
     $register = model('Register');
     $config = model('Xdata')->get('admin_Config:register');
     // 配置
     /* 判断用户手机号码可用性 */
     if (!$register->isValidPhone($phone)) {
         return array('status' => 0, 'msg' => $register->getLastError());
         /* 判断用户名是否可用 */
     } elseif (!$register->isValidName($username)) {
         return array('status' => 0, 'msg' => $register->getLastError());
         /* 密码判断 */
     } elseif (!$register->isValidPasswordNoRepeat($password)) {
         return array('status' => 0, 'msg' => $register->getLastError());
     }
     $userData = array('login_salt' => rand(10000, 99999));
     // 用户基本资料数组
     $userData['password'] = model('User')->encryptPassword($password, $userData['login_salt']);
     // 用户密码
     $userData['uname'] = $username;
     // 用户名
     $userData['phone'] = $phone;
     // 用户手机号码
     $userData['sex'] = $sex;
     // 用户性别
     $userData['ctime'] = time();
     // 注册时间
     $userData['reg_ip'] = get_client_ip();
     // 注册IP
     /* 用户是否默认审核 */
     $userData['is_audit'] = 1;
     $config['register_audit'] and $userData['is_audit'] = 0;
     $userData['is_active'] = 1;
     // 默认激活
     $userData['is_init'] = 1;
     // 默认初始化
     $userData['first_letter'] = getFirstLetter($username);
     // 用户首字母
     /* 用户搜索 */
     $userData['search_key'] = $username . ' ' . $userData['first_letter'];
     preg_match('/[\\x7f-\\xff]+/', $username) and $userData['search_key'] .= ' ' . Pinyin::getShortPinyin($username, 'utf-8');
     $uid = model('User')->add($userData);
     // 添加用户数据
     if (!$uid) {
         return array('status' => 0, 'msg' => '注册失败');
     }
     // 注册失败的提示
     /* 添加默认用户组 */
     $userGroup = $config['default_user_group'];
     empty($userGroup) and $userGroup = C('DEFAULT_GROUP_ID');
     is_array($userGroup) and $userGroup = implode(',', $userGroup);
     model('UserGroupLink')->domoveUsergroup($uid, $userGroup);
     /* 添加双向关注用户 */
     if (!empty($config['each_follow'])) {
         model('Follow')->eachDoFollow($uid, $config['each_follow']);
     }
     /* 添加默认关注用户 */
     $defaultFollow = $config['default_follow'];
     $defaultFollow = explode(',', $defaultFollow);
     $defaultFollow = array_diff($defaultFollow, explode(',', $config['each_follow']));
     empty($defaultFollow) or model('Follow')->bulkDoFollow($uid, $defaultFollow);
     return array('status' => 1, 'msg' => '注册成功');
 }
Ejemplo n.º 14
0
 /**
  * 备份
  * 获取地区(按字母) --using
  *
  * @return array 城市列表
  */
 public function get_user_city_bak()
 {
     $my = model('User')->where('`uid` = ' . $this->mid)->getField('city');
     $letters = array('my' => array(), 'A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
     $provinces = D('area')->where('pid=0')->findAll();
     $map['pid'] = array('in', getSubByKey($provinces, 'area_id'));
     $map['title'] = array('exp', 'not in("市辖区","县","市","省直辖县级行政单位" ,"省直辖行政单位")');
     $citys = D('area')->where($map)->findAll();
     foreach ($citys as $k => $v) {
         $first_letter = getFirstLetter($v['title']);
         $letters[$first_letter][$v['area_id']]['city_id'] = $v['area_id'];
         $letters[$first_letter][$v['area_id']]['city_name'] = $v['title'];
         if ($v['area_id'] == $my) {
             $letters['my'][$v['area_id']]['city_id'] = $v['area_id'];
             $letters['my'][$v['area_id']]['city_name'] = $v['title'];
         }
         unset($first_letter);
     }
     return $letters;
 }
Ejemplo n.º 15
0
 /**
  * 获取地区 --using
  *
  * @return array 地区列表
  */
 public function get_area_list()
 {
     $letters = array('A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
     $provinces = D('area')->where('pid=0')->findAll();
     $map['pid'] = array('in', getSubByKey($provinces, 'area_id'));
     $citys = D('area')->where($map)->findAll();
     $map1['pid'] = array('in', getSubByKey($citys, 'area_id'));
     $map1['title'] = array('exp', 'not in("市辖区","县","市","省直辖县级行政单位" ,"省直辖行政单位")');
     $countys = D('area')->where($map1)->findAll();
     // 所有的县
     foreach ($countys as $k => $v) {
         $first_letter = getFirstLetter($v['title']);
         $letters[$first_letter][$v['area_id']]['city_id'] = $v['area_id'];
         $letters[$first_letter][$v['area_id']]['city_name'] = $v['title'];
         unset($first_letter);
     }
     return $letters;
 }
Ejemplo n.º 16
0
 /**
  * 修改用户信息 --using
  *
  * @param string $uname
  *            用户名
  * @param integer $sex
  *            性别(1-男,2-女)
  * @param string $intro
  *            个人简介
  * @param string $city_id
  *            地区ID
  * @param string $password
  *            新密码
  * @param string $old_password
  *            旧密码
  * @param string $tags
  *            标签(多个标签之间用逗号隔开)
  */
 public function save_user_info()
 {
     $save = array();
     // 修改用户昵称
     if (isset($this->data['uname'])) {
         $uname = t($this->data['uname']);
         $save['uname'] = filter_keyword($uname);
         $oldName = t($this->data['old_name']);
         $res = model('Register')->isValidName($uname);
         if (!$res) {
             $error = model('Register')->getLastError();
             return array('status' => 0, 'msg' => $error);
         }
         $save['first_letter'] = getFirstLetter($uname);
         // 如果包含中文将中文翻译成拼音
         if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) {
             // 昵称和呢称拼音保存到搜索字段
             $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']);
         } else {
             $save['search_key'] = $save['uname'];
         }
     }
     // 修改性别
     if (isset($this->data['sex'])) {
         $save['sex'] = 1 == intval($this->data['sex']) ? 1 : 2;
     }
     // 修改用户真实姓名
     if (isset($this->data['realname'])) {
         $save['realname'] = t($this->data['realname']);
     }
     // 修改公司
     if (isset($this->data['company'])) {
         $save['company'] = t($this->data['company']);
     }
     // 修改职位
     if (isset($this->data['position'])) {
         $save['position'] = t($this->data['position']);
     }
     // 修改个人简介
     if (isset($this->data['intro'])) {
         $save['intro'] = t($this->data['intro']);
     }
     // // 修改地区
     // if ($this->data ['city_id']) {
     //     $area_id = intval ( $this->data ['city_id'] );
     //     $area = D ( 'area' )->where ( 'area_id=' . $area_id )->find ();
     //     $city = D ( 'area' )->where ( 'area_id=' . $area ['pid'] )->find ();
     //     $province = D ( 'area' )->where ( 'area_id=' . $city ['pid'] )->find ();
     //     $save ['province'] = intval ( $province ['area_id'] );
     //     $save ['city'] = intval ( $city ['area_id'] );
     //     $save ['area'] = t ( $area ['area_id'] );
     //     $save ['location'] = $province ['title'] . ' ' . $city ['title'] . ' ' . $area ['title'];
     // }
     // 修改地区
     if ($this->data['city_id']) {
         $id = intval($this->data['city_id']);
         //$area = D ( 'district' )->where ( 'id=' . $id )->find ();
         $city = D('district')->where('id=' . $id)->find();
         $province = D('district')->where('id=' . $city['upid'])->find();
         $save['province'] = intval($province['id']);
         $save['city'] = intval($city['id']);
         //$save ['area'] = t ( $area ['id'] );
         $save['location'] = $province['name'] . ' ' . $city['name'];
     }
     // 修改密码
     if ($this->data['password']) {
         // 验证新密码与旧密码是否一致
         if ($this->data['password'] == $this->data['old_password']) {
             $return = array('status' => 0, 'msg' => L('PUBLIC_PASSWORD_SAME'));
             return $return;
         }
     }
     // 数据中心修改用户昵称性别地区
     if (!empty($save) || $this->data['password'] && $this->data['old_password']) {
         $sCenter_token = $this->getCenterToken();
         $UserData = model('User')->where('`uid`=' . $this->mid)->find();
         if (!empty($UserData) && ($save['uname'] || $save['sex'] || $save['company'] || $save['position'] || $save['realname'] || $city['name'])) {
             $sCtlgurl = C('APIURL') . '/v1/user/modify?_format=json&access_token=' . $sCenter_token;
             $rCtlg = array('open_id' => $UserData['cyj_id'], 'realname' => '', 'gender' => $save['sex'], 'city' => $city['name'], 'company' => $save['company'], 'position' => $save['position'], 'realname' => $save['realname']);
             if (!empty($save['uname'])) {
                 $rCtlg['username'] = $save['uname'];
             }
             $sCtlgstatus = request_post($sCtlgurl, $rCtlg);
             $rStatus = json_decode($sCtlgstatus, true);
         }
         if ($this->data['password'] && $this->data['old_password']) {
             $sCtlgurl = C('APIURL') . '/v1/user/reset-pwd?_format=json&access_token=' . $sCenter_token;
             $rCtlg = array('open_id' => $UserData['cyj_id'], 'password' => $this->data['password'], 'old_password' => $this->data['old_password']);
             $sCtlgstatus = request_post($sCtlgurl, $rCtlg);
             $rStatus = json_decode($sCtlgstatus, true);
             $save['login_salt'] = $rStatus['data']['ret']['password_salt'];
             $save['password'] = $rStatus['data']['ret']['password'];
         }
         if ($rStatus['code'] === 0 || !empty($this->data['intro'])) {
             $res = model('User')->where('`uid`=' . $this->mid)->save($save);
             $res !== false && model('User')->cleanCache($this->mid);
             $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll();
             if ($user_feeds) {
                 $feed_ids = getSubByKey($user_feeds, 'feed_id');
                 model('Feed')->cleanCache($feed_ids, $this->mid);
             }
             return array('status' => 1, 'msg' => '修改成功');
         }
         if ($rStatus['code'] !== 0) {
             return array('status' => 0, 'msg' => $rStatus['data']['msg']);
         }
     }
     // 修改用户标签
     if (isset($this->data['tags'])) {
         if (empty($this->data['tags'])) {
             return array('status' => 0, 'msg' => L('PUBLIC_TAG_NOEMPTY'));
         }
         $nameList = t($this->data['tags']);
         $nameList = explode(',', $nameList);
         $tagIds = array();
         foreach ($nameList as $name) {
             $tagIds[] = model('Tag')->setAppName('public')->setAppTable('user')->getTagId($name);
         }
         $rowId = intval($this->mid);
         if (!empty($rowId)) {
             $registerConfig = model('Xdata')->get('admin_Config:register');
             if (count($tagIds) > $registerConfig['tag_num']) {
                 return array('status' => 0, 'msg' => '最多只能设置' . $registerConfig['tag_num'] . '个标签');
             }
             model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds);
         }
         return array('status' => 1, 'msg' => '修改成功');
     }
 }
Ejemplo n.º 17
0
 /**
  * 绑定第三方帐号,生成新账号 --using
  * @param varchar uname 用户名
  * @param varchar password 密码
  * @param varchar type 帐号类型
  * @param varchar type_uid 第三方用户标识
  * @param varchar access_token 第三方access token
  * @param varchar refresh_token 第三方refresh token(选填,根据第三方返回值)
  * @param varchar expire_in 过期时间(选填,根据第三方返回值)
  */
 public function bind_new_user()
 {
     $uname = t($this->data['uname']);
     $password = t($this->data['password']);
     //用户名验证
     if (!model('Register')->isValidName($uname)) {
         $msg = model('Register')->getLastError();
         $return = array('status' => 0, 'msg' => $msg);
         return $return;
     }
     //密码验证
     if (!model('Register')->isValidPasswordNoRepeat($password)) {
         $msg = model('Register')->getLastError();
         $return = array('status' => 0, 'msg' => $msg);
         return $return;
     }
     $login_salt = rand(11111, 99999);
     $map['uname'] = $uname;
     $map['login_salt'] = $login_salt;
     $map['password'] = md5(md5($password) . $login_salt);
     $map['login'] = $uname;
     $map['ctime'] = time();
     $registerConfig = model('Xdata')->get('admin_Config:register');
     $map['is_audit'] = $registerConfig['register_audit'] ? 0 : 1;
     $map['is_active'] = 1;
     //手机端不需要激活
     $map['is_init'] = 1;
     //手机端不需要初始化步骤
     $map['first_letter'] = getFirstLetter($uname);
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //如果包含中文将中文翻译成拼音
         $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
     } else {
         $map['search_key'] = $map['uname'];
     }
     $uid = model('User')->add($map);
     if ($uid) {
         //第三方登录数据写入
         $other['oauth_token'] = addslashes($this->data['access_token']);
         $other['oauth_token_secret'] = addslashes($this->data['refresh_token']);
         $other['type'] = addslashes($this->data['type']);
         $other['type_uid'] = addslashes($this->data['type_uid']);
         $other['uid'] = $uid;
         M('login')->add($other);
         $data['oauth_token'] = getOAuthToken($uid);
         $data['oauth_token_secret'] = getOAuthTokenSecret();
         $data['uid'] = $uid;
         $savedata['type'] = 'location';
         $savedata = array_merge($savedata, $data);
         $result = M('login')->add($savedata);
         // 添加至默认的用户组
         $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         // 添加双向关注用户
         $eachFollow = $registerConfig['each_follow'];
         if (!empty($eachFollow)) {
             model('Follow')->eachDoFollow($uid, $eachFollow);
         }
         // 添加默认关注用户
         $defaultFollow = $registerConfig['default_follow'];
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow));
         if (!empty($defaultFollow)) {
             model('Follow')->bulkDoFollow($uid, $defaultFollow);
         }
         return $data;
     } else {
         return array('status' => '0', 'msg' => '注册失败');
     }
 }
Ejemplo n.º 18
0
 /**
  * 添加用户
  *
  * @param array $user
  *        	新用户的相关信息|新用户对象
  * @return boolean 是否添加成功
  */
 public function addUser(array $user)
 {
     // # 判断用户名是否被注册
     if ($user['uname'] and !$this->isChangeUserName($user['uname'])) {
         $this->error = '用户昵称已存在,请使用其他昵称';
         return false;
         // # 判断手机号码是否被注册
     } elseif ($user['phone'] and !$this->isChangePhone($user['phone'])) {
         $this->error = '该手机号已经存在,请更换';
         return false;
         // # 判断邮箱是否被注册
     } elseif ($user['email'] and !$this->isChangeEmail($user['email'])) {
         $this->error = '该邮箱已经被注册,请更换';
         return false;
         /**
          * 如果email为空,则删除email
          */
     } elseif (empty($user['email'])) {
         unset($user['email']);
     }
     $user['login_salt'] = rand(10000, 99999);
     // # 用户盐值
     $user['ctime'] = time();
     // # 注册时间
     $user['reg_ip'] = get_client_ip();
     // # 用户客户端注册IP
     $user['password'] = $this->encryptPassword($user['password'], $user['login_salt']);
     $user['first_letter'] = getFirstLetter($user['uname']);
     $user['search_key'] = $user['uname'];
     preg_match('/[\\x7f-\\xff]/', $user['uname']) and $user['search_key'] .= '  ' . model('PinYin')->Pinyin($user['uname']);
     if ($uid = $this->add($user)) {
         // # 添加部门信息
         model('Department')->updateUserDepartById($uid, intval($_POST['department_id']));
         // # 添加用户组关联信息
         empty($_POST['user_group']) or model('UserGroupLink')->domoveUsergroup($uid, implode(',', $_POST['user_group']));
         // # 添加用户职业关联信息
         empty($_POST['user_category']) or model('UserCategory')->updateRelateUser($uid, $_POST['user_category']);
         return true;
     }
     $this->error = L('PUBLIC_ADD_USER_FAIL');
     return false;
 }
Ejemplo n.º 19
0
 /**
  * 第三方绑定,通过手机号获取用户信息
  *
  */
 public function getUserInfoByPhone()
 {
     file_put_contents('/tmp/test.log', 'getUserInfoByPhone' . "\n\r", FILE_APPEND);
     $phone = $_REQUEST['phone'];
     $code = $this->data['code'];
     if (empty($code)) {
         return $this->returnData('', '验证码不能为空', -1);
     } elseif (!model('Sms')->CheckCaptcha($phone, $code)) {
         return $this->returnData('', model('Sms')->getMessage(), -1);
     }
     //数据中心 判断手机号是否存在 存在返回用户信息
     $sCenter_token = $this->getCenterToken();
     $sCkurl = C('APIURL') . '/v1/user/mobile-sole?access_token=' . $sCenter_token . '&mobile=' . $phone;
     $sJson = request_get($sCkurl);
     file_put_contents('/tmp/test.log', $sJson . "\n\r", FILE_APPEND);
     $rResult = json_decode($sJson, true);
     // code=0 该手机号未被注册
     if ($rResult['code'] === 0) {
         return $this->returnData('', '该帐号尚未注册', 0);
     }
     $map['is_audit'] = 1;
     $map['is_active'] = 1;
     $map['is_init'] = 1;
     $map['cyj_id'] = $rResult['data']['ret']['open_id'];
     //数据中心存在而ts不存在的情况
     $user = model('User')->where(array('cyj_id' => $map['cyj_id']))->find();
     file_put_contents('/tmp/test.log', json_encode($user) . "\n\r", FILE_APPEND);
     if (empty($user)) {
         $regmodel = model('Register');
         $registerConfig = model('Xdata')->get('admin_Config:register');
         //ts开始注册
         $database['phone'] = $rResult['data']['ret']['mobile'];
         $database['uname'] = $rResult['data']['ret']['username'];
         $database['password'] = $rResult['data']['ret']['password'];
         $database['login_salt'] = $rResult['data']['ret']['password_salt'];
         $database['cyj_id'] = $rResult['data']['ret']['open_id'];
         $database['sex'] = $rResult['data']['ret']['gender'] ? $rResult['data']['ret']['gender'] : 0;
         $database['ctime'] = time();
         $database['is_audit'] = $registerConfig['register_audit'] ? 0 : 1;
         // $map['is_audit'] = 1;
         $database['is_active'] = 1;
         //手机端不需要激活
         $database['is_init'] = 1;
         //手机端不需要初始化步骤
         $database['first_letter'] = getFirstLetter($database['uname']);
         if (preg_match('/[\\x7f-\\xff]+/', $database['uname'])) {
             //如果包含中文将中文翻译成拼音
             $database['search_key'] = $database['uname'] . ' ' . model('PinYin')->Pinyin($database['uname']);
         } else {
             $database['search_key'] = $database['uname'];
         }
         $uid = model('User')->add($database);
         // 添加至默认的用户组
         $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         // 添加双向关注用户
         $eachFollow = $registerConfig['each_follow'];
         if (!empty($eachFollow)) {
             model('Follow')->eachDoFollow($uid, $eachFollow);
         }
         // 添加默认关注用户
         $defaultFollow = $registerConfig['default_follow'];
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow));
         if (!empty($defaultFollow)) {
             model('Follow')->bulkDoFollow($uid, $defaultFollow);
         }
     }
     $userInfo = model('User')->getUserInfoByPhone($phone, $map);
     file_put_contents('/tmp/test.log', json_encode($userInfo) . "\n\r", FILE_APPEND);
     $rtnData = array();
     if ($userInfo) {
         $rtnData['uid'] = $userInfo['uid'];
         $rtnData['uname'] = $rResult['data']['ret']['username'];
         $rtnData['sex'] = $rResult['data']['ret']['gender'] ? $rResult['data']['ret']['gender'] : 0;
         $rtnData['ctime'] = $userInfo['ctime'];
         $rtnData['avatar'] = $userInfo['avatar_original'];
         //$rResult['data']['ret']['avatar'];
         if ($login = D('')->table(C('DB_PREFIX') . 'login')->where("uid=" . $userInfo['uid'] . " AND type='location'")->find()) {
             $data['oauth_token'] = $login['oauth_token'];
             $data['oauth_token_secret'] = $login['oauth_token_secret'];
         } else {
             $data['oauth_token'] = getOAuthToken($userInfo['uid']);
             $data['oauth_token_secret'] = getOAuthTokenSecret();
             $savedata['uid'] = $userInfo['uid'];
             $savedata['type'] = 'location';
             $savedata = array_merge($savedata, $data);
             D('')->table(C('DB_PREFIX') . 'login')->add($savedata);
         }
         $rtnData['is_admin'] = isAdmin($rtnData['uid']);
         $rtnData = array_merge($rtnData, $data);
         file_put_contents('/tmp/test.log', json_encode($rtnData) . "\n\r", FILE_APPEND);
     }
     $msg = $userInfo ? 'ok' : '帐号异常,请找回密码!';
     file_put_contents('/tmp/test.log', $msg . "\n\r", FILE_APPEND);
     $code = $userInfo ? 1 : 0;
     file_put_contents('/tmp/test.log', json_encode($this->returnData($rtnData, $msg, $code)) . "\n\r", FILE_APPEND);
     return $this->returnData($rtnData, $msg, $code);
 }
Ejemplo n.º 20
0
 private function _register($type, &$result)
 {
     if (!isset(self::$validLogin[$type])) {
         $result['status'] = 0;
         $result['info'] = '参数错误';
         return;
     }
     if (!model('Register')->isValidEmail($email)) {
         $result['status'] = 0;
         $result['info'] = model('Register')->getLastError();
         return;
     }
     if (!model('Register')->isValidPassword($password, $repassword)) {
         $result['status'] = 0;
         $result['info'] = model('Register')->getLastError();
         return;
     }
     // if (! isLegalUsername ( t ( $_POST ['uname'] ) )) {
     //     $result ['status'] = 0;
     //     $result ['info'] = "昵称格式不正确";
     //     return;
     // }
     // $haveName = D ( 'User' )->where ( "`uname`='" . t ( $_POST ['uname'] ) . "'" )->find ();
     // if (is_array ( $haveName ) && sizeof ( $haveName ) > 0) {
     //     $result ['status'] = 0;
     //     $result ['info'] = "昵称已被使用";
     //     return;
     // }
     $type = $_POST['type'];
     $this->_loadTypeLogin($type);
     $platform = new $type();
     $userinfo = $platform->userInfo();
     // 检查是否成功获取用户信息
     if (empty($userinfo['id']) || empty($userinfo['uname'])) {
         $result['status'] = 0;
         $result['jumpUrl'] = SITE_URL;
         $result['info'] = '获取用户信息失败';
         return;
     }
     // 初使化用户信息, 激活帐号
     $data['uname'] = t($_POST['uname']) ? t($_POST['uname']) : $userinfo['uname'];
     $data['email'] = t($_POST['email']);
     $data['login'] = t($_POST['email']);
     $data['sex'] = intval($userinfo['sex']);
     $data['reg_ip'] = get_client_ip();
     $data['ctime'] = time();
     $data['login_salt'] = rand(11111, 99999);
     $data['password'] = md5(md5($_POST['passwd']) . $data['login_salt']);
     $data['location'] = t($_POST['city_names']);
     $cityIds = t($_POST['city_ids']);
     $cityIds = explode(',', $cityIds);
     isset($cityIds[0]) && ($data['province'] = intval($cityIds[0]));
     isset($cityIds[1]) && ($data['city'] = intval($cityIds[1]));
     isset($cityIds[2]) && ($data['area'] = intval($cityIds[2]));
     // 审核状态: 0-需要审核;1-通过审核
     $regInfo = model('Xdata')->get('admin_Config:register');
     $data['is_audit'] = $regInfo['register_audit'] ? 0 : 1;
     $data['first_letter'] = getFirstLetter($data['uname']);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $data['uname'])) {
         //昵称和呢称拼音保存到搜索字段
         $data['search_key'] = $data['uname'] . ' ' . model('PinYin')->Pinyin($data['uname']);
     } else {
         $data['search_key'] = $data['uname'];
     }
     if ($id = D('user')->add($data)) {
         // 记录至同步登录表
         $syncdata['uid'] = $id;
         $syncdata['type_uid'] = $userinfo['id'];
         $syncdata['type'] = $type;
         $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token'];
         $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret'];
         D('login')->add($syncdata);
         // 转换头像
         //if ($_POST ['type'] != 'qq' || $_POST['type'] !='qzone') { // 暂且不转换QQ头像: QQ头像的转换很慢, 且会拖慢apache
         //  D ( 'Avatar' )->saveAvatar ( $id, $userinfo ['userface'] );
         //}
         $res = model('Passport')->loginLocalWithoutPassword($data['uname'], true);
         $this->registerRelation($id);
     } else {
         $result['status'] = 0;
         $result['info'] = '同步帐号发生错误';
         return false;
     }
 }
Ejemplo n.º 21
0
 public function formatByFirstLetter($uids)
 {
     $peoplelist = array('A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
     $list = array();
     foreach ($uids as $k => $v) {
         $user_info = $this->getUserInfos(array($v));
         $list[$k] = $user_info[0];
         $first_letter = getFirstLetter($list[$k]['uname']);
         switch ($first_letter) {
             case 'A':
                 $peoplelist['A'][] = $list[$k];
                 break;
             case 'B':
                 $peoplelist['B'][] = $list[$k];
                 break;
             case 'C':
                 $peoplelist['C'][] = $list[$k];
                 break;
             case 'D':
                 $peoplelist['D'][] = $list[$k];
                 break;
             case 'E':
                 $peoplelist['E'][] = $list[$k];
                 break;
             case 'F':
                 $peoplelist['F'][] = $list[$k];
                 break;
             case 'G':
                 $peoplelist['G'][] = $list[$k];
                 break;
             case 'H':
                 $peoplelist['H'][] = $list[$k];
                 break;
             case 'I':
                 $peoplelist['I'][] = $list[$k];
                 break;
             case 'J':
                 $peoplelist['J'][] = $list[$k];
                 break;
             case 'K':
                 $peoplelist['K'][] = $list[$k];
                 break;
             case 'L':
                 $peoplelist['L'][] = $list[$k];
                 break;
             case 'M':
                 $peoplelist['M'][] = $list[$k];
                 break;
             case 'N':
                 $peoplelist['N'][] = $list[$k];
                 break;
             case 'O':
                 $peoplelist['O'][] = $list[$k];
                 break;
             case 'P':
                 $peoplelist['P'][] = $list[$k];
                 break;
             case 'Q':
                 $peoplelist['Q'][] = $list[$k];
                 break;
             case 'R':
                 $peoplelist['R'][] = $list[$k];
                 break;
             case 'S':
                 $peoplelist['S'][] = $list[$k];
                 break;
             case 'T':
                 $peoplelist['T'][] = $list[$k];
                 break;
             case 'U':
                 $peoplelist['U'][] = $list[$k];
                 break;
             case 'V':
                 $peoplelist['V'][] = $list[$k];
                 break;
             case 'W':
                 $peoplelist['W'][] = $list[$k];
                 break;
             case 'X':
                 $peoplelist['X'][] = $list[$k];
                 break;
             case 'Y':
                 $peoplelist['Y'][] = $list[$k];
                 break;
             case 'Z':
                 $peoplelist['Z'][] = $list[$k];
                 break;
         }
         unset($first_letter);
     }
     return $peoplelist;
 }
Ejemplo n.º 22
0
 public function doRegister()
 {
     $service = model('Register');
     $invite = t($_POST['invate']);
     $inviteCode = t($_POST['invate_key']);
     $email = t($_POST['email']);
     $verify = t($_POST['verify']);
     $phone = t($_POST['phone']);
     $regCode = t($_POST['regCode']);
     $uname = t($_POST['uname']);
     $sex = 1 == $_POST['sex'] ? 1 : 2;
     $password = trim($_POST['password']);
     $repassword = trim($_POST['repassword']);
     if (!$email && !$phone) {
         $re['flag'] = 0;
         $re['msg'] = '非法提交';
         echo json_encode($re);
         exit;
     }
     $email && ($email_correct = $service->isValidEmail($email));
     // $verify && $verify_correct = (md5(strtoupper($verify)) == $_SESSION['verify']);
     /* # 验证邮箱验证码是否不正确 */
     $verify and $verify_correct = model('Sms')->checkEmailCaptcha($email, $verify);
     $phone && ($phone_correct = $service->isValidPhone($phone));
     // $regCode && $regCode_correct = $service->isValidRegCode($regCode);
     /* # 验证手机验证码是否不正确 */
     $regCode and $regCode_correct = model('Sms')->CheckCaptcha($phone, $regCode);
     $uname_correct = $service->isValidName($uname);
     $password_correct = $service->isValidPassword($_POST['password'], $_POST['repassword']);
     if ($email && (!$email_correct || !$verify_correct) || $phone && (!$phone_correct && !$regCode_correct) || !$uname_correct || !$password_correct) {
         $re['flag'] = 0;
         $re['msg'] = $service->getLastError();
         $verify_correct or $re['msg'] = '验证码错误';
         echo json_encode($re);
         exit;
     }
     /*if ($user = model('Passport')->getLocalUser($email, $password)) {
     			if ($user['is_active'] == 0) {
     				//redirect(U('w3g/Public/login'), 3, '帐号尚未激活,请激活后重新登录');
     				$re['flag'] = 0;
     				$re['msg'] = '帐号尚未激活,请激活后重新登录';
     				echo json_encode($re);
     				exit;
     			}
     		}*/
     $login_salt = rand(11111, 99999);
     $map['uname'] = $uname;
     $map['sex'] = $sex;
     $map['login_salt'] = $login_salt;
     $map['password'] = md5(md5($password) . $login_salt);
     $email and $map['email'] = $email;
     $phone and $map['phone'] = $phone;
     $map['reg_ip'] = get_client_ip();
     $map['ctime'] = time();
     $map['first_letter'] = getFirstLetter($uname);
     $map['is_init'] = 1;
     $openid = session('openid');
     empty($openid) || ($map['openid'] = $openid);
     // 审核状态: 0-需要审核;1-通过审核
     $map['is_audit'] = $this->_config['register_audit'] ? 0 : 1;
     // 需求添加 - 若后台没有填写邮件配置,将直接过滤掉激活操作
     $isActive = $this->_config['need_active'] ? 0 : 1;
     if ($isActive == 0) {
         $emailConf = model('Xdata')->get('admin_Config:email');
         if (empty($emailConf['email_host']) || empty($emailConf['email_account']) || empty($emailConf['email_password'])) {
             $isActive = 1;
         }
     }
     //当手机注册时,直接过滤掉激活操作
     //$phone && $isActive = 1;
     //直接激活
     $isActive = 1;
     $map['is_active'] = $isActive;
     //$map['first_letter'] = getFirstLetter($uname);
     //如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //昵称和呢称拼音保存到搜索字段
         $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
     } else {
         $map['search_key'] = $map['uname'];
     }
     $uid = $this->_user_model->add($map);
     // dump($uid);
     if ($uid) {
         // 添加积分
         model('Credit')->setUserCredit($uid, 'init_default');
         // 如果是邀请注册,则邀请码失效
         if ($invite) {
             // 验证码使用
             $receiverInfo = model('User')->getUserInfo($uid);
             // 添加用户邀请码字段
             model('Invite')->setInviteCodeUsed($inviteCode, $receiverInfo);
             //给邀请人奖励
             model('User')->where('uid=' . $uid)->setField('invite_code', $inviteCode);
         }
         // 添加至默认的用户组
         $userGroup = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($userGroup['default_user_group']) ? C('DEFAULT_GROUP_ID') : $userGroup['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         //注册来源-第三方帐号绑定
         if (isset($_POST['other_type'])) {
             $other['type'] = t($_POST['other_type']);
             $other['type_uid'] = t($_POST['other_uid']);
             $other['oauth_token'] = t($_POST['oauth_token']);
             $other['oauth_token_secret'] = t($_POST['oauth_token_secret']);
             $other['uid'] = $uid;
             D('login')->add($other);
         }
         //判断是否需要审核
         if ($this->_config['register_audit']) {
             //$this->redirect('w3g/Register/waitForAudit', array('uid' => $uid));
             $re['flag'] = 0;
             $re['msg'] = '注册成功,等待审核';
             echo json_encode($re);
             exit;
         } else {
             if (!$isActive) {
                 $this->_register_model->sendActivationEmail($uid);
                 //$this->redirect('w3g/Register/waitForActivation', array('uid' => $uid));
                 $re['flag'] = 0;
                 $re['msg'] = '注册成功,等待激活';
                 echo json_encode($re);
                 exit;
             } else {
                 $email = $email ? $email : $phone;
                 //自动登录帐号
                 D('Passport')->loginLocal($email, $password);
                 $re['flag'] = 1;
                 $re['msg'] = '注册成功';
                 echo json_encode($re);
                 exit;
             }
         }
     } else {
         // $this->error(L('PUBLIC_REGISTER_FAIL'));			// 注册失败
         // echo '0';
         $re['flag'] = 0;
         $re['msg'] = '注册失败';
         echo json_encode($re);
         exit;
     }
 }
Ejemplo n.º 23
0
     $p = 1;
     echo '<script>window.location.href="' . getJumpUrl($t, $p) . '";</script>';
     exit;
 } else {
     $data = array();
     foreach ($user_list as &$value) {
         if (empty($value['email'])) {
             $value['email'] = 'ts_' . $value['uid'] . '@thinksns.com';
         }
         $salt = rand(11111, 99999);
         $salt = mysql_escape_string($salt);
         $password = md5($value['password'] . $salt);
         $password = mysql_escape_string($password);
         $sex = $value['sex'] == 1 ? 1 : 2;
         $sex = mysql_escape_string($sex);
         $first_letter = getFirstLetter($value['uname']);
         $first_letter = mysql_escape_string($first_letter);
         $search_key = $value['uname'] . ' ' . $Py->Pinyin($value['uname']);
         $search_key = mysql_escape_string($search_key);
         $value = updateValue($value);
         $data[] = "('" . $value['uid'] . "','" . $value['email'] . "','" . $password . "','" . $salt . "','" . $value['uname'] . "','" . $value['email'] . "','" . $sex . "','" . $value['location'] . "','1','" . $value['is_active'] . "','" . $value['is_init'] . "','" . $value['ctime'] . "','1',null,'" . $value['domain'] . "','" . $value['province'] . "','" . $value['city'] . "','0', '127.0.0.1', 'zh-cn', 'PRC', '0', '" . $first_letter . "', '', null, null, '0', '" . $search_key . "', null, 0, 0)";
         // 添加用户组信息 - todo
         $user_group_link_sql = 'SELECT * FROM `' . $old_db_conf['DB_PREFIX'] . 'user_group_link` WHERE `uid` = ' . $value['uid'] . ' LIMIT 1';
         $user_group_info = $old_db->query($user_group_link_sql);
         // 获取管理用户组
         $admin_group_sql = 'SELECT p.* FROM `' . $old_db_conf['DB_PREFIX'] . 'user_group_popedom` AS p LEFT JOIN `' . $old_db_conf['DB_PREFIX'] . 'node` AS n ON p.`node_id` = n.`node_id` WHERE n.`app_name` = \'admin\' AND n.`mod_name` = \'*\' AND n.`act_name` = \'*\'';
         $admin_group_info = $old_db->query($admin_group_sql);
         if (empty($user_group_info) || $user_group_info[0]['user_group_id'] != $admin_group_info[0]['user_group_id']) {
             $user_group_data[] = "(null, '" . $value['uid'] . "', '3')";
         } else {
             if ($user_group_info[0]['user_group_id'] == $admin_group_info[0]['user_group_id']) {
Ejemplo n.º 24
0
 /**
  * UC登录或者注册
  * @param string $username
  * @param string $password
  * @param string $is_remember_me 是否记住登录
  * @return bool 
  */
 private function ucLogin($username, $password, $is_remember_me)
 {
     //载入UC客户端SDK
     include_once SITE_PATH . '/api/uc_client/client.php';
     //1. 获取UC信息.
     if ($this->isValidEmail($username)) {
         $use_email = true;
         $uc_login_type = 2;
     } else {
         $use_email = false;
         $uc_login_type = 0;
     }
     $uc_user = uc_user_login($username, $password, $uc_login_type);
     //2. 已经同步过的直接登录
     $uc_user_ref = ts_get_ucenter_user_ref('', $uc_user['0'], '');
     if ($uc_user_ref['uid'] && $uc_user_ref['uc_uid'] && $uc_user[0] > 0) {
         //登录本地帐号
         $result = $uc_user_ref['uid'] > 0 ? $this->_recordLogin($uc_user_ref['uid'], $is_remember_me) : false;
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //3. 关联表无、获取本地帐号信息.
     $ts_user = $this->getLocalUser($username, $password);
     // 调试用-写log
     // $log_message = "============================ \n "
     // 				.date('Y-m-d H:i:s')." \n ".$_SERVER['REQUEST_URI']." \n "
     // 				.var_export($uc_user,true)." \n "
     // 				.var_export($ts_user,true)." \n "
     // 				.var_export($uc_user_ref,true)." \n ";
     // $log_file = SITE_PATH."/ts_uc_log.txt";
     // $result = error_log($log_message,3,$log_file);
     //4. 关联表无、UC有、本地有的
     if ($uc_user[0] > 0 && $ts_user['uid'] > 0) {
         $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_user[0], $uc_user[1], $uc_user[3]);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_user['uid'], $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //5. 关联表无、UC有、本地无的
     if ($uc_user[0] > 0 && !$ts_user['uid']) {
         //写入本地系统
         $login_salt = rand(11111, 99999);
         $map['uname'] = $uc_user[1];
         $map['sex'] = 1;
         $map['login_salt'] = $login_salt;
         $map['password'] = md5(md5($uc_user[2]) . $login_salt);
         $map['login'] = $map['email'] = $uc_user[3];
         $map['reg_ip'] = get_client_ip();
         $map['ctime'] = time();
         $map['is_audit'] = 1;
         $map['is_active'] = 1;
         $map['first_letter'] = getFirstLetter($uname);
         //如果包含中文将中文翻译成拼音
         if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
             //昵称和呢称拼音保存到搜索字段
             $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
         } else {
             $map['search_key'] = $map['uname'];
         }
         $ts_uid = model('User')->add($map);
         if (!$ts_uid) {
             $this->error = '本地用户注册失败,请联系管理员';
             return false;
         }
         //写入关联表
         $result = ts_add_ucenter_user_ref($ts_uid, $uc_user[0], $uc_user[1], $uc_user[3]);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         // 添加至默认的用户组
         $registerConfig = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($ts_uid, implode(',', $userGroup));
         // 添加双向关注用户
         $eachFollow = $registerConfig['each_follow'];
         if (!empty($eachFollow)) {
             model('Follow')->eachDoFollow($ts_uid, $eachFollow);
         }
         // 添加默认关注用户
         $defaultFollow = $registerConfig['default_follow'];
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow));
         if (!empty($defaultFollow)) {
             model('Follow')->bulkDoFollow($ts_uid, $defaultFollow);
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_uid, $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //6. 关联表无、UC无、本地有
     if ($uc_user[0] < 0 && $ts_user['uid'] > 0) {
         //写入UC
         $uc_uid = uc_user_register($ts_user['uname'], $password, $ts_user['email'], '', '', get_client_ip());
         if ($uc_uid > 0) {
             $this->error = 'UC帐号注册失败,请联系管理员';
             return false;
         }
         //写入关联表
         $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_uid, $ts_user['uname'], $ts_user['email']);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_user['uid'], $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_uid);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //7. 关联表无、UC无、本地无的
     $this->error = '用户不存在';
     return false;
 }
Ejemplo n.º 25
0
function pinyin($zh)
{
    $ret = "";
    $s1 = iconv("UTF-8", "gb2312", $zh);
    $s2 = iconv("gb2312", "UTF-8", $s1);
    if ($s2 == $zh) {
        $zh = $s1;
    }
    for ($i = 0; $i < strlen($zh); $i++) {
        $s1 = substr($zh, $i, 1);
        $p = ord($s1);
        if ($p > 160) {
            $s2 = substr($zh, $i++, 2);
            $ret .= getFirstLetter($s2);
        } else {
            $ret .= $s1;
        }
    }
    return $ret;
}
Ejemplo n.º 26
0
 /**
  * 添加用户
  * 
  * @param array|object $user
  *        	新用户的相关信息|新用户对象
  * @return boolean 是否添加成功
  */
 public function addUser($user)
 {
     // 验证用户名称是否重复
     $map['uname'] = t($user['uname']);
     $isExist = $this->where($map)->count();
     if ($isExist > 0) {
         $this->error = '用户昵称已存在,请使用其他昵称';
         return false;
     }
     if (is_object($user)) {
         $salt = rand(11111, 99999);
         $user->login_salt = $salt;
         $user->login = $user->email;
         $user->ctime = time();
         $user->reg_ip = get_client_ip();
         $user->password = $this->encryptPassword($user->password, $salt);
     } else {
         if (is_array($user)) {
             $salt = rand(11111, 99999);
             $user['login_salt'] = $salt;
             $user['login'] = $user['email'];
             $user['ctime'] = time();
             $user['reg_ip'] = get_client_ip();
             $user['password'] = $this->encryptPassword($user['password'], $salt);
         }
     }
     // 添加昵称拼音索引
     $user['first_letter'] = getFirstLetter($user['uname']);
     // 如果包含中文将中文翻译成拼音
     if (preg_match('/[\\x7f-\\xff]+/', $user['uname'])) {
         // 昵称和呢称拼音保存到搜索字段
         $user['search_key'] = $user['uname'] . ' ' . model('PinYin')->Pinyin($user['uname']);
     } else {
         $user['search_key'] = $user['uname'];
     }
     // 添加用户操作
     $result = $this->add($user);
     if (!$result) {
         $this->error = L('PUBLIC_ADD_USER_FAIL');
         // 添加用户失败
         return false;
     } else {
         // 添加部门关联信息
         model('Department')->updateUserDepartById($result, intval($_POST['department_id']));
         // 添加用户组关联信息
         if (!empty($_POST['user_group'])) {
             model('UserGroupLink')->domoveUsergroup($result, implode(',', $_POST['user_group']));
         }
         // 添加用户职业关联信息
         if (!empty($_POST['user_category'])) {
             model('UserCategory')->updateRelateUser($result, $_POST['user_category']);
         }
         return true;
     }
 }
Ejemplo n.º 27
0
 public function getAreaByLetter()
 {
     $area = array('热门城市' => array(), 'A' => array(), 'B' => array(), 'C' => array(), 'D' => array(), 'E' => array(), 'F' => array(), 'G' => array(), 'H' => array(), 'I' => array(), 'J' => array(), 'K' => array(), 'L' => array(), 'M' => array(), 'N' => array(), 'O' => array(), 'P' => array(), 'Q' => array(), 'R' => array(), 'S' => array(), 'T' => array(), 'U' => array(), 'V' => array(), 'W' => array(), 'X' => array(), 'Y' => array(), 'Z' => array());
     $hot_areas = model('Xdata')->get('admin:globalarea');
     //热门城市
     foreach ($hot_areas as $k => $v) {
         $hot_areas[$k]['id'] = $v['area_id'];
         $hot_areas[$k]['pid'] = model('Area')->where('area_id=' . $v['area_id'])->getField('pid');
     }
     $area['热门城市'] = $hot_areas;
     $category = model('CategoryTree')->setTable('area')->getNetworkList();
     foreach ($category as $key => $value) {
         if ($value['child']) {
             foreach ($value['child'] as $k => $v) {
                 $first_letter = getFirstLetter($v['title']);
                 switch ($first_letter) {
                     case 'A':
                         $area['A'][$v['id']] = $v;
                         break;
                     case 'B':
                         $area['B'][$v['id']] = $v;
                         break;
                     case 'C':
                         $area['C'][$v['id']] = $v;
                         break;
                     case 'D':
                         $area['D'][$v['id']] = $v;
                         break;
                     case 'E':
                         $area['E'][$v['id']] = $v;
                         break;
                     case 'F':
                         $area['F'][$v['id']] = $v;
                         break;
                     case 'G':
                         $area['G'][$v['id']] = $v;
                         break;
                     case 'H':
                         $area['H'][$v['id']] = $v;
                         break;
                     case 'I':
                         $area['I'][$v['id']] = $v;
                         break;
                     case 'J':
                         $area['J'][$v['id']] = $v;
                         break;
                     case 'K':
                         $area['K'][$v['id']] = $v;
                         break;
                     case 'L':
                         $area['L'][$v['id']] = $v;
                         break;
                     case 'M':
                         $area['M'][$v['id']] = $v;
                         break;
                     case 'N':
                         $area['N'][$v['id']] = $v;
                         break;
                     case 'O':
                         $area['O'][$v['id']] = $v;
                         break;
                     case 'P':
                         $area['P'][$v['id']] = $v;
                         break;
                     case 'Q':
                         $area['Q'][$v['id']] = $v;
                         break;
                     case 'R':
                         $area['R'][$v['id']] = $v;
                         break;
                     case 'S':
                         $area['S'][$v['id']] = $v;
                         break;
                     case 'T':
                         $area['T'][$v['id']] = $v;
                         break;
                     case 'U':
                         $area['U'][$v['id']] = $v;
                         break;
                     case 'V':
                         $area['V'][$v['id']] = $v;
                         break;
                     case 'W':
                         $area['W'][$v['id']] = $v;
                         break;
                     case 'X':
                         $area['X'][$v['id']] = $v;
                         break;
                     case 'Y':
                         $area['Y'][$v['id']] = $v;
                         break;
                     case 'Z':
                         $area['Z'][$v['id']] = $v;
                         break;
                 }
                 unset($first_letter);
             }
         }
     }
     return $area;
 }
Ejemplo n.º 28
0
 /**
  * 更新用户信息
  */
 public function doUpdateUser()
 {
     $uid = intval($_POST['uid']);
     $user = model('User');
     // 验证用户名称是否重复
     $oldUname = $user->where('uid=' . $uid)->getField('uname');
     $vmap['uname'] = t($_POST['uname']);
     if ($oldUname != $vmap['uname']) {
         $isExist = $user->where($vmap)->count();
         if ($isExist > 0) {
             $this->error('用户昵称已存在,请使用其他昵称');
             return false;
         }
     }
     $map = $user->create();
     $map['login'] = t($_POST['email']);
     unset($map['password']);
     // 生成新密码
     if (isset($_POST['password']) && !empty($_POST['password'])) {
         $map['login_salt'] = rand(11111, 99999);
         $map['password'] = md5(md5($_POST['password']) . $map['login_salt']);
     }
     $map['first_letter'] = getFirstLetter($map['uname']);
     // 检查map返回值,有表单验证
     $result = $user->where("uid=" . $uid)->save($map);
     if (count($_POST['user_group']) == 0) {
         $this->error('用户组不能为空');
     }
     $r = model('UserGroupLink')->domoveUsergroup($uid, implode(',', $_POST['user_group']));
     // 更改部门
     /*		
     		if(!empty($_POST['department_id'])){
     			model('Department')->updateUserDepartById($uid,intval($_POST['department_id']));	
     		}*/
     //更改职业信息
     model('UserCategory')->updateRelateUser($uid, $_POST['user_category']);
     if ($result || $r) {
         model('User')->cleanCache($uid);
         // 清除权限缓存
         model('Cache')->rm('perm_user_' . $uid);
         // 保存用户组的信息
         $this->assign('jumpUrl', U('admin/User/editUser', array('uid' => $uid, 'tabHash' => 'editUser')));
         $this->success(L('PUBLIC_SYSTEM_MODIFY_SUCCESS'));
     } else {
         $this->error(L('PUBLIC_ADMIN_OPRETING_ERROR'));
     }
 }
Ejemplo n.º 29
0
 /**
  * 绑定第三方帐号,生成新账号 --using
  * @author <*****@*****.**>
  * @param varchar uname 用户名
  * @param varchar password 密码
  * @param varchar type 帐号类型
  * @param varchar type_uid 第三方用户标识
  * @param varchar access_token 第三方access token
  * @param varchar refresh_token 第三方refresh token(选填,根据第三方返回值)
  * @param varchar expire_in 过期时间(选填,根据第三方返回值)
  *
  * @return array('status' => , 'msg' => )
  */
 public function bind_new_user2()
 {
     $uname = t($this->data['uname']);
     $password = t($this->data['password']);
     //用户名验证
     if (!model('Register')->isValidName($uname)) {
         $msg = model('Register')->getLastError();
         $return = array('status' => 0, 'msg' => $msg);
         return $return;
     }
     //密码验证
     if (!model('Register')->isValidPasswordNoRepeat($password)) {
         $msg = model('Register')->getLastError();
         $return = array('status' => 0, 'msg' => $msg);
         return $return;
     }
     //数据中心开始注册
     $access_token = $this->getCenterToken();
     $sRurl = C('APIURL') . '/v1/user/register?access_token=' . $access_token;
     $rCont = array('mobile' => $phone, 'password' => $password, 'reg_channel' => 'ts', 'reg_ip' => get_client_ip(), 'username' => $uname, 'gender' => $sex);
     $sCenstatus = request_post($sRurl, $rCont);
     $rRes = json_decode($sCenstatus, true);
     if ($rRes['code'] !== 0) {
         $return = array('status' => 0, 'msg' => '注册失败');
         return $return;
     }
     $map['cyj_id'] = $rRes['data']['ret']['open_id'];
     $map['password'] = $rRes['data']['ret']['password'];
     $map['login_salt'] = $rRes['data']['ret']['password_salt'];
     //$login_salt = rand(111111, 999999);
     $map['uname'] = $uname;
     //$map['login_salt'] = $login_salt;
     //$map['password'] = md5(md5($password).$login_salt);
     // $map['login'] = $uname; // # 该字段为手机号,有用户名方式和email登陆!
     $map['ctime'] = time();
     $registerConfig = model('Xdata')->get('admin_Config:register');
     $map['is_audit'] = $registerConfig['register_audit'] ? 0 : 1;
     $map['is_active'] = 1;
     //手机端不需要激活
     $map['is_init'] = 1;
     //手机端不需要初始化步骤
     $map['first_letter'] = getFirstLetter($uname);
     if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
         //如果包含中文将中文翻译成拼音
         $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
     } else {
         $map['search_key'] = $map['uname'];
     }
     $uid = model('User')->add($map);
     if ($uid) {
         //第三方登录数据写入
         $other['oauth_token'] = addslashes($this->data['access_token']);
         $other['oauth_token_secret'] = addslashes($this->data['refresh_token']);
         $other['type'] = addslashes($this->data['type']);
         $other['type_uid'] = addslashes($this->data['type_uid']);
         $other['uid'] = $uid;
         M('login')->add($other);
         $data['oauth_token'] = getOAuthToken($uid);
         $data['oauth_token_secret'] = getOAuthTokenSecret();
         $data['uid'] = $uid;
         $savedata['type'] = 'location';
         $savedata = array_merge($savedata, $data);
         $result = M('login')->add($savedata);
         // 添加至默认的用户组
         $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup));
         // 添加双向关注用户
         $eachFollow = $registerConfig['each_follow'];
         if (!empty($eachFollow)) {
             model('Follow')->eachDoFollow($uid, $eachFollow);
         }
         // 添加默认关注用户
         $defaultFollow = $registerConfig['default_follow'];
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow));
         if (!empty($defaultFollow)) {
             model('Follow')->bulkDoFollow($uid, $defaultFollow);
         }
         if ($map['is_audit'] == 1) {
             return $data;
         } else {
             $return = array('status' => 1, 'msg' => '注册成功,请等待审核', 'need_audit' => 1);
         }
     } else {
         return array('status' => 0, 'msg' => '注册失败');
     }
 }