MetaPhase-Consulting/State-TalentMAP

View on GitHub
public/login.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
  <title>TalentMAP Persona Selection</title>
  <style>
    a { font-size:1.5em; line-height: 3em; cursor: pointer; text-decoration: underline; color: blue }
    body { padding-left: 1.5em; }
  </style>
</head>
<body>
<div>
  <h1>Login</h1>
  <h2>Personas</h2>
  <ul>
    <li>
      <a OnClick="login('admin', 'admin');">Administrator</a>
    </li>
    <li>
      <a OnClick="login('shadtrachl', 'password');">Leah Shadtrach (CDO)</a>
    </li>
    <li>
      <a OnClick="login('townpostj', 'password');">Jenny Townpost (Bidder)</a>
    </li>
    <li>
      <a OnClick="login('rehmant', 'password');">Tarek Rehman (Bidder)</a>
    </li>
    <li>
      <a OnClick="login('woodwardw', 'password');">Wendy Woodward (Bureau)</a>
    </li>
    <li>
      <a OnClick="login('velezp', 'password');">Preston Velez (Post)</a>
    </li>
    <li>
      <a OnClick="login('lincolna', 'password');">Abigail Lincoln (GTM/AO)</a>
    </li>
    <li>
      <a OnClick="login('anthonyp', 'password');">Patrick Anthony (Panel Admin)</a>
    </li>
    <li>
      <a OnClick="login('andersons', 'password');">Stephanie Anderson (System Admin)</a>
    </li>
  </ul>
</div>
<div>
  <h2>Custom</h2>
  <form onsubmit="submitLogin(); return false;">
    <label for="username">Username</label>
    <input type="text" name="username" id="username" />
    <label for="password">Password</label>
    <input type="password" name="password" id="password" />
    <button type="submit">Submit</button>
  </form>
</div>
<script>
  config = {};

  function getConfig() {
    // create XMLHttpRequest
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        var myObj = JSON.parse(this.responseText);
        config = myObj;
      }
    };
    xhr.open("GET", "%PUBLIC_URL%/config/config.json", true);
    xhr.send();
  }
  getConfig();

  function login(username, password) {
    // create XMLHttpRequest
    var xhr = new XMLHttpRequest();
    xhr.open("POST", config.api_config.baseURL + "/accounts/token/");
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4) {
        // used to simulate the windows auth identification and token assignment
        localStorage.setItem("tmusrname", username);
        window.location.href = '%PUBLIC_URL%/tokenValidation?tmApiToken=' + JSON.parse(xhr.response).token
      }
    };

    xhr.send("username=" + username + "&password=" + password);
  }

  function submitLogin() {
    login(document.getElementById('username').value, document.getElementById('password').value);
  }
</script>
</body>
</html>