login.class.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of login
  7. *
  8. * @author Administrator
  9. */
  10. class login {
  11. private static $_login;
  12. public static function getInstance() {
  13. if (!self::$_login) {
  14. $c = __CLASS__;
  15. self::$_login = new $c;
  16. }
  17. return self::$_login;
  18. }
  19. private function getLoginSql($uname) {
  20. return "select user_login,(select active from public.employee ee where ee.employee_id=u.employee_id) as employee_id_active, can_visit_vgm,can_add_booking, can_add_tk_status,truck_driver,po_booking,o_final_delivery_u,ipad_view_po,can_view_doc,can_upload_doc,can_add_catalog,can_add_po,packing_list_company,is_only_vgm,contact_id_user,is_demo, ra_password as password,employee_id, contact_id, user_type, last_pwd_change, EXTRACT(DAY from (now() - last_pwd_change)) as last_pwd_change_date, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  21. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  22. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  23. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, belong_schemas, main_schemas, error_login_count, EXTRACT(EPOCH FROM (now()-COALESCE(error_login_time, now()))) as second, po_status, view_air_file_format,
  24. special_customer_event, can_edi_vgm, isf_aci_ams_station,login_version,is_kerry_shipment,can_visit_delivery,currency_group from public.ra_online_user u where lower(user_login) = '" . strtolower($uname) . "'";
  25. }
  26. public function do_login() {
  27. $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
  28. $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
  29. if (!empty($uname) || !empty($password)) {
  30. } else {
  31. $uname = common::check_input($_POST['uname']);
  32. $verifcation_code = common::check_input($_POST['verifcation_code']);
  33. //首先校验验证码
  34. if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
  35. $data = array(
  36. 'msg' => 'verifcation_error',
  37. 'data' => ''
  38. );
  39. common::echo_json_encode(400, $data);
  40. exit();
  41. }
  42. $sql = $this->getLoginSql($uname);
  43. $rs = common::excuteObjectSql($sql);
  44. if (empty($rs['belong_schemas'])) {
  45. $rs['belong_schemas'] = "public";
  46. }
  47. if (empty($rs['main_schemas'])) {
  48. $rs['main_schemas'] = "public";
  49. }
  50. if (!empty($rs)) {
  51. //验证employee是否active
  52. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  53. if (strtolower(Soure) =='topocean'){
  54. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  55. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  56. }else{
  57. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  58. }
  59. }
  60. if (strtolower(Soure) =='apex'){
  61. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  62. }
  63. $data = array(
  64. 'msg' => 'no_active',
  65. 'login_version' => $rs["login_version"],
  66. 'data' => $data
  67. );
  68. common::echo_json_encode(500, $data);
  69. $this->failedLogin($uname, 'Employee not active');
  70. exit();
  71. }
  72. //处理登录状态
  73. $userInfo = common::check_input($_COOKIE['userInfo']);
  74. $noCheckPwd = false;
  75. if (!empty($userInfo)) {
  76. $userInfoSplit = explode("_", $userInfo);
  77. if ($uname == $userInfoSplit[0]) {
  78. if ($userInfoSplit[1] == md5($rs['password'])) {
  79. $noCheckPwd = true;
  80. }
  81. }
  82. }
  83. if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
  84. $data = array(
  85. 'msg' => 'error_times',
  86. 'login_version' => $rs["login_version"],
  87. 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
  88. );
  89. common::echo_json_encode(400, $data);
  90. $this->failedLogin($uname, 'Failed login too times');
  91. exit();
  92. }
  93. if ($rs['is_online'] != 't') {
  94. if (strtolower($rs['user_type']) != "employee") {
  95. $data =array(
  96. 'msg' => 'no_online',
  97. 'login_version' => $rs["login_version"],
  98. 'data' => ''
  99. );
  100. common::echo_json_encode(500, $data);
  101. $this->failedLogin($uname, 'Online is not active');
  102. exit();
  103. }
  104. }
  105. //if ($rs['decrypt_password'] != $_POST['psw']) {
  106. if ($noCheckPwd) {
  107. }else{
  108. if ($rs['password'] != $_POST['psw']) {
  109. common::excuteUpdateSql("update public.ra_online_user set error_login_count=error_login_count+1, error_login_time=now() where lower(user_login) = '" . strtolower($uname) . "'");
  110. $data = array(
  111. 'msg' => 'password_error',
  112. 'login_version' => $rs["login_version"],
  113. 'data' => ''
  114. );
  115. common::echo_json_encode(400, $data);
  116. $this->failedLogin($uname, 'Password is wrong');
  117. exit();
  118. }
  119. }
  120. if ($rs['online_active'] != 't') {
  121. $data = array(
  122. 'msg' => 'no_active',
  123. 'login_version' => $rs["login_version"],
  124. 'data' => ''
  125. );
  126. common::echo_json_encode(500, $data);
  127. $this->failedLogin($uname, 'Online is not active');
  128. exit();
  129. }
  130. //check password length
  131. $tar = utils::checkPassword($rs['password']);
  132. if (!empty($tar)) {
  133. $data = array(
  134. 'msg' => $tar,
  135. 'login_version' => $rs["login_version"],
  136. 'data' => ''
  137. );
  138. common::echo_json_encode(500, $data);
  139. exit();
  140. }
  141. if (empty($rs['last_pwd_change'])) {
  142. $data = array(
  143. 'msg' => 'first_login',
  144. 'login_version' => $rs["login_version"],
  145. 'data' => ''
  146. );
  147. common::echo_json_encode(500, $data);
  148. exit();
  149. }
  150. //get more infor by employee_id or contact_id
  151. $sql = '';
  152. $diffdate = $rs['last_pwd_change_date'];
  153. $user_type = $rs['user_type'];
  154. //if user is customer, check company
  155. if (strtolower($user_type) == 'customer') {
  156. $company = $rs['company_name'];
  157. } else {
  158. if (!empty($rs['station']))
  159. $company = $rs['station'];
  160. }
  161. if (strtolower($uname) == 'ra.admin') {
  162. $company = 'Admin';
  163. }
  164. // get system config
  165. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_session_timeout', 'customer_session_timeout', 'password_change_alert', 'employee_password_change_cycle', 'customer_password_change_cycle')";
  166. $rs1s = common::excuteListSql($sql);
  167. foreach ($rs1s as $rs1) {
  168. if ($rs1['ra_name'] == 'employee_session_timeout')
  169. $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
  170. if ($rs1['ra_name'] == 'customer_session_timeout')
  171. $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
  172. if ($rs1['ra_name'] == 'password_change_alert')
  173. $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
  174. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  175. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  176. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  177. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  178. }
  179. $sql="select item_value from config where item='passwordChangePeriod'";
  180. $pcp = common::excuteObjectSql($sql);
  181. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  182. if (strtolower($rs['user_type']) == 'employee') {
  183. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  184. $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
  185. //如果有新配置,则采用新配置
  186. if (!empty($pcp)) {
  187. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  188. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
  189. }
  190. } else {
  191. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  192. $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
  193. //如果有新配置,则采用新配置
  194. if (!empty($pcp)) {
  195. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  196. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
  197. }
  198. }
  199. $loginName = $rs['user_login'];
  200. $email = $rs['email'];
  201. //Timeout
  202. if ($diffdate > $PASSWORD_CHANGE_CYCLE) {
  203. if(empty($email)){
  204. $data = array(
  205. 'status' => '0',
  206. 'msg' => 'login user email is empty',
  207. 'login_version' => $rs["login_version"],
  208. 'data' => ''
  209. );
  210. common::echo_json_encode(500, $data);
  211. exit();
  212. }else{
  213. //$this -> passwordExpires($loginName,$email);
  214. }
  215. }
  216. if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
  217. $login_tmp = array(
  218. 'msg' => 'today',
  219. 'uname' => $uname,
  220. 'login_version' => $rs["login_version"],
  221. 'data' => ''
  222. );
  223. } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
  224. $login_tmp = array(
  225. 'msg' => 'last',
  226. 'uname' => $uname,
  227. 'login_version' => $rs["login_version"],
  228. 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
  229. 'is_only_vgm' => $rs["is_only_vgm"]
  230. );
  231. }
  232. //insert into log table
  233. $ip = common::ip();
  234. $sql = "insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')";
  235. if (common::excuteUpdateSql($sql)) {
  236. common::excuteUpdateSql("update public.ra_online_user set Last_Login_Time = now(), error_login_count=0, error_login_time=null where lower(user_login) = '" . strtolower($uname) . "'");
  237. if (isset($login_tmp)) {
  238. common::echo_json_encode(200, $login_tmp);
  239. } else {
  240. $data = array(
  241. 'msg' => 'success',
  242. 'uname' => $uname,
  243. 'login_version' => $rs["login_version"],
  244. 'data' => '',
  245. 'is_only_vgm' => $rs["is_only_vgm"]
  246. );
  247. common::echo_json_encode(200, $data);
  248. }
  249. $online_user = $rs;
  250. $online_user['user_login'] = $uname;
  251. $online_user['company'] = $company;
  252. $online_user['password'] = "";
  253. if (!_isAdmin()) {
  254. if ($rs["is_only_vgm"] == "t") {//VGM用户写死
  255. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where url_action in ('ocean_order','password','vgm') and menu_id in ('ship','profile') order by order_by asc), ',')";
  256. $rrrs = common::excuteOneSql($sql);
  257. } else {
  258. $sql = "select array_to_string(ARRAY(select p.url_action from public.ra_online_user_permission up left join public.ra_online_user u on up.user_name = u.user_login left join public.ra_online_permission p on up.p_id = p.id where lower(u.user_login) = '" . common::check_input(strtolower($uname)) . "'), ',')";
  259. $rrrs = common::excuteOneSql($sql);
  260. if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
  261. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
  262. $rrrs = common::excuteOneSql($sql);
  263. }
  264. }
  265. $online_user['permission'] = $rrrs;
  266. }
  267. if (!empty($online_user['docdownload']))
  268. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
  269. else {
  270. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where active = true";
  271. if (strtolower($online_user['user_type']) == "customer")
  272. $sql .= " and client_display = true";
  273. $sql .= " group by display_name order by min(id)";
  274. }
  275. $online_user['view_doc_type'] = common::excuteListSql($sql);
  276. if (!empty($online_user['view_air_file_format']))
  277. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  278. else {
  279. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where active = true";
  280. if (strtolower($online_user['user_type']) == "customer")
  281. $sql .= " and client_display = true";
  282. $sql .= " group by display_name order by min(id)";
  283. }
  284. $online_user['view_air_doc_type'] = common::excuteListSql($sql);
  285. //补充aci and ams CustomerLogin station - public
  286. $ocean_station_temp = $online_user['ocean_station'];
  287. $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  288. $ocean_agent_temp = $online_user['ocean_agent'];
  289. $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  290. $_SESSION['ONLINE_USER'] = $online_user;
  291. $_SESSION['LAST_OPERATE_TIME'] = time();
  292. $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
  293. //判断是否记录密码 add
  294. if ($_POST['rememberpwd'] === 'true') {
  295. if (!$noCheckPwd) {
  296. $user_info = $uname . "_" . md5($rs['password']);
  297. setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
  298. }
  299. } else {
  300. setcookie('userInfo', '', time() - 1, "/");
  301. }
  302. if ($rs['is_super'] == "t") {
  303. $schemas_list = common::excuteListSql("select * from schemas_list");
  304. } else {
  305. $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
  306. }
  307. ///if (count($schemas_list) > 1) {
  308. foreach ($schemas_list as $sk => $sv) {
  309. if ($sv['schemas_name'] == "public") {
  310. continue;
  311. }
  312. $ttdd = common::excuteObjectSql("select contact_id_user, employee_id, contact_id, user_type, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  313. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  314. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  315. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, po_status, view_air_file_format, special_customer_event, can_edi_vgm, isf_aci_ams_station, is_kerry_shipment from " . $sv['schemas_name'] . ".ra_online_user where lower(user_login) = '" . strtolower($uname) . "'");
  316. if (empty($ttdd)) {
  317. unset($schemas_list[$sk]);
  318. continue;
  319. }
  320. if (!empty($ttdd['docdownload'])) {
  321. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
  322. } else {
  323. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
  324. if (strtolower($ttdd['user_type']) == "customer")
  325. $sql .= " and client_display = true";
  326. $sql .= " group by display_name order by min(id)";
  327. }
  328. $ttdd['view_doc_type'] = common::excuteListSql($sql);
  329. if (!empty($ttdd['view_air_file_format'])) {
  330. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  331. } else {
  332. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where active = true";
  333. if (strtolower($ttdd['user_type']) == "customer")
  334. $sql .= " and client_display = true";
  335. $sql .= " group by display_name order by min(id)";
  336. }
  337. $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
  338. //补充aci and ams CustomerLogin station - other like sfs
  339. $ocean_station_temp = $ttdd['ocean_station'];
  340. $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  341. $ocean_agent_temp = $ttdd['ocean_agent'];
  342. $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  343. $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
  344. }
  345. //}
  346. $_SESSION['schemas_list'] = $schemas_list;
  347. //不再返回登录页面,直接跳转
  348. if (isset($_GET['up'])) {
  349. if($_GET['v'] == 'new'){
  350. header("Location: main_new_version.php?action=main");
  351. }else{
  352. header("Location: main.php?action=main");
  353. }
  354. }
  355. exit();
  356. } else {
  357. $data = array(
  358. 'msg' => 'database_error',
  359. 'login_version' => $rs["login_version"],
  360. 'data' => ''
  361. );
  362. common::echo_json_encode(500, $data);
  363. exit();
  364. }
  365. } else {
  366. $data = array(
  367. 'msg' => 'no_exist',
  368. 'login_version' => $rs["login_version"],
  369. 'data' => ''
  370. );
  371. common::echo_json_encode(500, $data);
  372. exit();
  373. }
  374. }
  375. }
  376. public function check_uname(){
  377. $uname = common::check_input($_POST['uname']);
  378. $sql = $this->getLoginSql($uname);
  379. $rs = common::excuteObjectSql($sql);
  380. if (!empty($rs)) {
  381. //只是验证用户是否存在,是否激活
  382. //验证employee是否active
  383. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  384. if (strtolower(Soure) =='topocean'){
  385. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  386. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  387. }else{
  388. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  389. }
  390. }
  391. if (strtolower(Soure) =='apex'){
  392. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  393. }
  394. $data = array(
  395. 'msg' => 'no_active',
  396. );
  397. common::echo_json_encode(200, $data);
  398. exit();
  399. }
  400. if ($rs['is_online'] != 't') {
  401. if (strtolower($rs['user_type']) != "employee") {
  402. $data =array(
  403. 'msg' => 'no_online',
  404. );
  405. common::echo_json_encode(200, $data);
  406. exit();
  407. }
  408. }
  409. if ($rs['online_active'] != 't') {
  410. $data = array(
  411. 'msg' => 'no_active',
  412. );
  413. common::echo_json_encode(200, $data);
  414. exit();
  415. }
  416. //验证成功
  417. $data = array(
  418. 'msg' => 'success',
  419. );
  420. common::echo_json_encode(200, $data);
  421. exit();
  422. } else {
  423. $data = array(
  424. 'msg' => 'no_exist',
  425. );
  426. common::echo_json_encode(200, $data);
  427. exit();
  428. }
  429. }
  430. public function verifcation_code(){
  431. // 生成一个4位随机数作为验证码
  432. //$random_num = mt_rand(1000, 9999);
  433. $random_num = $this->generateCaptcha(6);
  434. $_SESSION['captcha'] = $random_num;
  435. // 创建一个宽度为80像素、高度为30像素的图片
  436. $width = 130;
  437. $height = 40;
  438. $image = imagecreate($width, $height);
  439. // 设置颜色
  440. $white = imagecolorallocate($image, 255, 255, 255); // 白色作为背景
  441. $black = imagecolorallocate($image, 0, 0, 0); // 黑色作为文字
  442. // 填充背景
  443. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  444. // 在图片上绘制四个字符
  445. $font_size = 18;
  446. $x = 14;
  447. $y = 12;
  448. for ($i = 0; $i < 6; $i++) {
  449. $char = substr($random_num, $i, 1);
  450. imagestring($image, $font_size, $x, $y, $char, $black);
  451. $x += $font_size+1;
  452. }
  453. // 返回Base64编码
  454. ob_start();
  455. imagepng($image);
  456. $image_data = ob_get_clean();
  457. // 释放内存
  458. imagedestroy($image);
  459. $data = array("imagePngBase64" =>base64_encode($image_data));
  460. common::echo_json_encode(200, $data);
  461. exit();
  462. }
  463. //邮件密码原文
  464. public function forgot_password() {
  465. $login = common::check_input($_POST['login']);
  466. $email = common::check_input($_POST['email']);
  467. $verifcation_code = common::check_input($_POST['verifcation_code']);
  468. //首先校验验证码
  469. if ($_SESSION['captcha'] != $verifcation_code) {
  470. $data = array(
  471. 'msg' => 'verifcation_error',
  472. 'data' => ''
  473. );
  474. common::echo_json_encode(500, $data);
  475. exit();
  476. }
  477. $msg = "";
  478. if (!empty($email) || !empty($login)) {
  479. $sql_p = "select User_Login, ra_password as password from public.ra_online_user where lower(user_login) = '" . strtolower($login) . "' and lower(email) = '" . strtolower($email) . "'";
  480. $rs = common::excuteObjectSql($sql_p);
  481. if (!empty($rs)) {
  482. $r = utils::sendEmailByPassword($login, $rs['password'], $email);
  483. if ($r == 'success') {
  484. $msg = "success";
  485. } else {
  486. $msg = $r;
  487. }
  488. } else {
  489. $msg = "Can not find this user with give login id and email, please confirm!";
  490. }
  491. } else {
  492. $msg = "Login Name or Email Required !";
  493. }
  494. $data = array(
  495. 'msg' => $msg,
  496. );
  497. common::echo_json_encode(200, $data);
  498. exit();
  499. }
  500. public function generateCaptcha($length = 6) {
  501. $captcha = '';
  502. for ($i = 0; $i < $length; $i++) {
  503. // 随机选择字母或数字
  504. $char = mt_rand(0, 1) ? rand(0, 9) : chr(rand(ord('A'), ord('Z')));
  505. $captcha .= strval($char);
  506. }
  507. return $captcha;
  508. }
  509. public function do_login_auto() {
  510. $uname = common::check_input($_GET['u']);
  511. $password = common::check_input($_GET['p']);
  512. $login_error_times = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Login_Error_Times'");
  513. $lock_user_seconds = common::excuteOneSql("select ra_value from ra_online_config where ra_name='Lock_User_Seconds'");
  514. if (!empty($uname) || !empty($password)) {
  515. } else {
  516. $uname = common::check_input($_POST['uname']);
  517. $sql = $this->getLoginSql($uname);
  518. $rs = common::excuteObjectSql($sql);
  519. if (empty($rs['belong_schemas'])) {
  520. $rs['belong_schemas'] = "public";
  521. }
  522. if (empty($rs['main_schemas'])) {
  523. $rs['main_schemas'] = "public";
  524. }
  525. if (!empty($rs)) {
  526. //验证employee是否active
  527. if (!empty($rs["employee_id"]) && $rs["employee_id_active"] != "t") {
  528. if (strtolower(Soure) =='topocean'){
  529. if (strtolower($rs['user_type']) == "employee" && utils::endWith($rs['email'], "cn")) {
  530. $data = "<a href='mailto:lilyyang@topocean.com.cn'>lilyyang@topocean.com.cn</a>";
  531. }else{
  532. $data = "<a href='mailto:winnie@topocean.com'>winnie@topocean.com</a>";
  533. }
  534. }
  535. if (strtolower(Soure) =='apex'){
  536. $data = "<a href='mailto:maria.wang@apexshipping.com.cn'>maria.wang@apexshipping.com.cn</a>";
  537. }
  538. $data = array(
  539. 'msg' => 'no_active',
  540. 'login_version' => $rs["login_version"],
  541. 'data' => $data
  542. );
  543. common::echo_json_encode(500, $data);
  544. $this->failedLogin($uname, 'Employee not active');
  545. exit();
  546. }
  547. //add 处理登录状态
  548. $userInfo = common::check_input($_COOKIE['userInfo']);
  549. $noCheckPwd = false;
  550. if (!empty($userInfo)) {
  551. $userInfoSplit = explode("_", $userInfo);
  552. if ($uname == $userInfoSplit[0]) {
  553. if ($userInfoSplit[1] == md5($rs['password'])) {
  554. $noCheckPwd = true;
  555. }
  556. }
  557. }
  558. //if (!$noCheckPwd) {
  559. if ($rs['error_login_count'] > $login_error_times && $rs['second'] < $lock_user_seconds) {
  560. $data = array(
  561. 'msg' => 'error_times',
  562. 'login_version' => $rs["login_version"],
  563. 'data' => ceil(($lock_user_seconds - $rs['second']) / 60)
  564. );
  565. common::echo_json_encode(500, $data);
  566. $this->failedLogin($uname, 'Failed login too times');
  567. exit();
  568. }
  569. if ($rs['is_online'] != 't') {
  570. if (strtolower($rs['user_type']) != "employee") {
  571. $data =array(
  572. 'msg' => 'no_online',
  573. 'login_version' => $rs["login_version"],
  574. 'data' => ''
  575. );
  576. common::echo_json_encode(500, $data);
  577. $this->failedLogin($uname, 'Online is not active');
  578. exit();
  579. }
  580. }
  581. //if ($rs['decrypt_password'] != $_POST['psw']) {
  582. if ($noCheckPwd) {
  583. }else{
  584. if ($rs['password'] != $_POST['psw']) {
  585. common::excuteUpdateSql("update public.ra_online_user set error_login_count=error_login_count+1, error_login_time=now() where lower(user_login) = '" . strtolower($uname) . "'");
  586. $data = array(
  587. 'msg' => 'password_error',
  588. 'login_version' => $rs["login_version"],
  589. 'data' => ''
  590. );
  591. common::echo_json_encode(500, $data);
  592. $this->failedLogin($uname, 'Password is wrong');
  593. exit();
  594. }
  595. }
  596. if ($rs['online_active'] != 't') {
  597. $data = array(
  598. 'msg' => 'no_active',
  599. 'login_version' => $rs["login_version"],
  600. 'data' => ''
  601. );
  602. common::echo_json_encode(500, $data);
  603. $this->failedLogin($uname, 'Online is not active');
  604. exit();
  605. }
  606. //check password length
  607. $tar = utils::checkPassword($rs['password']);
  608. if (!empty($tar)) {
  609. $data = array(
  610. 'msg' => $tar,
  611. 'login_version' => $rs["login_version"],
  612. 'data' => ''
  613. );
  614. common::echo_json_encode(500, $data);
  615. exit();
  616. }
  617. if (empty($rs['last_pwd_change'])) {
  618. $data = array(
  619. 'msg' => 'first_login',
  620. 'login_version' => $rs["login_version"],
  621. 'data' => ''
  622. );
  623. common::echo_json_encode(500, $data);
  624. exit();
  625. }
  626. //}
  627. //get more infor by employee_id or contact_id
  628. $sql = '';
  629. $diffdate = $rs['last_pwd_change_date'];
  630. $user_type = $rs['user_type'];
  631. //if user is customer, check company
  632. if (strtolower($user_type) == 'customer') {
  633. $company = $rs['company_name'];
  634. } else {
  635. if (!empty($rs['station']))
  636. $company = $rs['station'];
  637. }
  638. if (strtolower($uname) == 'ra.admin') {
  639. $company = 'Admin';
  640. }
  641. // get system config
  642. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_session_timeout', 'customer_session_timeout', 'password_change_alert', 'employee_password_change_cycle', 'customer_password_change_cycle')";
  643. $rs1s = common::excuteListSql($sql);
  644. foreach ($rs1s as $rs1) {
  645. if ($rs1['ra_name'] == 'employee_session_timeout')
  646. $EMPLOYEE_SESSION_TIMEOUT = $rs1['ra_value'];
  647. if ($rs1['ra_name'] == 'customer_session_timeout')
  648. $CUSTOMER_SESSION_TIMEOUT = $rs1['ra_value'];
  649. if ($rs1['ra_name'] == 'password_change_alert')
  650. $PASSWORD_CHANGE_ALERT = $rs1['ra_value'];
  651. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  652. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  653. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  654. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  655. }
  656. $sql="select item_value from config where item='passwordChangePeriod'";
  657. $pcp = common::excuteObjectSql($sql);
  658. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  659. if (strtolower($rs['user_type']) == 'employee') {
  660. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  661. $SESSION_TIMEOUT = $EMPLOYEE_SESSION_TIMEOUT;
  662. //如果有新配置,则采用新配置
  663. if (!empty($pcp)) {
  664. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  665. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Employee"]["advanceDays"];
  666. }
  667. } else {
  668. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  669. $SESSION_TIMEOUT = $CUSTOMER_SESSION_TIMEOUT;
  670. //如果有新配置,则采用新配置
  671. if (!empty($pcp)) {
  672. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  673. $PASSWORD_CHANGE_ALERT = $passwordChangePeriod["Customer"]["advanceDays"];
  674. }
  675. }
  676. /* if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
  677. echo json_encode(array(
  678. 'msg' => 'password_require_change',
  679. 'login_version' => $rs["login_version"],
  680. 'data' => ''
  681. ));
  682. $this->failedLogin($uname, 'Required password change');
  683. exit();
  684. }*/
  685. $loginName = $rs['user_login'];
  686. $email = $rs['email'];
  687. if ($diffdate > $PASSWORD_CHANGE_CYCLE) {// Timeout
  688. if(empty($email)){
  689. $data = array(
  690. 'status' => '0',
  691. 'msg' => 'login user email is empty',
  692. 'login_version' => $rs["login_version"],
  693. 'data' => ''
  694. );
  695. common::echo_json_encode(500, $data);
  696. exit();
  697. }else{
  698. //$this -> passwordExpires($loginName,$email);
  699. }
  700. }
  701. if ($diffdate == $PASSWORD_CHANGE_CYCLE) {// Due today
  702. $login_tmp = array(
  703. 'msg' => 'today',
  704. 'login_version' => $rs["login_version"],
  705. 'data' => ''
  706. );
  707. } elseif ($diffdate >= ($PASSWORD_CHANGE_CYCLE - $PASSWORD_CHANGE_ALERT)) {// Password expires soon, JS Tips
  708. $login_tmp = array(
  709. 'msg' => 'last',
  710. 'login_version' => $rs["login_version"],
  711. 'data' => $PASSWORD_CHANGE_CYCLE - $diffdate,
  712. 'is_only_vgm' => $rs["is_only_vgm"]
  713. );
  714. }
  715. //insert into log table
  716. $ip = common::ip();
  717. $sql = "insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')";
  718. if (common::excuteUpdateSql($sql)) {
  719. common::excuteUpdateSql("update public.ra_online_user set Last_Login_Time = now(), error_login_count=0, error_login_time=null where lower(user_login) = '" . strtolower($uname) . "'");
  720. //自动登录。为了方便调用,先注销掉
  721. if (isset($login_tmp)) {
  722. //common::echo_json_encode(500, $login_tmp);
  723. } else {
  724. $data = array(
  725. 'msg' => 'success',
  726. 'login_version' => $rs["login_version"],
  727. 'data' => '',
  728. 'is_only_vgm' => $rs["is_only_vgm"]
  729. );
  730. //common::echo_json_encode("200", $data);
  731. }
  732. $online_user = $rs;
  733. $online_user['user_login'] = $uname;
  734. $online_user['company'] = $company;
  735. $online_user['password'] = "";
  736. if (!_isAdmin()) {
  737. if ($rs["is_only_vgm"] == "t") {//VGM用户写死
  738. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where url_action in ('ocean_order','password','vgm') and menu_id in ('ship','profile') order by order_by asc), ',')";
  739. $rrrs = common::excuteOneSql($sql);
  740. } else {
  741. $sql = "select array_to_string(ARRAY(select p.url_action from public.ra_online_user_permission up left join public.ra_online_user u on up.user_name = u.user_login left join public.ra_online_permission p on up.p_id = p.id where lower(u.user_login) = '" . common::check_input(strtolower($uname)) . "'), ',')";
  742. $rrrs = common::excuteOneSql($sql);
  743. if (strtolower($rs['user_type']) == "employee" && empty($rrrs)) {
  744. $sql = "select array_to_string(ARRAY(select url_action from public.ra_online_permission where is_customer = true order by order_by asc), ',')";
  745. $rrrs = common::excuteOneSql($sql);
  746. }
  747. }
  748. $online_user['permission'] = $rrrs;
  749. }
  750. if (!empty($online_user['docdownload']))
  751. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
  752. else {
  753. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where active = true";
  754. if (strtolower($online_user['user_type']) == "customer")
  755. $sql .= " and client_display = true";
  756. $sql .= " group by display_name order by min(id)";
  757. }
  758. $online_user['view_doc_type'] = common::excuteListSql($sql);
  759. if (!empty($online_user['view_air_file_format']))
  760. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  761. else {
  762. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where active = true";
  763. if (strtolower($online_user['user_type']) == "customer")
  764. $sql .= " and client_display = true";
  765. $sql .= " group by display_name order by min(id)";
  766. }
  767. $online_user['view_air_doc_type'] = common::excuteListSql($sql);
  768. //补充aci and ams CustomerLogin station - public
  769. $ocean_station_temp = $online_user['ocean_station'];
  770. $online_user['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  771. $ocean_agent_temp = $online_user['ocean_agent'];
  772. $online_user['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  773. $_SESSION['ONLINE_USER'] = $online_user;
  774. $_SESSION['LAST_OPERATE_TIME'] = time();
  775. $_SESSION['SESSION_TIMEOUT'] = $SESSION_TIMEOUT;
  776. //判断是否记录密码 add
  777. if ($_POST['rememberpwd'] === 'true') {
  778. if (!$noCheckPwd) {
  779. $user_info = $uname . "_" . md5($rs['password']);
  780. setcookie('userInfo', $user_info, time() + 30 * 24 * 3600, "/");
  781. }
  782. } else {
  783. setcookie('userInfo', '', time() - 1, "/");
  784. }
  785. if ($rs['is_super'] == "t") {
  786. $schemas_list = common::excuteListSql("select * from schemas_list");
  787. } else {
  788. $schemas_list = common::excuteListSql("select * from schemas_list where schemas_name=any(regexp_split_to_array('" . $rs['belong_schemas'] . "'::text, ';'::text))");
  789. }
  790. ///if (count($schemas_list) > 1) {
  791. foreach ($schemas_list as $sk => $sv) {
  792. if ($sv['schemas_name'] == "public") {
  793. continue;
  794. }
  795. $ttdd = common::excuteObjectSql("select contact_id_user, employee_id, contact_id, user_type, email, user_webtype_id, active, is_online, station, allow_login_remote, can_see_amslog,can_view_eccn, can_see_isflog, can_see_isflog_withaddress,
  796. customer_search_type, customer_destination, can_add_ams, can_add_isf, air_station, air_sales, ocean_station, ocean_sales,ocean_following_sales,ocean_following_sales_or,air_following_sales,air_following_sales_or, trucking_station, ocean_dest_op, can_see_password, can_add_opsales_code, ocean_station_or, ocean_agent_or, ocean_sales_or, ocean_dest_op_or, air_station_or, air_sales_or, trucking_station_or,
  797. can_add_user, can_add_employee, can_add_contact, company_name, ams_email, isf_email, customer_discharge, online_active, is_super, ocean_agent,active, can_send_email, view_file_format as docdownload, container_status, consolidated_cbsa_code, can_add_aci,
  798. air_customers, air_customer_search_type,trucking_customers,trucking_customer_search_type, upload_document, view_file_format, event_type, po_status, view_air_file_format, special_customer_event, can_edi_vgm, isf_aci_ams_station, is_kerry_shipment from " . $sv['schemas_name'] . ".ra_online_user where lower(user_login) = '" . strtolower($uname) . "'");
  799. if (empty($ttdd)) {
  800. unset($schemas_list[$sk]);
  801. continue;
  802. }
  803. if (!empty($ttdd['docdownload'])) {
  804. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
  805. } else {
  806. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
  807. if (strtolower($ttdd['user_type']) == "customer")
  808. $sql .= " and client_display = true";
  809. $sql .= " group by display_name order by min(id)";
  810. }
  811. $ttdd['view_doc_type'] = common::excuteListSql($sql);
  812. if (!empty($ttdd['view_air_file_format'])) {
  813. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
  814. } else {
  815. $sql = "select string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where active = true";
  816. if (strtolower($ttdd['user_type']) == "customer")
  817. $sql .= " and client_display = true";
  818. $sql .= " group by display_name order by min(id)";
  819. }
  820. $ttdd['view_air_doc_type'] = common::excuteListSql($sql);
  821. //补充aci and ams CustomerLogin station - other like sfs
  822. $ocean_station_temp = $ttdd['ocean_station'];
  823. $ttdd['session_ocean_station'] = $this->getOriginOrAgent($ocean_station_temp);
  824. $ocean_agent_temp = $ttdd['ocean_agent'];
  825. $ttdd['session_ocean_agent'] = $this->getOriginOrAgent($ocean_agent_temp);
  826. $_SESSION[$sv['schemas_name'] . '_ONLINE_USER'] = $ttdd;
  827. }
  828. //}
  829. $_SESSION['schemas_list'] = $schemas_list;
  830. //不再返回登录页面,直接跳转
  831. if (isset($_GET['up'])) {
  832. if($_GET['v'] == 'new'){
  833. header("Location: main_new_version.php?action=main");
  834. }else{
  835. header("Location: main.php?action=main");
  836. }
  837. }
  838. //自动登录。为了方便调用,先注销掉
  839. //exit();
  840. } else {
  841. $data = array(
  842. 'msg' => 'database_error',
  843. 'login_version' => $rs["login_version"],
  844. 'data' => ''
  845. );
  846. common::echo_json_encode(500, $data);
  847. exit();
  848. }
  849. } else {
  850. $data = array(
  851. 'msg' => 'no_exist',
  852. 'login_version' => $rs["login_version"],
  853. 'data' => ''
  854. );
  855. common::echo_json_encode(500, $data);
  856. exit();
  857. }
  858. }
  859. }
  860. private function failedLogin($uname, $company){
  861. $ip = common::ip();
  862. common::excuteUpdateSql("insert into public.ra_online_user_login_log (user_name,manufacturer,from_app,ip,date_time, session_id) values ('" . common::check_input($uname) . "', '" . common::check_input($company) . "','Online','$ip',now(), '" . session_id() . "')");
  863. }
  864. //重置密码
  865. public function passwordExpires($loginName,$email){
  866. $result = array(
  867. 'msg' => "passwordExpires",
  868. );
  869. common::echo_json_encode(400, $result);
  870. exit();
  871. }
  872. //submit change form -- change expires password
  873. public function update_pwd_expires(){
  874. $loginName = common::check_input($_POST['uname']);
  875. $old_password = common::check_input($_POST['old_password']);
  876. $password = common::check_input($_POST['password']);
  877. $verifcation_code =
  878. //首先校验验证码
  879. $verifcation_code = common::check_input($_POST['verifcation_code']);
  880. if (strtolower($_SESSION['captcha']) != strtolower($verifcation_code)) {
  881. $data = array(
  882. 'msg' => 'verifcation_error',
  883. 'data' => ''
  884. );
  885. common::echo_json_encode(400, $data);
  886. exit();
  887. }
  888. $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($loginName) . "'";
  889. $rs = common::excuteObjectSql($sql);
  890. $str = '';
  891. if (!empty($rs)) {
  892. if ($rs['password'] != $old_password) {
  893. $str = "Old password is incorrect!";
  894. }
  895. } else {
  896. $str = "Old password is incorrect!";
  897. }
  898. if(!empty($str)){
  899. $data = array(
  900. 'msg' => $str,
  901. 'data' => ''
  902. );
  903. common::echo_json_encode(400, $data);
  904. exit();
  905. }
  906. //验证通过,进行修改密码
  907. $msg = $this->updateExpirePassword($loginName, $password);
  908. if($msg == "success"){
  909. $data = array(
  910. 'msg' => "success",
  911. 'data' => ''
  912. );
  913. common::echo_json_encode(200, $data);
  914. exit();
  915. } else {
  916. $data = array(
  917. 'msg' => $str,
  918. 'data' => ''
  919. );
  920. common::echo_json_encode(400, $data);
  921. exit();
  922. }
  923. }
  924. //更新密码
  925. public function updateExpirePassword($login,$new_password) {
  926. $str = $this->checkPasswordRule($login, $new_password);
  927. //更新密码,擦除expire pwd痕迹
  928. if (empty($str)) {
  929. $sql = "UPDATE public.ra_online_user SET ra_password = '" . common::check_input($new_password) . "',password_new=redant_encode('".$new_password."'),
  930. last_pwd_change = now(),password_expires_keycode = null,password_expires_time = null
  931. WHERE lower(user_login) = '" . common::check_input(strtolower($login)) . "';";
  932. $rls = common::excuteUpdateSql($sql);
  933. if (!$rls) {
  934. $str = "Database Error, Try Later.";
  935. } else {
  936. $sql = "INSERT INTO public.ra_online_user_password_history (user_login, password, create_user, create_date) VALUES ('" . $login . "', " . common::check_input($new_password) . ", '" . $login . "', now());";
  937. common::excuteUpdateSql($sql);
  938. $str = "success";
  939. }
  940. }
  941. return $str;
  942. }
  943. //密码规则验证
  944. public function checkPasswordRule($login, $new_password){
  945. $sql="select item_value from config where item='passwordCheckRules'";
  946. $rs = common::excuteObjectSql($sql);
  947. $str = "";
  948. if (!empty($rs)) {
  949. $passwordCheckRules = json_decode($rs["item_value"],true);
  950. //校验使用次数
  951. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  952. $sql = "select password from public.ra_online_user_password_history where lower(user_login)='".common::check_input(strtolower($login))."' order by id desc limit ".$passwordCheckRules["pastPasswordCheckNum"];
  953. $passwords = common::excuteListSql($sql);
  954. foreach ($passwords as $pwd) {
  955. if ($pwd['password'] == $new_password) {
  956. $str = "This password has been recently used";
  957. }
  958. }
  959. }
  960. if(empty($str)){
  961. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  962. }
  963. }else{
  964. $str = utils::checkPassword($new_password);
  965. }
  966. return $str;
  967. }
  968. public function getOriginOrAgent($ocean_station_temp){
  969. $session_ocean_station = "";
  970. if (strtolower($ocean_station_temp) == 'all'){
  971. $session_ocean_station = $ocean_station_temp;
  972. }
  973. if (!(strtolower($ocean_station_temp) == 'all' || empty($ocean_station_temp))){
  974. if (utils::checkExist($ocean_station_temp, ";")) {
  975. $ost = str_replace(";","','",strtolower($ocean_station_temp));
  976. $sql="select kerry_station_id,contact_id from ocean.contacts where coalesce(kerry_station_id,'') <>''and lower(contact_id) in ('".$ost."')";
  977. $tar = common::excuteListSql($sql);
  978. foreach ($tar as $tk => $tv) {
  979. $tar[$tv['contact_id']] = $tv['kerry_station_id'];
  980. }
  981. $_tt = explode(";", $ocean_station_temp);
  982. foreach ($_tt as $vv) {
  983. if (!empty($vv)){
  984. $session_ocean_station .= trim($vv).';';
  985. if (!empty($tar[$vv])) {
  986. $session_ocean_station .= $tar[trim($vv)].';';
  987. }
  988. }
  989. }
  990. } else {
  991. $session_ocean_station .= trim($ocean_station_temp).';';
  992. $temp_contacts = common::excuteObjectSql("select kerry_station_id from ocean.contacts where lower(contact_id)='".strtolower(common::check_input($ocean_station_temp))."'");
  993. if (!empty($temp_contacts['kerry_station_id'])){
  994. $session_ocean_station .= $temp_contacts['kerry_station_id'].';';
  995. }
  996. }
  997. }
  998. return $session_ocean_station;
  999. }
  1000. }
  1001. ?>