Skip to content

Instantly share code, notes, and snippets.

@BenGitsCode
Created January 20, 2017 03:11
Show Gist options
  • Save BenGitsCode/4e1bdee257cd0cfd727cefb7717030db to your computer and use it in GitHub Desktop.
Save BenGitsCode/4e1bdee257cd0cfd727cefb7717030db to your computer and use it in GitHub Desktop.
Scaffold Sample user AJAX requests
'use strict';
const app = require('../app-data');
const signIn = (success, failure, data) => {
$.ajax({
method: "POST",
url: app.server.api + '/sign-in',
data,
})
.done(success, data)
.fail(failure);
};
const signUp = (success, failure, data) => {
$.ajax({
method: "POST",
url: app.server.api + '/sign-up',
data,
})
.done(success, data)
.fail(failure);
};
const signOut = (success, failure, data) => {
$.ajax({
method: "DELETE",
url: app.server.api + '/sign-out/' + app.currentUser.id,
data,
headers: {
Authorization: 'Token token='+ app.currentUser.token,
},
})
.done(success)
.fail(failure);
};
const changePass = (success, failure, data) => {
// if (!app.currentUser) bad;
$.ajax({
method: "PATCH",
url: app.server.api + '/change-password/' + app.currentUser.id,
data,
headers: {
Authorization: 'Token token='+ app.currentUser.token,
},
})
.done(success)
.fail(failure);
};
module.exports = {
signUp,
signIn,
signOut,
changePass,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment