PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/login.php

https://github.com/fredd-for/emaus_tesoreria
PHP | 376 lines | 241 code | 58 blank | 77 comment | 50 complexity | c43d28aae5650b37c224d14d4e0b4c36 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. session_start(); // Initialize session data
  3. ob_start(); // Turn on output buffering
  4. ?>
  5. <?php include "ewcfg6.php" ?>
  6. <?php include "ewmysql6.php" ?>
  7. <?php include "phpfn6.php" ?>
  8. <?php include "usuarioinfo.php" ?>
  9. <?php include "userfn6.php" ?>
  10. <?php
  11. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  12. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
  13. header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
  14. header("Cache-Control: post-check=0, pre-check=0", false);
  15. header("Pragma: no-cache"); // HTTP/1.0
  16. ?>
  17. <?php
  18. // Define page object
  19. $login = new clogin();
  20. $Page =& $login;
  21. // Page init processing
  22. $login->Page_Init();
  23. // Page main processing
  24. $login->Page_Main();
  25. ?>
  26. <?php include "header.php" ?>
  27. <script language="JavaScript" type="text/javascript">
  28. <!--
  29. // Write your client script here, no need to add script tags.
  30. // To include another .js script, use:
  31. // ew_ClientScriptInclude("my_javascript.js");
  32. //-->
  33. </script>
  34. <script type="text/javascript">
  35. <!--
  36. var login = new ew_Page("login");
  37. // extend page with ValidateForm function
  38. login.ValidateForm = function(fobj)
  39. {
  40. if (!this.ValidateRequired)
  41. return true; // ignore validation
  42. if (!ew_HasValue(fobj.username))
  43. return ew_OnError(this, fobj.username, "Por favor ingrese una Identificaci�n de Usuario");
  44. if (!ew_HasValue(fobj.password))
  45. return ew_OnError(this, fobj.password, "Ingrese contrase�a");
  46. // Call Form Custom Validate event
  47. if (!this.Form_CustomValidate(fobj)) return false;
  48. return true;
  49. }
  50. // extend page with Form_CustomValidate function
  51. login.Form_CustomValidate =
  52. function(fobj) { // DO NOT CHANGE THIS LINE!
  53. // Your custom validation code here, return false if invalid.
  54. return true;
  55. }
  56. // requires js validation
  57. <?php if (EW_CLIENT_VALIDATE) { ?>
  58. login.ValidateRequired = true;
  59. <?php } else { ?>
  60. login.ValidateRequired = false;
  61. <?php } ?>
  62. //-->
  63. </script>
  64. <p><span class="phpmaker">Pagina de ingreso</span></p>
  65. <?php $login->ShowMessage() ?>
  66. <form action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return login.ValidateForm(this);">
  67. <table border="0" cellspacing="0" cellpadding="4">
  68. <tr>
  69. <td><span class="phpmaker">Nombre del usuario</span></td>
  70. <td><span class="phpmaker"><input type="text" name="username" id="username" size="20" value="<?php echo $login->sUsername ?>"></span></td>
  71. </tr>
  72. <tr>
  73. <td><span class="phpmaker">Contrasea</span></td>
  74. <td><span class="phpmaker"><input type="password" name="password" id="password" size="20"></span></td>
  75. </tr>
  76. <tr>
  77. <td>&nbsp;</td>
  78. <td><span class="phpmaker">
  79. <label><input type="radio" name="rememberme" id="rememberme" value="a"<?php if ($login->sLoginType == "a") { ?> checked="checked"<?php } ?>>Ingresar automticamente hasta que me desconecte explcitamente</label><br>
  80. <label><input type="radio" name="rememberme" id="rememberme" value="u"<?php if ($login->sLoginType == "u") { ?> checked="checked"<?php } ?>>Guardar mi nombre de usuario</label><br>
  81. <label><input type="radio" name="rememberme" id="rememberme" value=""<?php if ($login->sLoginType == "") { ?> checked="checked"<?php } ?>>Siempre preguntar por mi usuario y contrasea</label>
  82. </span></td>
  83. </tr>
  84. <tr>
  85. <td colspan="2" align="center"><span class="phpmaker"><input type="submit" name="submit" id="submit" value=" Ingresar "></span></td>
  86. </tr>
  87. </table>
  88. </form>
  89. <br>
  90. <p><span class="phpmaker">
  91. <a href="register.php">Registrar</a>&nbsp;&nbsp;&nbsp;&nbsp;
  92. </span></p>
  93. <div align="center">
  94. <img src="ewmenu/problema.jpg" width="50%" ></img>
  95. </div>
  96. <script language="JavaScript" type="text/javascript">
  97. <!--
  98. // Write your startup script here
  99. // document.write("page loaded");
  100. //-->
  101. </script>
  102. <?php include "footer.php" ?>
  103. <?php
  104. //
  105. // Page Class
  106. //
  107. class clogin {
  108. // Page ID
  109. var $PageID = 'login';
  110. // Page Object Name
  111. var $PageObjName = 'login';
  112. // Page Name
  113. function PageName() {
  114. return ew_CurrentPage();
  115. }
  116. // Page Url
  117. function PageUrl() {
  118. $PageUrl = ew_CurrentPage() . "?";
  119. return $PageUrl;
  120. }
  121. // Message
  122. function getMessage() {
  123. return @$_SESSION[EW_SESSION_MESSAGE];
  124. }
  125. function setMessage($v) {
  126. if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
  127. $_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
  128. } else {
  129. $_SESSION[EW_SESSION_MESSAGE] = $v;
  130. }
  131. }
  132. // Show Message
  133. function ShowMessage() {
  134. if ($this->getMessage() <> "") { // Message in Session, display
  135. echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
  136. $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
  137. }
  138. }
  139. // Validate Page request
  140. function IsPageRequest() {
  141. return TRUE;
  142. }
  143. //
  144. // Class initialize
  145. // - init objects
  146. // - open connection
  147. //
  148. function clogin() {
  149. global $conn;
  150. // Initialize table object
  151. $GLOBALS["usuario"] = new cusuario();
  152. // Intialize page id (for backward compatibility)
  153. if (!defined("EW_PAGE_ID"))
  154. define("EW_PAGE_ID", 'login', TRUE);
  155. // Open connection to the database
  156. $conn = ew_Connect();
  157. }
  158. //
  159. // Page_Init
  160. //
  161. function Page_Init() {
  162. global $gsExport, $gsExportFile, $usuario;
  163. global $Security;
  164. $Security = new cAdvancedSecurity();
  165. // Global page loading event (in userfn6.php)
  166. Page_Loading();
  167. // Page load event, used in current page
  168. $this->Page_Load();
  169. }
  170. //
  171. // Page_Terminate
  172. // - called when exit page
  173. // - if URL specified, redirect to the URL
  174. //
  175. function Page_Terminate($url = "") {
  176. global $conn;
  177. // Page unload event, used in current page
  178. $this->Page_Unload();
  179. // Global page unloaded event (in userfn*.php)
  180. Page_Unloaded();
  181. // Close Connection
  182. $conn->Close();
  183. // Go to URL if specified
  184. if ($url <> "") {
  185. ob_end_clean();
  186. header("Location: $url");
  187. }
  188. exit();
  189. }
  190. var $sUsername;
  191. var $sLoginType;
  192. //
  193. // Page main processing
  194. //
  195. function Page_Main() {
  196. global $Security, $gsFormError;
  197. $sLastUrl = $Security->LastUrl(); // Get Last Url
  198. if ($sLastUrl == "")
  199. $sLastUrl = "index.php";
  200. if (!$Security->IsLoggedIn())
  201. $Security->AutoLogin();
  202. $Security->LoadUserLevel(); // Load user level
  203. if (@$_POST["username"] <> "") {
  204. // Setup variables
  205. $this->sUsername = ew_StripSlashes(@$_POST["username"]);
  206. $sPassword = ew_StripSlashes(@$_POST["password"]);
  207. $this->sLoginType = strtolower(@$_POST["rememberme"]);
  208. $bValidate = $this->ValidateForm($this->sUsername, $sPassword);
  209. if (!$bValidate)
  210. $this->setMessage($gsFormError);
  211. } else {
  212. if ($Security->IsLoggedIn()) {
  213. if ($this->getMessage() == "")
  214. $this->Page_Terminate($sLastUrl); // Return to last accessed page
  215. }
  216. $bValidate = FALSE;
  217. // Restore settings
  218. $this->sUsername = @$_COOKIE[EW_PROJECT_NAME]['UserName'];
  219. if (@$_COOKIE[EW_PROJECT_NAME]['AutoLogin'] == "autologin") {
  220. $this->sLoginType = "a";
  221. } elseif (@$_COOKIE[EW_PROJECT_NAME]['AutoLogin'] == "rememberusername") {
  222. $this->sLoginType = "u";
  223. } else {
  224. $this->sLoginType = "";
  225. }
  226. }
  227. if ($bValidate) {
  228. $bValidPwd = FALSE;
  229. // Call loggin in event
  230. $bValidate = $this->User_LoggingIn($this->sUsername, $sPassword);
  231. if ($bValidate) {
  232. $bValidPwd = $Security->ValidateUser($this->sUsername, $sPassword);
  233. if (!$bValidPwd)
  234. $this->setMessage("ID del usuario o contrase�a incorrecta"); // Invalid User ID/password
  235. } else {
  236. if ($this->getMessage() == "")
  237. $this->setMessage("Ingreso cancelado"); // Login cancelled
  238. }
  239. if ($bValidPwd) {
  240. // Write cookies
  241. $expirytime = time() + 365*24*60*60; // Change cookie expiry time here
  242. if ($this->sLoginType == "a") { // Auto login
  243. setcookie(EW_PROJECT_NAME . '[AutoLogin]', "autologin", $expirytime); // Set up autologin cookies
  244. setcookie(EW_PROJECT_NAME . '[UserName]', $this->sUsername, $expirytime); // Set up user name cookies
  245. setcookie(EW_PROJECT_NAME . '[Password]', TEAencrypt($sPassword, EW_RANDOM_KEY), $expirytime); // Set up password cookies
  246. } elseif ($this->sLoginType == "u") { // Remember user name
  247. setcookie(EW_PROJECT_NAME . '[AutoLogin]', "rememberusername", $expirytime); // Set up remember user name cookies
  248. setcookie(EW_PROJECT_NAME . '[UserName]', $this->sUsername, $expirytime); // Set up user name cookies
  249. } else {
  250. setcookie(EW_PROJECT_NAME . '[AutoLogin]', "", $expirytime); // Clear autologin cookies
  251. }
  252. // Call loggedin event
  253. $this->User_LoggedIn($this->sUsername);
  254. $this->Page_Terminate($sLastUrl); // Return to last accessed URL
  255. } else {
  256. // Call user login error event
  257. $this->User_LoginError($this->sUsername, $sPassword);
  258. }
  259. }
  260. }
  261. //
  262. // Validate form
  263. //
  264. function ValidateForm($usr, $pwd) {
  265. global $gsFormError;
  266. // Initialize
  267. $gsFormError = "";
  268. // Check if validation required
  269. if (!EW_SERVER_VALIDATE)
  270. return TRUE;
  271. if (trim($usr) == "") {
  272. $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
  273. $gsFormError .= "Por favor ingrese una Identificaci�n de Usuario";
  274. }
  275. if (trim($pwd) == "") {
  276. $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
  277. $gsFormError .= "Ingrese contrase�a";
  278. }
  279. // Return validate result
  280. $ValidateForm = ($gsFormError == "");
  281. // Call Form Custom Validate event
  282. $sFormCustomError = "";
  283. $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
  284. if ($sFormCustomError <> "") {
  285. $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
  286. $gsFormError .= $sFormCustomError;
  287. }
  288. return $ValidateForm;
  289. }
  290. // Page Load event
  291. function Page_Load() {
  292. //echo "Page Load";
  293. }
  294. // Page Unload event
  295. function Page_Unload() {
  296. //echo "Page Unload";
  297. }
  298. // User Logging In event
  299. function User_LoggingIn($usr, $pwd) {
  300. // Enter your code here
  301. // To cancel, set return value to FALSE
  302. return TRUE;
  303. }
  304. // User Logged In event
  305. function User_LoggedIn($usr) {
  306. //echo "User Logged In";
  307. }
  308. // User Login Error event
  309. function User_LoginError($usr, $pwd) {
  310. //echo "User Login Error";
  311. }
  312. // Form Custom Validate event
  313. function Form_CustomValidate(&$CustomError) {
  314. // Return error message in CustomError
  315. return TRUE;
  316. }
  317. }
  318. ?>