Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const baseUrl = 'https://baas.kinvey.com/';
  2. const appKey = 'kid_BJz94Cj1N';    
  3. const appSecret = 'aa1c91c934994554ae791884e07b2391';
  4.  
  5.  
  6. function makeAuth(type) {
  7.     return type === 'basic'
  8.         ? 'Basic ' + btoa(appKey + ':' + appSecret)
  9.         : 'Kinvey ' + sessionStorage.getItem('authtoken');
  10. }
  11.  
  12. function makeRequest(method, module, url, auth) {
  13.     return req = {
  14.         method,
  15.         url: baseUrl + module + '/' + appKey + '/' + url,
  16.         headers: {
  17.             Authorization: makeAuth(auth)
  18.         }
  19.     };
  20. }
  21.  
  22. function post(module, url, data, auth) {
  23.     let req = makeRequest('POST', module, url, auth);
  24.     req.data = JSON.stringify(data);
  25.     req.headers['Content-Type'] = 'application/json';
  26.     return $.ajax(req);
  27. }
  28.  
  29. let form = $('#formRegister');
  30.  
  31. let username = form.find('input[name="username"]').val();
  32. let password = form.find('input[name="passwd"]').val();
  33.  
  34.  
  35. let userInfo = await requester.post('user', '', {username, password},'basic');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement