Example #1
0
 public function sloginAction()
 {
     $p = $_REQUEST;
     $pPlatform = empty($p['platform']) ? 0 : intval(trim($p['platform']));
     $pIconurl = empty($p['iconurl']) ? '' : trim($p['iconurl']);
     $pUsid = empty($p['usid']) ? '' : trim($p['usid']);
     $pUsername = empty($p['username']) ? '' : Tool_Fnc::safe_string($p['username']);
     $pDid = empty($p['did']) ? '' : trim($p['did']);
     $tTime = time();
     if (empty($pPlatform)) {
         Tool_Fnc::ajaxMsg('请选择第三方平台');
     }
     if (!empty($pIconurl) && !Tool_Validate::url($pIconurl)) {
         Tool_Fnc::ajaxMsg('头像不是有效地址');
     }
     if (empty($pUsid) || !Tool_Validate::safe($pUsid)) {
         Tool_Fnc::app('usid 有问题');
     }
     #if(empty($pUsername) || !Tool_Validate::safe($pUsername)){Tool_Fnc::ajaxMsg('昵称有问题');}
     if (empty($pDid) || !Tool_Validate::az09($pDid)) {
         Tool_Fnc::ajaxMsg('did error');
     }
     $tMAMO = new Web_MembersaidModel();
     $tMMO = new Web_MembersModel();
     $tMAMO->begin();
     //判断是否授权过
     $tUid = 0;
     $tMARow = $tMAMO->field('id,username,iconurl,mid')->where('usid = \'' . $pUsid . '\' and platform = ' . $pPlatform)->fRow();
     if (empty($tMARow['id'])) {
         #第一次授权
         $tKey = Tool_Fnc::newrand(4);
         $tData = array('mem_img' => $pIconurl, 'mem_name' => $pUsername, 'mem_key' => $tKey);
         if (!($tUid = $tMMO->insert($tData))) {
             $tMAMO->back();
             Tool_Fnc::ajaxMsg('操作失败:001');
         }
         $tData = array('platform' => $pPlatform, 'iconurl' => $pIconurl, 'usid' => $pUsid, 'created' => $tTime, 'username' => $pUsername, 'mid' => $tUid, 'ip' => Tool_Fnc::realip());
         if (!$tMAMO->insert($tData)) {
             $tMAMO->back();
             Tool_Fnc::ajaxMsg('操作失败:002');
         }
     } else {
         $tUid = $tMARow['mid'];
         $tMRow = $tMMO->field('mem_name,mem_img')->where('id_web_members = ' . $tMARow['mid'])->fRow();
         $tMData = array();
         $tMAData = array();
         if ($tMARow['username'] == $tMRow['mem_name'] && $tMRow['mem_name'] != $pUsername) {
             #如果单独修改昵称 不予第三方同步
             $tMData = array_merge($tMData, array('mem_name' => $pUsername));
             $tMAData = array_merge($tMAData, array('username' => $pUsername));
         }
         if ($tMARow['iconurl'] == $tMRow['mem_img'] && $tMRow['mem_img'] != $pIconurl) {
             #如果单独修改头像 不予第三方同步
             $tMData = array_merge($tMData, array('mem_img' => $pIconurl));
             $tMAData = array_merge($tMAData, array('iconurl' => $pIconurl));
         }
         if (count($tMData)) {
             $tMData = array_merge($tMData, array('id_web_members' => $tMARow['mid']));
             if (!$tMMO->update($tMData)) {
                 $tMAMO->back();
                 Tool_Fnc::ajaxMsg('操作失败:003');
             }
             $tData = array('mid' => $tMARow['mid'], 'updated' => $tTime);
             $tMAData = array_merge($tMAData, $tData);
             if (!$tMAMO->update($tMAData)) {
                 $tMAMO->back();
                 Tool_Fnc::ajaxMsg('操作失败:004');
             }
         }
     }
     //did入库
     $tMDMO = new Web_MembersdidModel();
     $tMDRow = $tMDMO->field('count(0) c')->where('mid = ' . $tUid . ' and did = \'' . $pDid . '\'')->fRow();
     if (empty($tMDRow['c'])) {
         $tData = array('mid' => $tUid, 'did' => $pDid, 'created' => $tTime);
         $tMDMO->insert($tData);
     }
     $tMAMO->commit();
     $tTokenarr = $this->creattoken($tUid);
     $tISMO = new Web_IncognitosheetsModel();
     $tISMO->incognito_real($pDid, $tUid);
     Tool_Fnc::ajaxMsg("登录成功", 1, $tTokenarr);
     //登录成功返回token
 }