login.template 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <script>
  2. {{#if key}}
  3. back();
  4. {{/if}}
  5. </script>
  6. <form id="form" style="display:none;">
  7. <input name="username" autocomplete="off" class="fill-width" placeholder="Username" id="login-username" type="text"/>
  8. <input id="login-password" class="fill-width" placeholder="Password" name="password" type="password"/>
  9. <button value="Cancel" class="danger">Cancel</button>
  10. <button value="Login" onclick="$(this).parent().submit();">Login</button>
  11. </form>
  12. <script>
  13. {{#unless key}}
  14. $(document).ready(function(){
  15. $('form#form').show().submit(function(){
  16. var data = $(this).serializeObject(),
  17. State = History.getState();
  18. for(var i in State.data){
  19. data[i] = State.data;
  20. }
  21. data.type = 'action';
  22. data.id = 'login';
  23. apiCall(data,function(d){
  24. if(!exists(d.error) && exists(d.key)){
  25. setKey(d.key);
  26. notify('login','You have logged in successfully');
  27. back(true);
  28. }else{
  29. setKey(null);
  30. $('#loading').hide();
  31. if(!exists(d.error)){
  32. alert('Error communicating with the server');
  33. }
  34. }
  35. return false;
  36. });
  37. return false;
  38. }).find('.danger').click(function(){
  39. back(true);
  40. return false;
  41. }).parent().find('input').keypress(function(e){
  42. if(e.which == 13){
  43. $('form#form').submit();
  44. return false;
  45. }
  46. });
  47. });
  48. {{/unless}}
  49. </script>