예제 #1
0
 public function updateStaffAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get('we_data_access_im');
     $request = $this->getRequest();
     $state = $request->get("state");
     $im_deptid = $request->get("dept_id");
     //将im的部门id转化为sns里的部门id
     $deptInfo = $this->getDeptInfo($im_deptid);
     $sns_deptid = $deptInfo["deptid"];
     $login_account = $request->get("login_account");
     $e_mail = $request->get("e_mail");
     $nick_name = $request->get("nick_name");
     $password = $request->get("password");
     $sex = $request->get("sex");
     $duty = $request->get("duty");
     $duty = empty($duty) ? null : $duty;
     $mobile = $request->get("mobile");
     $mobile = empty($mobile) ? null : $mobile;
     $success = true;
     $msg = "";
     //判断手机号正误
     if (!empty($mobile)) {
         if (!Utils::validateMobile($mobile)) {
             $result = array("success" => false, "msg" => "手机账号格式错误!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         } else {
             $sql = "";
             $para = array();
             if ($state == "add") {
                 $sql = "select count(*) number from we_staff where mobile_bind=?;";
                 array_push($para, (string) $mobile);
             } else {
                 $sql = "select count(*) number from we_staff where mobile_bind=? and login_account!=?;";
                 array_push($para, (string) $mobile, $login_account);
             }
             try {
                 $ds = $da->GetData("table", $sql, $para);
                 if ($ds && $ds["table"]["recordcount"] > 0) {
                     if ((int) $ds["table"]["rows"][0]["number"] > 0) {
                         $result = array("success" => false, "msg" => "已存在该手机号码!");
                         $response = new Response(json_encode($result));
                         $response->headers->set('Content-Type', 'text/json');
                         return $response;
                     }
                 }
             } catch (\Exception $e) {
                 $this->get("logger")->err($e->getMessage());
             }
         }
     }
     $user = $this->get('security.context')->getToken()->getUser();
     $deptMgr = new \Justsy\BaseBundle\Management\Dept($da, $da_im, $this->container);
     $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $login_account, $this->container->get("logger"), $this->container);
     if ($state == "add") {
         if ($staffMgr->checkUser($mobile)) {
             $result = array("success" => false, "msg" => "用户账号已存在,请重新输入!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         //获得ldap_uid
         $login_array = explode("@", $login_account);
         if (count($login_array) < 2) {
             continue;
         }
         $ldap_uid = $login_array[0];
         //注册用户账号
         $register = new \Justsy\BaseBundle\Controller\ActiveController();
         $register->setContainer($this->container);
         $parameter = array("account" => $login_account, "realName" => $nick_name, "passWord" => $password, "ldap_uid" => $ldap_uid, "eno" => $user->eno, "ename" => $user->ename, "isNew" => '0', "mailtype" => "1", "import" => '1', "isSendMessage" => "N", "mobile" => $mobile, "duty" => $duty, "deptid" => $sns_deptid, "mutual" => "Y");
         $result = $register->doSave($parameter);
         if ($result["returncode"] == "0000") {
             $staffdata = $staffMgr->getInfo();
             //成功后统计人员
             $sql = "call dept_emp_stat(?)";
             $da_im->ExecSQL($sql, array((string) $staffdata["fafa_jid"]));
             //自动关注服务号
             $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
             $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
             $servicerMgr->atten_service($parameter);
             $revJids = $staffMgr->getFriendAndColleagueJid();
             Utils::sendImMessage($user->fafa_jid, implode(",", $revJids), "newstaff", json_encode($staffMgr->getinfo()), $this->container, "", "", false, Utils::$systemmessage_code);
         } else {
             $success = false;
             $msg = "添加用户账号失败:" . $result["msg"];
         }
         $result = array("success" => $success, "msg" => $msg);
         $response = new Response(json_encode($result));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     } else {
         $staffinfo = $staffMgr->getInfo();
         $deptinfo = $deptMgr->getinfo($staffinfo["dept_id"]);
         //判断是否更改了性别
         if ($sex == $staffinfo["sex_id"]) {
             $sex = null;
         }
         //判断是否更改了职务
         if ($duty == $staffinfo["duty"]) {
             $duty = null;
         }
         //判断是否更改了姓名
         if ($nick_name == $staffinfo["nick_name"]) {
             $nick_name = null;
         }
         //判断是否更新了部门
         if ($sns_deptid == $deptinfo["dept_id"]) {
             $sns_deptid = null;
         }
         //判断是否更新了手机
         if ($mobile == $staffinfo["mobile_bind"]) {
             $mobile = null;
         }
         $uResult = $staffMgr->checkAndUpdate($nick_name, $mobile, $sns_deptid, $duty, null, $sex, null, $e_mail);
         $u_staff = null;
         $factory = null;
         //判断是否修改了密码
         if (!empty($password)) {
             $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             $factory = $this->get('security.encoder_factory');
             $targetStaffInfo = $u_staff->getInfo();
             $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $factory);
             if ($re) {
                 //给自己发送一个staff-changepasswod的出席,通知在线客户端密码发生修改,需要新密码重新登录
                 Utils::sendImPresence($user->fafa_jid, $targetStaffInfo["fafa_jid"], "staff-changepasswod", "staff-changepasswod", $this->container, "", "", false, Utils::$systemmessage_code);
             }
         }
         //判断是否修改了帐号
         if ($e_mail != $login_account) {
             //判断邮件是否存在
             if (empty($u_staff)) {
                 $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             }
             if (empty($factory)) {
                 $factory = $this->get('security.encoder_factory');
             }
             $u_staff->changeLoginAccount($e_mail, $factory);
         }
         try {
             $revJids = $staffMgr->getFriendAndColleagueJid();
             if ($uResult && !empty($sns_deptid)) {
                 //部门变更时,需要通知手机端更新原部门和新部门数据
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptinfo), $this->container, "", "", false, Utils::$systemmessage_code);
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptMgr->getinfo($sns_deptid)), $this->container, "", "", false, Utils::$systemmessage_code);
                 $old_fafa_deptid = $deptinfo["fafa_deptid"];
                 $fafa_jid = $staffinfo["fafa_jid"];
                 //取消关注服务号
                 $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
                 $parameter = array("eno" => $user->eno, "deptid" => $old_fafa_deptid, "login_account" => $login_account);
                 $servicerMgr->cancel_atten($parameter);
                 //自动关注服务号
                 $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
                 $servicerMgr->atten_service($parameter);
             }
         } catch (\Exception $e) {
             $this->get("logger")->err($e->getMessage());
             $success = false;
             $msg = "修改人员信息失败!";
         }
     }
     $result = array("success" => $success, "msg" => $msg);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
예제 #2
0
 public static function userAuthAction($container, $request, $dbcon, $con_im, $login_account, $password, $comefrom)
 {
     $defaultPostURl = "http://10.100.20.27/CallCenter/ESB_InvokeService.ashx";
     $cacheobj = new Enterprise($dbcon, $container->get("logger"), $container);
     //
     $authConfig = $cacheobj->getUserAuth();
     $httpUrlConfig = $authConfig["ssoauthurl"];
     if (empty($httpUrlConfig)) {
         $httpUrlConfig = $defaultPostURl;
         $eno = "100001";
     } else {
         $ldapConfgiObject = json_decode($httpUrlConfig, true);
         $eno = $ldapConfgiObject["ENO"];
         $httpUrlConfig = $ldapConfgiObject["URL"];
     }
     try {
         $data = array();
         $data["loginName"] = $login_account;
         $data["password"] = $password;
         $data["isNeedSyn"] = false;
         $para = "ServiceName=WXSC_Account&MethodName=POST:JSON:UserAuthentication&Message=" . json_encode($data) . "&Version=1";
         $container->get("logger")->err("SOA URL:" . $httpUrlConfig . "?" . $para);
         $postresult = Utils::do_post_request($httpUrlConfig, $para);
         $container->get("logger")->err("SOA Result:" . $postresult);
         $resultObject = json_decode($postresult, true);
         if (!empty($resultObject["errcode"]) || $resultObject["isSuccess"] === false) {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             return $re;
         }
         $mbuser = $resultObject["results"];
         $fafa_account = strtolower($login_account . "@fafatime.com");
         if (count($mbuser) > 0) {
             $mbuser = $mbuser[0];
             $nickName = isset($mbuser["nickName"]) ? $mbuser["nickName"] : $mbuser["phoneNumber"];
             $staff = new Staff($dbcon, $con_im, $fafa_account);
             $staffinfo = $staff->getInfo();
             if (empty($staffinfo)) {
                 //新用户:注册 激活
                 $enInfo = $cacheobj->getInfo($eno);
                 $active = new \Justsy\BaseBundle\Controller\ActiveController();
                 $active->setContainer($container);
                 $uid = strtolower($mbuser["id"]);
                 $active->doSave(array('account' => $fafa_account, 'realName' => $nickName, 'passWord' => $password, 'eno' => $eno, 'ename' => $enInfo["ename"], 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1'));
                 $sex_id = "1";
                 $duty = isset($mbuser["userRoles"]) ? $mbuser["userRoles"] : "";
                 $ldap_uid = isset($mbuse["id"]) ? $mbuser["id"] : "";
                 $tmp = "";
                 if (!empty($duty) && count($duty) > 0) {
                     for ($i = 0; $i < count($duty); $i++) {
                         $tmp = $duty[$i]["roleName"];
                         if ($tmp == "Designer") {
                             break;
                         }
                     }
                 }
                 if ($tmp == "Designer") {
                     $duty = "造型师";
                 } else {
                     $duty = "";
                 }
                 $sql = "update we_staff set ldap_uid=?,sex_id=?,duty=? where login_account=?";
                 $params = array($uid, (string) $sex_id, $duty, $fafa_account);
                 $dbcon->ExecSQL($sql, $params);
                 if (!empty($mbuser["phoneNumber"])) {
                     $staff->checkAndUpdate(null, $mbuser["phoneNumber"], null, null);
                 }
             } else {
                 $duty = isset($mbuser["userRoles"]) ? $mbuser["userRoles"] : "";
                 $ldap_uid = isset($mbuser["id"]) ? $mbuser["id"] : "";
                 $tmp = "";
                 if (!empty($duty) && count($duty) > 0) {
                     for ($i = 0; $i < count($duty); $i++) {
                         $tmp = $duty[$i]["roleName"];
                         if ($tmp == "Designer") {
                             break;
                         }
                     }
                 }
                 if ($tmp == "Designer") {
                     $duty = "造型师";
                 } else {
                     $duty = "";
                 }
                 //更新信息
                 $staff->checkAndUpdate($nickName, $mbuser["phoneNumber"], null, $duty, $ldap_uid);
             }
             //头像
             $headUrl = $mbuser["headPortrait"];
         }
         $Obj = new \Justsy\BaseBundle\Login\UserProvider($container);
         $user = $Obj->loadUserByUsername($fafa_account, $comefrom);
         //�Ǽ�seesion
         $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($user, $user->getPassword(), "secured_area", $user->getRoles());
         $container->get("security.context")->setToken($token);
         $session = $request->getSession()->set('_security_' . 'secured_area', serialize($token));
         $event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent($request, $token);
         $container->get("event_dispatcher")->dispatch("security.interactive_login", $event);
         $re["returncode"] = ReturnCode::$SUCCESS;
         $re["openid"] = $user->openid;
         $re["login_account"] = $fafa_account;
         $re["ldap_uid"] = $user->ldap_uid;
         $re["jid"] = $user->fafa_jid;
         //为了避免用户修改密码后只刷新了所在服务器,im密码实时获取
         $sql = "select password from users where username=?";
         $iminfo = $con_im->GetData("im", $sql, array((string) $user->fafa_jid));
         $re["des"] = count($iminfo["im"]["rows"]) > 0 ? $iminfo["im"]["rows"][0]["password"] : "";
     } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
         $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
     } catch (\Exception $e) {
         $re["returncode"] = ReturnCode::$SYSERROR;
     }
     return $re;
 }
예제 #3
0
 public function staffAttrSyncAction()
 {
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $appid = trim($request->get("appid"));
     $code = trim($request->get("code"));
     $openid = trim($request->get("openid"));
     $eno = trim($request->get("eno"));
     $staffattrlist = trim($request->get("attrs"));
     if (empty($appid)) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "应用ID不能为空。"));
     }
     if (empty($code)) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "动态授权码不能为空。"));
     }
     if (empty($staffattrlist)) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "同步的人员属性不能为空。"));
     }
     $sql_app = "select appkey from we_appcenter_apps where appid=?";
     $para_app = array($appid);
     $data_app = $conn->GetData("dt", $sql_app, $para_app);
     if ($data_app == null || count($data_app["dt"]["rows"]) == 0 || empty($data_app["dt"]["rows"][0]["appkey"])) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "应用ID不正确。"));
     }
     $appkey = $data_app["dt"]["rows"][0]["appkey"];
     if (strtolower($code) != strtolower(MD5($appid . $appkey))) {
         return $this->responseJson($request, array("returncode" => ReturnCode::$SYSERROR, "msg" => "动态授权码不正确。"));
     }
     $attrObject = json_decode($staffattrlist, true);
     $nickname = isset($attrObject["NickName"]) ? $attrObject["NickName"] : null;
     $nickname = isset($attrObject["nickname"]) ? $attrObject["nickname"] : $nickname;
     $headportrait_url = isset($attrObject["HeadPortrait"]) ? $attrObject["HeadPortrait"] : null;
     $headportrait_url = isset($attrObject["headportrait"]) ? $attrObject["headportrait"] : $headportrait_url;
     $gender = isset($attrObject["Gender"]) ? $attrObject["Gender"] : null;
     $gender = isset($attrObject["gender"]) ? $attrObject["gender"] : $gender;
     $duty = isset($attrObject["Role"]) ? $attrObject["Role"] : null;
     $duty = isset($attrObject["role"]) ? $attrObject["role"] : $duty;
     $staff = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $openid);
     if (!empty($headPortrait)) {
         $staff->SaveUserHead($headportrait_url);
     }
     $staff->checkAndUpdate($nick_name, null, null, $duty, null, $gender);
 }
