예제 #1
0
 public function ResetPassWordAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $account = strtolower($request->get("account"));
     $password = $request->get("password");
     $result = array("success" => true, "message" => "");
     $user = $this->get('security.context')->getToken()->getUser();
     try {
         $u_staff = new Staff($da, $da_im, $account, $this->get('logger'), $this->container);
         $targetStaffInfo = $u_staff->getInfo();
         $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $this->get('security.encoder_factory'));
         if ($re) {
             //$this->get("logger")->err("sendImPresence:".$targetStaffInfo["fafa_jid"]);
             //给自己发送一个staff-changepasswod的出席,通知在线客户端密码发生修改,需要新密码重新登录
             Utils::sendImPresence($user->fafa_jid, $targetStaffInfo["fafa_jid"], "staff-changepasswod", "staff-changepasswod", $this->container, "", "", false, Utils::$systemmessage_code);
             //记录用户操作日志
             $syslog = new \Justsy\AdminAppBundle\Controller\SysLogController();
             $syslog->setContainer($this->container);
             $desc = "重置了用户账号:" . $account . "登录密码!";
             $syslog->AddSysLog($desc, "重置密码");
         } else {
             $result = array("success" => false, "message" => "修改密码错误!");
         }
     } catch (\Exception $e) {
         $this->get("logger")->err($e->getMessage());
         $result = array("success" => false, "message" => "修改密码错误!");
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
예제 #2
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;
 }
예제 #3
0
 public function updatepasswordAction()
 {
     //判断请求域。是wefafa或子域则不验证授权令牌
     $isWeFaFaDomain = $this->checkWWWDomain();
     $res = $this->get("request");
     $da = $this->get("we_data_access");
     $opneid = $res->get("staff");
     $newpass = $res->get("newpass");
     $factory = $this->get('security.encoder_factory');
     $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get("we_data_access_im"), $opneid);
     $staffMgr->changepassword($opneid, $newpass, $factory);
     $re = array();
     $re["returncode"] = "0000";
     $response = new Response($res->get('jsoncallback') ? $res->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
예제 #4
0
 public function executeAction()
 {
     $request = $this->getRequest();
     $login_account = $request->get("login_account");
     $fafa_jid = $request->get("fafa_jid");
     $type = $request->get("type");
     $password = $request->get("password");
     $my_jid = $this->get('security.context')->getToken()->getUser()->fafa_jid;
     $result = array();
     $send_status = false;
     $msg = "";
     //修改密码
     if ($type == "adminLock") {
         $da = $this->get('we_data_access');
         $da_im = $this->get('we_data_access_im');
         $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'));
         $targetStaffInfo = $u_staff->getInfo();
         $re = $u_staff->changepassword($login_account, $password, $this->get('security.encoder_factory'));
         if ($re) {
             $send_status = Utils::sendImMessage($my_jid, $fafa_jid, $type, $password, $this->container, "", "", false, Utils::$systemmessage_code, '0');
         } else {
             $msg = "密码修改失败!";
         }
     } else {
         $send_status = Utils::sendImMessage($my_jid, $fafa_jid, $type, $type, $this->container, "", "", false, Utils::$systemmessage_code, '0');
     }
     $result = array("success" => $send_status, "msg" => $msg);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
예제 #5
0
 public function resetpassAction($appid)
 {
     $request = $this->get("request");
     $pv = $request->get("pv");
     $result = array();
     $result["s"] = "0";
     if (empty($appid) || empty($pv)) {
         $result["msg"] = "参数无效!";
     } else {
         $da = $this->get('we_data_access');
         $curuser = $this->get('security.context')->getToken()->getUser();
         try {
             $sql = "select b.login_account from we_appcenter_apps a,we_staff b where a.appname=b.nick_name and a.appid=?";
             $ds = $da->GetData("t", $sql, array((string) $appid));
             if ($ds == null || count($ds["t"]["rows"]) == 0) {
                 $result["msg"] = "appid参数无效!";
             } else {
                 $u_staff = new Staff($da, $this->get('we_data_access_im'), $curuser, $this->get('logger'));
                 $u_staff->changepassword($ds["t"]["rows"][0]["login_account"], $pv, $this->get('security.encoder_factory'));
                 $result["s"] = "1";
                 $result["msg"] = $pv;
             }
         } catch (\Exception $e) {
             $result["msg"] = $e->getMessage();
         }
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
예제 #6
0
 public function register_announcer($parameter)
 {
     $nick_name = isset($parameter["name"]) ? $parameter["name"] : null;
     $state = isset($parameter["state"]) ? $parameter["state"] : "add";
     $login_account = isset($parameter["login_account"]) ? $parameter["login_account"] : null;
     $account = explode("@", $login_account);
     $ldap_uid = $account[0];
     $deptid = isset($parameter["deptid"]) ? $parameter["deptid"] : array();
     $fileid = isset($parameter["fileid"]) ? $parameter["fileid"] : null;
     $fileid = empty($fileid) ? null : $fileid;
     $password = isset($parameter["password"]) ? $parameter["password"] : null;
     $staffid = isset($parameter["staffid"]) ? $parameter["staffid"] : array();
     $user = $parameter["user"];
     $success = true;
     $msg = "";
     $da = $this->conn;
     if ($state == "add") {
         //取公众号部门id
         $departmentid = "";
         $sql = " select dept_id from we_department where fafa_deptid=?;";
         $ds = $da->GetData("table", $sql, array("v" . $user->eno . "999888"));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $departmentid = $ds["table"]["rows"][0]["dept_id"];
             $register = new \Justsy\BaseBundle\Controller\ActiveController();
             $register->setContainer($this->container);
             $register_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" => "", "duty" => "", "indefaultgroup" => "N", "mutual" => "N", "deptid" => $departmentid);
             $success = $register->doSave($register_parameter);
         }
         if ($success) {
             //向广播员添加具有的默认菜单项
             $sql = "insert into mb_staff_menu(staff_id,menu_id)values(?,'firendcircle');";
             try {
                 $da->ExecSQL($sql, array((string) $login_account));
             } catch (\Exception $e) {
             }
         }
         if (!$success) {
             $msg = "用户账号(" . $login_account . ")注册失败!";
         }
     } else {
         //用户修改了密码的操作
         if (!empty($password)) {
             $u_staff = new Staff($da, $this->conn_im, $login_account, $this->logger);
             $targetStaffInfo = $u_staff->getInfo();
             $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $this->container->get('security.encoder_factory'));
             $this->logger("-----------" . $re);
         }
     }
     if ($success) {
         $sqls = array();
         $paras = array();
         //修改头像
         $sql = "update we_staff set nick_name=?,photo_path=?,photo_path_small=?,photo_path_big=? where login_account=?;";
         $para = array((string) $nick_name, (string) $fileid, (string) $fileid, (string) $fileid, (string) $login_account);
         array_push($sqls, $sql);
         array_push($paras, $para);
         //修改im数据
         //获得fafa_jid
         $fafa_jid = "";
         $sql = "select fafa_jid from we_staff where login_account=?;";
         $ds = $da->GetData("table", $sql, array((string) $login_account));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $fafa_jid = $ds["table"]["rows"][0]["fafa_jid"];
             $sql_im = "update im_employee set employeename=?,photo=? where loginname=?;";
             $para_im = array((string) $nick_name, $fileid, (string) $fafa_jid);
             try {
                 $this->conn_im->ExecSQL($sql_im, $para_im);
             } catch (\Exception $e) {
             }
         }
         if ($state == "edit") {
             $sql = "delete from we_announcer where login_account=?;";
             $da->ExecSQL($sql, array((string) $login_account));
         }
         //部门的处理
         for ($j = 0; $j < count($deptid); $j++) {
             $sql = "insert into we_announcer(login_account,objid,`type`)values(?,?,1)";
             $para = array((string) $login_account, (string) $deptid[$j]);
             array_push($sqls, $sql);
             array_push($paras, $para);
         }
         //人员的处理
         for ($j = 0; $j < count($staffid); $j++) {
             $sql = "insert into we_announcer(login_account,objid,`type`)values(?,?,2)";
             $para = array((string) $login_account, (string) $staffid[$j]);
             array_push($sqls, $sql);
             array_push($paras, $para);
         }
         try {
             $da->ExecSQLS($sqls, $paras);
         } catch (\Exception $e) {
             $success = false;
             $msg = "更新用户信息失败!";
             $this->logger->err($e->getMessage());
         }
     }
     return array("success" => $success, "msg" => $msg);
 }
예제 #7
0
 public static function userAuthAction($container, $request, $dbcon, $con_im, $login_account, $password, $comefrom)
 {
     $login_account = strtolower($login_account);
     try {
         $password = strtoupper(md5($password));
         //$container->get("logger")->err($password);
         $staff = new Staff($dbcon, $con_im, strtolower($login_account));
         $user = $staff->getInfo();
         if ($user == null || $user["state_id"] != "1") {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             return $re;
         }
         $login_account = $user["login_account"];
         $Obj = new \Justsy\BaseBundle\Login\UserProvider($container);
         //
         $factory = $container->get('security.encoder_factory');
         //判断是否修改过密码.这时针对从第三方注册的帐号的密码为不可解开密文的情况时,sns中的密码和t_code字段临时存储为完全相同的数据
         //程序判断到这种情况 时,需要进行内部自动更改密码操作,之前的临时数据即为用户新密码
         //$container->get("logger")->err($user["password"]."==".$user["t_code"]);
         if ($user["password"] == $user["t_code"]) {
             $tmpPass = DES::encrypt($password);
             if ($tmpPass != $user["t_code"]) {
                 $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             }
             //更新密码
             $staff->changepassword($login_account, $password, $factory);
         }
         $user = new UserSession($login_account, $password, $login_account, array("ROLE_USER"));
         $encoder = $factory->getEncoder($user);
         $password_enc = $encoder->encodePassword($password, $login_account);
         $user = $Obj->loadUserByUsername($login_account, $comefrom);
         //$container->get("logger")->err($user->getPassword()."==".$password_enc);
         $logined = 1;
         if ($user->getPassword() != $password_enc) {
             //如果密码不正确时,有可能是修改了密码,只刷新了一台服务器上的缓存,其他集群环境中的还是原来的缓存
             //刷新当前服务器的人员信息才重试
             $u_staff = new Staff($dbcon, $con_im, $user->getusername(), $container->get('logger'));
             $user = $u_staff->getInfo(true);
             //刷新人员信息
             //$container->get("logger")->err("refresh cache data.....");
             $user = $Obj->loadUserByUsername($login_account, $comefrom);
             if ($user->getPassword() != $password_enc) {
                 $container->get("logger")->err($login_account . "==>" . $password . "=>" . $password_enc . "=>" . $user->getPassword());
                 $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
                 $logined = null;
             }
         }
         if (!empty($logined)) {
             //�Ǽ�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"] = $login_account;
             $re["ldap_uid"] = $user->ldap_uid;
             $re["jid"] = $user->fafa_jid;
             $re["des"] = $user->t_code;
         }
     } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
         $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
     } catch (\Exception $e) {
         $container->get("logger")->err($e);
         $re["returncode"] = ReturnCode::$SYSERROR;
     }
     return $re;
 }