Last active
December 12, 2015 07:09
-
-
Save astrotars/4734800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // you'll need to base64 encode the autho header before passing it to the server. | |
| // it's a fairly complex process outside of node, so i'd recommend using this webtoolkit.base64.js @ http://cl.ly/code/0N332C2e1D34 | |
| // to create your encoded header, do something like this: | |
| <script src="webtoolkit.base64.js"></script> | |
| var auth = 'Basic ' + Base64.encode('5IUl3fKao5' + ':' + '426LJy7887QzxC2VG434UmZl2d4brc54'); | |
| // client object | |
| var clientObj = { | |
| name: 'Client Name', | |
| phone: '303-442-2542' // format phone client side? | |
| } | |
| // user object | |
| var userObj = { | |
| first_name: 'Nick', | |
| last_name: 'Parsons', | |
| email: 'nick@movementstrategy.com', | |
| password: 'Movement456', // >= 6 chars | |
| } | |
| // create client | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'https://' + Global.Server + '/clients', | |
| headers: { | |
| Authorization: auth | |
| }, | |
| contentType: 'application/json', | |
| data: JSON.stringify(clientObj), | |
| success: function(client, textStatus, jqXHR) { | |
| console.log('client', client); | |
| // handle success / error messages | |
| // set client id in user object | |
| userObj.clients = [client._id]; // clients is an array of client id's | |
| // create user | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'https://' + Global.Server + '/users', | |
| headers: { | |
| Authorization: auth | |
| }, | |
| contentType: 'application/json', | |
| data: JSON.stringify(userObj), | |
| success: function(user, textStatus, jqXHR) { | |
| console.log('user', user); | |
| // handle success / error messages | |
| } | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment