Created
September 1, 2016 15:42
-
-
Save jackbravo/6a06e99ec409e2cc537afdce57c2df90 to your computer and use it in GitHub Desktop.
Registrar un usuario en drupal usando jQuery y REST, cortesía de @jmruvalcabav
This file contains 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
var user = { | |
_links: { | |
type: { | |
href: 'http://192.168.100.106:81/rest/type/user/user' | |
} | |
}, | |
name:[{'value':'user'}], | |
pass:[{'value':'pass'}], | |
status:[{'value':true}], | |
mail:[{'value':'example@example.com'}], | |
langcode:[{'value':'en'}], | |
roles:[{'target_id':'editor','target_type':'user_role'}], | |
field_publication:[{"target_id":"1","target_type":"taxonomy_term","url":"http://192.168.100.106:81/taxonomy/term/1"}] | |
//field_prueba:[{"value":"prueba"}] | |
//user_picture:[{ "target_id":"2354"}] | |
}; | |
jQuery.ajax({ | |
url: 'http://192.168.100.106:81/entity/user', | |
method: 'POST', | |
headers: { | |
authorization: 'Basic YWRtaW46YWRtaW4x', // user:pass base64 | |
'Content-Type': 'application/hal+json' }, | |
'data': JSON.stringify(user) | |
, | |
success: function (response) { | |
//Response | |
console.log("Response:"); | |
console.log(response); | |
}, | |
error: function (error){ | |
//Error | |
console.log("Error:"); | |
console.log(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment