PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/login.php

https://github.com/whale2/users
PHP | 128 lines | 102 code | 22 blank | 4 comment | 11 complexity | 025ccb78bb8ad92c374af9234a71c0b7 MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/config.php');
  3. require_once(dirname(__FILE__).'/User.php');
  4. // Allow modules to auto-login (if supported)
  5. $user = null;
  6. foreach (UserConfig::$authentication_modules as $module)
  7. {
  8. $user = $module->processAutoLogin();
  9. if (!is_null($user)) {
  10. $remember = false;
  11. $user->setSession($remember);
  12. $return = User::getReturn();
  13. User::clearReturn();
  14. if (!is_null($return))
  15. {
  16. header('Location: '.$return);
  17. }
  18. else
  19. {
  20. header('Location: '.UserConfig::$DEFAULTLOGINRETURN);
  21. }
  22. exit;
  23. }
  24. }
  25. if (array_key_exists('login', $_POST))
  26. {
  27. $module = null;
  28. foreach (UserConfig::$authentication_modules as $module)
  29. {
  30. if ($module->getID() == $_GET['module']) {
  31. break;
  32. }
  33. }
  34. $remember = false;
  35. $user = $module->processLogin($_POST, $remember);
  36. if (is_null($user))
  37. {
  38. header('Location: '.UserConfig::$USERSROOTURL.'/login.php?module='.$_GET['module'].'&error=failed');
  39. exit;
  40. }
  41. $user->setSession($remember);
  42. $return = User::getReturn();
  43. User::clearReturn();
  44. if (!is_null($return))
  45. {
  46. header('Location: '.$return);
  47. }
  48. else
  49. {
  50. header('Location: '.UserConfig::$DEFAULTLOGINRETURN);
  51. }
  52. exit;
  53. }
  54. require_once(UserConfig::$header);
  55. ?>
  56. <style>
  57. .userbase-errorbox {
  58. background: #f7dfb9;
  59. font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  60. padding: 0.4em 1em;
  61. margin: 1em 0;
  62. width: 475px;
  63. border: 4px solid #f77;
  64. border-radius: 7px;
  65. -moz-border-radius: 7px;
  66. -webkit-border-radius: 7px;
  67. font-size: 1.2em;
  68. color: #500;
  69. font-weight: bold;
  70. }
  71. #userbase-authlist {
  72. font: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  73. background: white;
  74. padding: 0 1em;
  75. margin: 0 auto;
  76. width: 480px;
  77. }
  78. #userbase-authlist h2 {
  79. font-weight: bold;
  80. font-size: 2.5em;
  81. }
  82. #userbase-authlist h3 {
  83. font-weight: bold;
  84. font-size: 1.5em;
  85. }
  86. </style>
  87. <div id="userbase-authlist">
  88. <h2>Log in</h2>
  89. <?php
  90. foreach (UserConfig::$authentication_modules as $module)
  91. {
  92. $id = $module->getID();
  93. ?>
  94. <div style="margin-bottom: 2em">
  95. <h3 name="<?php echo $id?>"><?php echo $module->getTitle()?></h3>
  96. <?php
  97. if (array_key_exists('module', $_GET) && $id == $_GET['module'] && array_key_exists('error', $_GET))
  98. {
  99. ?><div class="userbase-errorbox">Login failed</div><?php
  100. }
  101. $module->renderLoginForm("?module=$id");
  102. ?></div>
  103. <?php
  104. }
  105. ?></div><?php
  106. require_once(UserConfig::$footer);