PageRenderTime 107ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/assets/snippets/weblogin/weblogin.common.inc.php

https://github.com/dreeman/modx106
PHP | 94 lines | 74 code | 9 blank | 11 comment | 12 complexity | 58908450177125b5359afa79df3baf9a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * Commonly used login functions
  4. * Writen By Raymond Irving April, 2005
  5. *
  6. */
  7. // extract declarations
  8. function webLoginExtractDeclarations(&$html){
  9. $declare = array();
  10. if(strpos($html,"<!-- #declare:")===false) return $declare;
  11. $matches= array();
  12. if (preg_match_all("/<\!-- \#declare\:(.*)[^-->]?-->/i",$html,$matches)) {
  13. for($i=0;$i<count($matches[1]);$i++) {
  14. $tag = explode(" ",$matches[1][$i]);
  15. $tagname=trim($tag[0]);
  16. $tagvalue=trim($tag[1]);
  17. $declare[$tagname] = $tagvalue;
  18. }
  19. // remove declarations
  20. $html = str_replace($matches[0],"",$html);
  21. }
  22. return $declare;
  23. }
  24. // show javascript alert
  25. function webLoginAlert($msg){
  26. global $modx;
  27. return "<script>window.setTimeout(\"alert('".addslashes($modx->db->escape($msg))."')\",10);</script>";
  28. }
  29. // generate new password
  30. function webLoginGeneratePassword($length = 10) {
  31. $allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
  32. $ps_len = strlen($allowable_characters);
  33. mt_srand((double)microtime()*1000000);
  34. $pass = "";
  35. for($i = 0; $i < $length; $i++) {
  36. $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
  37. }
  38. return $pass;
  39. }
  40. // Send new password to the user
  41. function webLoginSendNewPassword($email,$uid,$pwd,$ufn){
  42. global $modx, $site_url;
  43. $mailto = $modx->config['mailto'];
  44. $websignupemail_message = $modx->config['websignupemail_message'];
  45. $emailsubject = $modx->config['emailsubject'];
  46. $emailsender = $modx->config['emailsender'];
  47. $site_name = $modx->config['site_name'];
  48. $site_start = $modx->config['site_start'];
  49. $message = sprintf($websignupemail_message, $uid, $pwd); // use old method
  50. // replace placeholders
  51. $message = str_replace("[+uid+]",$uid,$message);
  52. $message = str_replace("[+pwd+]",$pwd,$message);
  53. $message = str_replace("[+ufn+]",$ufn,$message);
  54. $message = str_replace("[+sname+]",$site_name,$message);
  55. $message = str_replace("[+semail+]",$emailsender,$message);
  56. $message = str_replace("[+surl+]",$site_url,$message);
  57. if (!ini_get('safe_mode')) $sent = mail($email, $emailsubject, $message, "From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion(), "-f {$emailsender}");
  58. else $sent = mail($email, $emailsubject, $message, "From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion());
  59. if (!$sent) webLoginAlert("Error while sending mail to $mailto",1);
  60. return true;
  61. }
  62. function preserveUrl($docid = '', $alias = '', $array_values = array(), $suffix = false) {
  63. global $modx;
  64. $array_get = $_GET;
  65. $urlstring = array();
  66. unset($array_get["id"]);
  67. unset($array_get["q"]);
  68. unset($array_get["webloginmode"]);
  69. $array_url = array_merge($array_get, $array_values);
  70. foreach ($array_url as $name => $value) {
  71. if (!is_null($value)) {
  72. $urlstring[] = urlencode($name) . '=' . urlencode($value);
  73. }
  74. }
  75. $url = join('&',$urlstring);
  76. if ($suffix) {
  77. if (empty($url)) {
  78. $url = "?";
  79. } else {
  80. $url .= "&";
  81. }
  82. }
  83. return $modx->makeUrl($docid, $alias, $url);
  84. }
  85. ?>