Guest User

Untitled

a guest
Oct 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. (function() {
  2. // create sub-namespace
  3. tms.security = {};
  4.  
  5. tms.security.readData = function(file) {
  6. // read data from file
  7. return 'a';
  8. };
  9.  
  10. tms.security.writeData = function(file, data) {
  11. // write data to file
  12. };
  13.  
  14. tms.security.compareData = function(user, pass) {
  15. // this is where a JSON request to server will go
  16. if ((user == 'a') && (pass == 'a')) {
  17. Ti.App.fireEvent('startCoSelect');
  18. } else {
  19. alert(L('invalidUSPS'));
  20. }
  21. };
  22.  
  23. tms.security.passwordEntry = function() {
  24. var tabs = Ti.UI.createTabGroup();
  25. var winPassword = Ti.UI.createWindow({
  26. title:L('password')
  27. });
  28. tabs.addTab(Ti.UI.createTab({
  29. title:L('password'),
  30. window:winPassword
  31. }));
  32. var txtUser = Titanium.UI.createTextField({
  33. color: '#336699',
  34. top: 10,
  35. left: Math.round(Ti.Platform.displayCaps.platformWidth * 0.05), // 5% of width
  36. width: Math.round(Ti.Platform.displayCaps.platformWidth * 0.9), // 90% od width
  37. height: 40,
  38. hintText: L('user'),
  39. keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
  40. returnKeyType: Titanium.UI.RETURNKEY_DEFAULT,
  41. borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
  42. });
  43. var txtPass = Titanium.UI.createTextField({
  44. color: '#336699',
  45. top: 60,
  46. left: Math.round(Ti.Platform.displayCaps.platformWidth * 0.05), // 5% of width
  47. width: Math.round(Ti.Platform.displayCaps.platformWidth * 0.9), // 90% od width
  48. height: 40,
  49. hintText: L('pass'),
  50. keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
  51. returnKeyType: Titanium.UI.RETURNKEY_DEFAULT,
  52. borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
  53. passwordMask: true
  54. });
  55. var btnLogin = Titanium.UI.createButton({
  56. title: L('login'),
  57. top: 110,
  58. width: 100,
  59. height: 40
  60. });
  61. var swtSave = Titanium.UI.createSwitch({
  62. value:false,
  63. top: 160
  64. });
  65. txtUser.addEventListener('return', function () {
  66. txtUser.blur()
  67. });
  68. txtPass.addEventListener('return', function () {
  69. txtPass.blur()
  70. });
  71. btnLogin.addEventListener("click", function (e) {
  72. if(swtSave.value == true) {
  73. /*var sep = Titanium.Filesystem.getSeparator();
  74. var dirHome = Titanium.Filesystem.getUserDirectory();
  75. var fileUser = Titanium.Filesystem.getFile(dirHome + sep + 'us.txt');
  76. var filePassword = Titanium.Filesystem.getFile(dirHome + sep + 'ps.txt');
  77. tms.security.writeData(fileUser, txtUser.value);
  78. tms.security.writeData(filePassword, txtPass.value);*/
  79. }
  80. tms.security.compareData(txtUser.value, txtPass.value);
  81. });
  82. winPassword.add(txtUser);
  83. winPassword.add(txtPass);
  84. winPassword.add(btnLogin);
  85. winPassword.add(swtSave);
  86. return tabs;
  87. };
  88.  
  89. tms.security.getPermission = function() {
  90. var tabs = tms.security.passwordEntry();
  91. /*var sep = Titanium.Filesystem.getSeparator();
  92. var dirHome = Titanium.Filesystem.getUserDirectory();
  93. var fileUser = Titanium.Filesystem.getFile(dirHome + sep + 'us.txt');
  94. var filePassword = Titanium.Filesystem.getFile(dirHome + sep + 'ps.txt');
  95. if(filePassword.exists() && fileUser.exists()) {
  96. // read files for data and compare
  97. tms.security.compareData(tms.security.readData(fileUser), tms.security.readData(filePassword));
  98. }*/
  99. return tabs;
  100. };
  101. })();
Add Comment
Please, Sign In to add comment