Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. function login(){
  2.  
  3. var login = document.getElementById('login').value;
  4. var pass = document.getElementById('pass').value;
  5.  
  6. //Get oAuth Token Step 1.
  7. $.ajax({
  8. url: url + 'oauth2/token/',
  9. type: 'post',
  10. data: {'grant_type': 'password',
  11. 'client_id' : clientID,
  12. 'client_secret': clientSecret,
  13. 'username': login,
  14. 'password': pass,},
  15. headers: { "Content-Type":'application/x-www-form-urlencoded' },
  16. contentType: 'application/x-www-form-urlencoded',
  17. success: function (data) {
  18.  
  19. log('Login Successful');
  20. log("Set: " + url);
  21.  
  22.  
  23.  
  24. chrome.storage.sync.set({
  25. pass: pass,
  26. login_name: login,
  27. logged: 'true',
  28. }, function() {
  29.  
  30. setTimeout(function() {
  31. status.textContent = '';
  32. }, 750);
  33.  
  34. save();
  35. setDisplayMode();
  36.  
  37. });
  38.  
  39. },
  40. error: function(xhr, exception){
  41.  
  42. if(xhr.status == 400 || xhr.status == 403){
  43.  
  44. log(xhr);
  45. log(exception);
  46. invalidLogin();
  47. return "Invalid Credentials";
  48. }
  49. },
  50. });
  51.  
  52. }
  53.  
  54. /**
  55. * Query and store user data to chrome.storage
  56. */
  57. function save() {
  58. var login = '';
  59. var pass = '';
  60.  
  61. //Get oAuth Token Step 1.
  62. chrome.storage.sync.get({
  63. pass: '',
  64. login_name: '',
  65. }, function(items){
  66. login = items.login_name;
  67. pass = items.pass;
  68.  
  69. $("#result").html("<img width='20px' src='loading.gif'>");
  70. $.ajax({
  71. url: url + 'oauth2/token/',
  72. type: 'post',
  73. data: {'grant_type': 'password',
  74. 'client_id' : clientID,
  75. 'client_secret': clientSecret,
  76. 'username': login,
  77. 'password': pass,},
  78. headers: { "Content-Type":'application/x-www-form-urlencoded' },
  79. contentType: 'application/x-www-form-urlencoded',
  80. success: function (data) {
  81.  
  82. var user = login.split('@')[0];
  83. //oAuth Step 2
  84. $.ajax({
  85. url: url,
  86. type: 'post',
  87. data: {
  88. 'action': 'read',
  89. 'object': 'subscriber',
  90. 'login': login,
  91. },
  92. headers: {
  93. 'Authorization': 'Bearer ' + data.access_token
  94. },
  95. success: function (data) {
  96. log(data);
  97. user = $(data).find("user").text()
  98.  
  99. $('#login_name').html(login);
  100. $('#extension').html($(data).find("user").text());
  101. $('#domain_name').html($(data).find("domain").text());
  102. var areaCode = $(data).find("area_code").text();
  103. document.getElementById("area_code").value = areaCode ;
  104. $("#result").html("SIP Username: " + user + "<br>Area Code: " + areaCode);
  105. chrome.storage.sync.set({
  106. user: $(data).find("user").text(),
  107. domain: $(data).find("domain").text(),
  108. dialstring_length: document.getElementById('dialstring_length').value,
  109. intl_prefix: document.getElementById("intl_prefix").value,
  110. country_initials: document.getElementById("country_code")
  111. [document.getElementById("country_code").selectedIndex]
  112. .getAttribute('country_initials'),
  113. country_code: document.getElementById("country_code").value,
  114. areacode: areaCode,
  115. use_list: $("input.use_list:checked").val(),
  116. logged: 'true'
  117. }, function() {
  118.  
  119. // Update status to let user know options were saved.
  120. var status = document.getElementById('status');
  121. status.textContent = 'Options saved.';
  122. log('Save Successful');
  123.  
  124. status.textContent = '';
  125. setDisplayMode();
  126.  
  127. });
  128. },
  129. error: function(xhr, exception){
  130.  
  131. chrome.storage.sync.set({
  132. logged: 'false'
  133. });
  134. if(xhr.status == 400 || xhr.status == 403){
  135.  
  136. alert("Invalid Credentials");
  137. $("#result").html("Invalid Credentials");
  138. }
  139. },
  140. });
  141.  
  142. },
  143. error: function(xhr, exception, third){
  144.  
  145. if(xhr.status == 400 || xhr.status == 403){
  146.  
  147. log(xhr);
  148. log(exception);
  149. log(third);
  150. invalidLogin();
  151. return "Invalid Credentials";
  152. }
  153. },
  154. });
  155.  
  156. });
  157.  
  158. }
  159.  
  160. /**
  161. * Query and store user data to chrome.storage
  162. */
  163. function save() {
  164. var login = '';
  165. var pass = '';
  166.  
  167. //Get oAuth Token Step 1.
  168. chrome.storage.sync.get({
  169. pass: '',
  170. login_name: '',
  171. }, function(items){
  172. login = items.login_name;
  173. pass = items.pass;
  174.  
  175. $("#result").html("<img width='20px' src='loading.gif'>");
  176. $.ajax({
  177. url: url + 'oauth2/token/',
  178. type: 'post',
  179. data: {'grant_type': 'password',
  180. 'client_id' : clientID,
  181. 'client_secret': clientSecret,
  182. 'username': login,
  183. 'password': pass,},
  184. headers: { "Content-Type":'application/x-www-form-urlencoded' },
  185. contentType: 'application/x-www-form-urlencoded',
  186. success: function (data) {
  187.  
  188. var user = login.split('@')[0];
  189. //oAuth Step 2
  190. $.ajax({
  191. url: url,
  192. type: 'post',
  193. data: {
  194. 'action': 'read',
  195. 'object': 'subscriber',
  196. 'login': login,
  197. },
  198. headers: {
  199. 'Authorization': 'Bearer ' + data.access_token
  200. },
  201. success: function (data) {
  202. log(data);
  203. user = $(data).find("user").text()
  204.  
  205. $('#login_name').html(login);
  206. $('#extension').html($(data).find("user").text());
  207. $('#domain_name').html($(data).find("domain").text());
  208. var areaCode = $(data).find("area_code").text();
  209. document.getElementById("area_code").value = areaCode ;
  210. $("#result").html("SIP Username: " + user + "<br>Area Code: " + areaCode);
  211. chrome.storage.sync.set({
  212. user: $(data).find("user").text(),
  213. domain: $(data).find("domain").text(),
  214. dialstring_length: document.getElementById('dialstring_length').value,
  215. intl_prefix: document.getElementById("intl_prefix").value,
  216. country_initials: document.getElementById("country_code")
  217. [document.getElementById("country_code").selectedIndex]
  218. .getAttribute('country_initials'),
  219. country_code: document.getElementById("country_code").value,
  220. areacode: areaCode,
  221. use_list: $("input.use_list:checked").val(),
  222. logged: 'true'
  223. }, function() {
  224.  
  225. // Update status to let user know options were saved.
  226. var status = document.getElementById('status');
  227. status.textContent = 'Options saved.';
  228. log('Save Successful');
  229.  
  230. status.textContent = '';
  231. setDisplayMode();
  232.  
  233. });
  234. },
  235. error: function(xhr, exception){
  236.  
  237. chrome.storage.sync.set({
  238. logged: 'false'
  239. });
  240. if(xhr.status == 400 || xhr.status == 403){
  241.  
  242. alert("Invalid Credentials");
  243. $("#result").html("Invalid Credentials");
  244. }
  245. },
  246. });
  247.  
  248. },
  249. error: function(xhr, exception, third){
  250.  
  251. if(xhr.status == 400 || xhr.status == 403){
  252.  
  253. log(xhr);
  254. log(exception);
  255. log(third);
  256. invalidLogin();
  257. return "Invalid Credentials";
  258. }
  259. },
  260. });
  261.  
  262. });
  263.  
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement