/* login.js
   
   This file is part of arena.

   arena is free software: you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License or, at your
   option, any later version.

   arena is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABLITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.

   You should have received a copy of the GNU General Public License along
   with arena.  If not, see <http://www.gnu.org/licenses/>.
*/

/* This file defines a utility class for user authentication.
*/

// User namespace
var User = {};

// Submit the specified form
User.submitUserName = function(thisForm, url) {
  if ( Form.valid(thisForm) ) {
    url += "?username=" + escape(thisForm.elements["username"].value);
    var LoginPost = new APost(1);
    LoginPost.fetch(url);
  }
  return false;
}

// Submit the specified form
User.submitCredentials = function(thisForm) {
  if ( Form.valid(thisForm) ) {
    // Prevent passwords from being sent in the clear
    if ( (thisForm.elements["password1"]) && (thisForm.elements["password2"]) && (thisForm.elements["password3"]) ) {
      thisForm.elements["pwd"].value = Sha256.hash(thisForm.elements["password1"].value + "+" + thisForm.elements["password2"].value + "+" + thisForm.elements["password3"].value);
      thisForm.elements["password1"].value = "";
      thisForm.elements["password2"].value = "";
      thisForm.elements["password3"].value = "";
      return true;
    }
  }
  return false;
}

