Advertisement
Guest User

JS

a guest
Feb 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements.  See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership.  The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License.  You may obtain a copy of the License at
  9.  *
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing,
  13.  * software distributed under the License is distributed on an
  14.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15.  * KIND, either express or implied.  See the License for the
  16.  * specific language governing permissions and limitations
  17.  * under the License.
  18.  */
  19. function init() {
  20. document.addEventListener("deviceready", deviceReady, true);
  21. delete init;
  22. }
  23.  
  24. function checkPreAuth() {
  25. var form = $("#loginForm");
  26. if(window.localStorage["username"] != undefined && window.localStorage["password"] != undefined) {
  27. $("#username", form).val(window.localStorage["username"]);
  28. $("#password", form).val(window.localStorage["password"]);
  29. handleLogin();
  30. }
  31. }
  32.  
  33. function handleLogin() {
  34. var form = $("#loginForm");
  35. //disable the button so we can't resubmit while we wait
  36. $("#submitButton",form).attr("disabled","disabled");
  37. var u = $("#username", form).val();
  38. var p = $("#password", form).val();
  39. console.log("click");
  40. if(u != '' && p!= '') {
  41. $.post("http://www.coldfusionjedi.com/demos/2011/nov/10/service.cfc?method=login&returnformat=json", {username:u,password:p}, function(res) {
  42. if(res == true) {
  43. //store
  44. window.localStorage["username"] = u;
  45. window.localStorage["password"] = p;
  46. $.mobile.changePage("sample.html");
  47. } else {
  48. navigator.notification.alert("Your login failed", function() {});
  49. }
  50. $("#submitButton").removeAttr("disabled");
  51. },"json");
  52. } else {
  53. //Thanks Igor!
  54. navigator.notification.alert("You must enter a username and password", function() {});
  55. $("#submitButton").removeAttr("disabled");
  56. }
  57. return false;
  58. }
  59.  
  60. function deviceReady() {
  61.  
  62. $("#loginForm").on("submit",handleLogin);
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement