Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. UsernameScreen.tvml:
  2.  
  3. <?xml version="1.0" encoding="UTF-8" ?>
  4. <document
  5.   data-view="LoginScreen"
  6.   data-next="templates/PasswordScreen.tvml">
  7.   <head>
  8.     <style>
  9.       .ass-button {
  10.         margin: 0 0 10px 0;
  11.       }
  12.     </style>
  13.   </head>
  14.   <formTemplate>
  15.     <banner>
  16.       <img src="${CONFIG.configURL}/${CONFIG.splashScreen}"
  17.     width="1920" height="1080" />
  18.       <description>Enter email</description>
  19.     </banner>
  20.     <textField id="username">Username</textField>
  21.     <footer >
  22.       <button class="ass-button" id="next">
  23.         <text>Next</text>
  24.       </button>
  25.       <button class="ass-button" id="back">
  26.         <text>Back</text>
  27.       </button>
  28.     </footer>
  29.   </formTemplate>
  30. </document>
  31.  
  32. PasswordScreen.tvml
  33. <?xml version="1.0" encoding="UTF-8" ?>
  34. <document
  35.   data-view="PasswordScreen">
  36.   <head>
  37.     <style>
  38.       .ass-button {
  39.         margin: 0 0 10px 0;
  40.       }
  41.     </style>
  42.   </head>
  43.   <formTemplate>
  44.     <banner>
  45.       <img src="${CONFIG.configURL}/${CONFIG.splashScreen}"
  46.     width="1920" height="1080" />
  47.       <description>Enter password</description>
  48.     </banner>
  49.     <textField name="password" secure="true">******</textField>
  50.     <footer>
  51.       <button class="ass-button" id="login">
  52.         <text>Login</text>
  53.       </button>
  54.       <button class="ass-button" id="back">
  55.         <text>Back</text>
  56.       </button>
  57.     </footer>
  58.   </formTemplate>
  59. </document>
  60.  
  61. LoginScreen.js
  62. ViewManager.registerView("LoginScreen", function(doc) {
  63.  
  64.   var document = doc.ownerDocument;
  65.   var nextScreen = doc.firstChild.getAttribute("data-next");
  66.   var backScreen = "templates/index.tvml"
  67.  
  68.   var userField = document.getElementsByTagName('textField').item(0);
  69.   var userKey = userField.getFeature("Keyboard");
  70.  
  71.   var username = '';
  72.  
  73.   userKey.onTextChange = function(event) {
  74.    User.username = userKey.text;
  75.   }
  76.  
  77.   var loader = new TemplateLoader();
  78.  
  79.   function nextFunction(event) {  
  80.  
  81.     if (User.username) {
  82.       loader.load(nextScreen, displayNextPage);
  83.     } else {
  84.       console.log("username???")
  85.     }
  86.  
  87.   }
  88.  
  89.  
  90.   function backFunction(event) {  
  91.  
  92.     loader.load(backScreen, displayNextPage);
  93.   }
  94.  
  95.   function displayNextPage(newDoc) {
  96.  
  97.     if (newDoc) {
  98.       nextDoc = newDoc;
  99.     }
  100.  
  101.     if ( nextDoc) {
  102.       navigationDocument.replaceDocument(nextDoc, doc);
  103.     }
  104.  
  105.   }
  106.  
  107.   document
  108.     .getElementById('next')
  109.     .addEventListener('select', nextFunction);
  110.  
  111.   document
  112.     .getElementById('back')
  113.     .addEventListener('select', backFunction);  
  114.  
  115. });
  116.  
  117.  
  118. PasswordScreen.js
  119. ViewManager.registerView("PasswordScreen", function(doc) {
  120.   //todo : setting constants
  121.   var urlLogin = BASE + '/apiserver/user-login';
  122.  
  123.  
  124.   var document = doc.ownerDocument;
  125.   var loader = new TemplateLoader();
  126.   var xhr = new XMLHttpRequest();
  127.  
  128.   var invCred = 'templates/InvalidCredentialsAlert.tvml';
  129.   var passField = document.getElementsByTagName('textField').item(0);
  130.   var passKey = passField.getFeature("Keyboard");
  131.  
  132.   var backScreen = "templates/UsernameScreen.tvml"
  133.  
  134.   passKey.onTextChange = function(event) {
  135.     User.password = passKey.text;
  136.   }
  137.  
  138.   xhr.open("POST", urlLogin);
  139.  
  140.   xhr.onload = function() {
  141.  
  142.     var response = JSON.parse(xhr.response);
  143.     if (response.status === false) {
  144.       Login = "Login";
  145.       //CAN BE A POPUP!!!
  146.       loader.load(invCred, displayNextPage);
  147.     } else {
  148.  
  149.       User.premium =  response.premium;
  150.       User.roles = response.user.roles;
  151.     }
  152.   }
  153.  
  154.   function displayNextPage(newDoc) {
  155.  
  156.     if (newDoc) {
  157.       nextDoc = newDoc;
  158.     }
  159.  
  160.     if ( nextDoc) {
  161.       navigationDocument.replaceDocument(nextDoc, doc);
  162.     }
  163.  
  164.   }
  165.  
  166.   function backFunction(event) {  
  167.  
  168.     loader.load(backScreen, displayNextPage);
  169.   }
  170.  
  171.  
  172.   document
  173.     .getElementById('login')
  174.     .addEventListener('select', function(event) {  
  175.  
  176.       if (User.password) {
  177.  
  178.         xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  179.         xhr.send("username="+User.username+"&password="+User.password+"&appIdentifier="+ User.appIdentifier);
  180.        
  181.       } else {
  182.         console.log("PASSWORD???")
  183.       }
  184.  
  185.     });  
  186.  
  187.   document
  188.     .getElementById('back')
  189.     .addEventListener('select', backFunction);  
  190.  
  191.  
  192. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement