loginwebpage.class.inc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. require_once("../application/nicewebpage.class.inc.php");
  3. /**
  4. * Web page used for displaying the login form
  5. */
  6. class login_web_page extends nice_web_page
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct("iTop Login");
  11. $this->add_style("
  12. body {
  13. background-color: #eee;
  14. margin: 0;
  15. padding: 0;
  16. }
  17. #login {
  18. width: 230px;
  19. margin-left: auto;
  20. margin-right: auto;
  21. margin-top: 150px;
  22. padding: 20px;
  23. background-color: #fff;
  24. border: 1px solid #000;
  25. }
  26. .center {
  27. text-align: center;
  28. }
  29. h1 {
  30. color: #83b217;
  31. font-size: 16pt;
  32. }
  33. .v-spacer {
  34. padding-top: 1em;
  35. }
  36. ");
  37. }
  38. public function DisplayLoginForm($bFailedLogin = false)
  39. {
  40. $sAuthUser = utils::ReadParam('auth_user', '');
  41. $sAuthPwd = utils::ReadParam('suggest_pwd', '');
  42. $this->add("<div id=\"login\">\n");
  43. $this->add("<h1>Welcome to iTop!</h1>\n");
  44. if ($bFailedLogin)
  45. {
  46. $this->add("<p class=\"hilite\">Incorrect login/password, please try again.</p>\n");
  47. }
  48. else
  49. {
  50. $this->add("<p>Please identify yourself before continuing.</p>\n");
  51. }
  52. $this->add("<form method=\"post\">\n");
  53. $this->add("<table>\n");
  54. $this->add("<tr><td><label for=\"user\">User Name:</label></td><td><input id=\"user\" type=\"text\" name=\"auth_user\" value=\"$sAuthUser\" /></td></tr>\n");
  55. $this->add("<tr><td><label for=\"pwd\">Password:</label></td><td><input id=\"pwd\" type=\"password\" name=\"auth_pwd\" value=\"$sAuthPwd\" /></td></tr>\n");
  56. $this->add("<tr><td colspan=\"2\" class=\"center v-spacer\"> <input type=\"submit\" value=\"Enter iTop\" /></td></tr>\n");
  57. $this->add("</table>\n");
  58. $this->add("<input type=\"hidden\" name=\"operation\" value=\"login\" />\n");
  59. $this->add("</form>\n");
  60. $this->add("</div>\n");
  61. }
  62. static function DoLogin()
  63. {
  64. $operation = utils::ReadParam('operation', '');
  65. session_start();
  66. if (!isset($_SESSION['auth_user']) || !isset($_SESSION['auth_pwd']))
  67. {
  68. if ($operation == 'login')
  69. {
  70. $sAuthUser = utils::ReadParam('auth_user', '', 'post');
  71. $sAuthPwd = utils::ReadParam('auth_pwd', '', 'post');
  72. }
  73. else
  74. {
  75. $oPage = new login_web_page();
  76. $oPage->DisplayLoginForm();
  77. $oPage->output();
  78. exit;
  79. }
  80. }
  81. else
  82. {
  83. $sAuthUser = $_SESSION['auth_user'];
  84. $sAuthPwd = $_SESSION['auth_pwd'];
  85. }
  86. if (!UserRights::Login($sAuthUser, $sAuthPwd))
  87. {
  88. // Unset all of the session variables.
  89. $_SESSION = array();
  90. // If it's desired to kill the session, also delete the session cookie.
  91. // Note: This will destroy the session, and not just the session data!
  92. if (isset($_COOKIE[session_name()]))
  93. {
  94. setcookie(session_name(), '', time()-3600, '/');
  95. }
  96. // Finally, destroy the session.
  97. session_destroy();
  98. $oPage = new login_web_page();
  99. $oPage->DisplayLoginForm( true /* failed attempt */);
  100. $oPage->output();
  101. exit;
  102. }
  103. else
  104. {
  105. $_SESSION['auth_user'] = $sAuthUser ;
  106. $_SESSION['auth_pwd'] = $sAuthPwd;
  107. }
  108. }
  109. } // End of class
  110. ?>