login.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?
  2. # Include the TV functions
  3. require_once 'includes/main.php';
  4. # Send our headers early
  5. header('Content-type: text/html; charset=utf-8');
  6. # Process logout
  7. if (isset($_REQUEST['logout'])) {
  8. logout();
  9. }
  10. # Redirect if we're already authenticated
  11. if (authenticated()) {
  12. login_redirect();
  13. }
  14. # Process login
  15. if (isset($_POST['username']) && isset($_POST['password'])) {
  16. login($_POST['username'], $_POST['password']);
  17. }
  18. #=========================================================================================
  19. printHeader('UberZach TV - Login');
  20. # Preserve the redirect
  21. $url = $_SERVER['PHP_SELF'];
  22. if (isset($_GET['dest'])) {
  23. $url .= '?dest=' . urlencode($_GET['dest']);
  24. }
  25. # Save our AUTH_ERR as a user notice, if it exists
  26. $notice = '';
  27. if ($AUTH_ERR) {
  28. $notice = $AUTH_ERR;
  29. }
  30. # Header
  31. print <<<ENDOLA
  32. <div style="width: 50%; margin-left: auto; margin-right: auto;">
  33. <form action="${url}" method="post" data-ajax="false">
  34. ENDOLA;
  35. # Print the user notice, if any, above the login fields
  36. if ($notice) {
  37. print <<<ENDOLA
  38. <p style="color: red;">
  39. $notice
  40. </p>
  41. ENDOLA;
  42. }
  43. # Login fields
  44. print <<<ENDOLA
  45. <p>
  46. <label>Username: <input type="text" name="username" /></label><br/>
  47. <label>Password: <input type="password" name="password" /></label><br/>
  48. </p>
  49. <p><input type="submit" name="login" value="Login" /></p>
  50. </form>
  51. </div>
  52. ENDOLA;
  53. printFooter();
  54. ?>