예제 #4
0
 public static function tokenValidate($container, $token)
 {
     $request = $container->get("request");
     $dbcon = $container->get("we_data_access");
     $con_im = $container->get("we_data_access_im");
     $rest = "/rest/validate";
     $defaultPostURl = "https://sso.avicmall.com:8443";
     $appcodeConfig = "fafa-app";
     $appkeyConfig = "DKGHwqJ5H91noPYNYm9b8EUPQSY";
     $cacheobj = new Enterprise($dbcon, $container->get("logger"), $container);
     //
     $authConfig = $cacheobj->getUserAuth();
     $httpUrlConfig = $authConfig["ssoauthurl"];
     if (empty($httpUrlConfig)) {
         $httpUrlConfig = $defaultPostURl;
         $eno = "100001";
     } else {
         $ldapConfgiObject = json_decode($httpUrlConfig, true);
         $eno = $ldapConfgiObject["ENO"];
         $httpUrlConfig = $ldapConfgiObject["URL"];
         $appcodeConfig = $ldapConfgiObject["AppCode"];
         $appkeyConfig = $ldapConfgiObject["AppKey"];
     }
     $httpUrlConfig = $httpUrlConfig . $rest;
     try {
         $reqHeader = SsoAvicAuth::getHeaders($appcodeConfig, $appkeyConfig);
         $para = array("ticketName" => "SIAMTGT", "ticketValue" => $token);
         //$container->get("logger")->err("SOA URL:".$httpUrlConfig." Body:".json_encode($para));
         $postresult = Utils::do_post_request($httpUrlConfig, json_encode($para), $reqHeader, $container->get("logger"));
         //$container->get("logger")->err("SOA Result:".$postresult);
         $resultObject = json_decode($postresult, true);
         if (!isset($resultObject["status"])) {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             $re["msg"] = "服务器异常";
             return $re;
         }
         if (!$resultObject["status"] || $resultObject["status"] == "false") {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             $re["msg"] = $resultObject["message"];
             return $re;
         }
         $usertoken = $resultObject["ticketEntry"]["ticketValue"];
         $user = $resultObject["user"];
         //用户信息
         $nickName = $user["cn"];
         //获取姓名
         $phoneNumber = $user["smart-securemobile"];
         //获取手机号
         $login_account = $user["uid"];
         $eninfo = $cacheobj->getInfo($eno);
         $domain = $eninfo["edomain"];
         $domain = strpos($domain, ".") === false ? "fafatime.com" : $domain;
         $fafa_account = strtolower($login_account . "@" . $domain);
         $staff = new Staff($dbcon, $con_im, $fafa_account);
         $staffinfo = $staff->getInfo();
         if (empty($staffinfo)) {
             $password = rand(100000, 999999);
             //新用户:注册 激活
             $enInfo = $cacheobj->getInfo($eno);
             $active = new \Justsy\BaseBundle\Controller\ActiveController();
             $active->setContainer($container);
             $uid = strtolower($login_account);
             $active->doSave(array('account' => $fafa_account, 'realName' => $nickName, 'passWord' => $password, 'eno' => $eno, 'ename' => $enInfo["ename"], 'isNew' => '0', 'mailtype' => "1", 'deptid' => "100054", 'isSendMessage' => "N", 'import' => '1'));
             $sql = "update we_staff set ldap_uid=?,mobile=?,mobile_bind=? where login_account=?";
             $params = array((string) $uid, (string) $phoneNumber, (string) $phoneNumber, (string) $fafa_account);
             $dbcon->ExecSQL($sql, $params);
         } else {
             $ldap_uid = $login_account;
             //更新信息
             if ($nickName == $staffinfo["nick_name"]) {
                 $nickName = null;
             }
             if ($phoneNumber == $staffinfo["mobile"]) {
                 $phoneNumber = null;
             }
             if (!empty($nickName) || !empty($phoneNumber)) {
                 try {
                     $staff->checkAndUpdate($nickName, $phoneNumber, null, null, $ldap_uid);
                 } catch (\Exception $e) {
                     $container->get("logger")->err($e->getMessage());
                 }
             }
         }
         $Obj = new \Justsy\BaseBundle\Login\UserProvider($container);
         $user = $Obj->loadUserByUsername($fafa_account, $comefrom);
         //�Ǽ�seesion
         $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($user, $user->getPassword(), "secured_area", $user->getRoles());
         $container->get("security.context")->setToken($token);
         $session = $request->getSession()->set('_security_' . 'secured_area', serialize($token));
         $event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent($request, $token);
         $container->get("event_dispatcher")->dispatch("security.interactive_login", $event);
         $re["returncode"] = ReturnCode::$SUCCESS;
         $re["openid"] = $user->openid;
         $re["login_account"] = $fafa_account;
         $re["ldap_uid"] = $user->ldap_uid;
         $re["jid"] = $user->fafa_jid;
         $re["token"] = $usertoken;
         //用户凭据
         //为了避免用户修改密码后只刷新了所在服务器,im密码实时获取
         $sql = "select password from users where username=?";
         $iminfo = $con_im->GetData("im", $sql, array((string) $user->fafa_jid));
         $re["des"] = count($iminfo["im"]["rows"]) > 0 ? $iminfo["im"]["rows"][0]["password"] : "";
     } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
         $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
     } catch (\Exception $e) {
         $re["msg"] = $e->getMessage();
         $re["returncode"] = ReturnCode::$SYSERROR;
     }
     return $re;
 }