-
Notifications
You must be signed in to change notification settings - Fork 34
Working with users
SwellRT sessions are user connections with the server both named or anonymous.
In the first case you will be able to perform the following actions:
Use the createUser()
method to create new accounts in a SwellRT server.
SwellRT.createUser(
// Parameters
{
id: "elvis",// (Required) the user id
password: "_password_", // (Optional)
email: "[email protected]", // (Optional) an email address
locale: "en_GB", // (Optional) the locale
avatarData: "data:image/png;base64,iVBORw0K (...)", // (Optional) a Base64 image
},
// onComplete callback
function(res) {
if (res.error) {
if (res.error == "ACCOUNT_ALREADY_EXISTS") {
}
console.log(error);
} else if (res.data) {
// data.avatarUrl = (relative path) '/swell/account/elvis/avatar/<filename>.png'
// data.email
}
});
Update the profile data of the current logged in user. To change the user's password see the setPassword(...)
function.
SwellRT.updateUserProfile(
// Parameters
{
email: "[email protected]", // (Optional) an email address
locale: "en_GB", // (Optional) the locale
avatarData: "data:image/png;base64,iVBORw0K (...)", // (Optional) a Base64 image
},
// onComplete callback
function(res) {
if (res.error) {
console.log(error);
} else if (res.data) {
// data.avatarUrl = (absolute path) 'http://api.swellrt.org/swell/account/elvis/avatar/<filename>.png'
// data.email
}
});
To delete any value, update with empty value, e.g. avatarData : ""
.
Profile data from the current logged in user can be get using following method:
SwellRT.getUserProfile(
// onComplete callback
function(res) {
if (res.error) {
console.log(error);
} else if (res.data) {
// data.avatarUrl
// data.email
// data.locale
}
});
To get the profile data of a list of provided users use the following method:
SwellRT.getUserProfile(
['[email protected]', '[email protected]', ... ],
// onComplete callback
function(res) {
if (res.error) {
console.log(error);
} else if (res.data) {
// data = array of profile data
}
});
There are two ways of changing an user password.
If an user has lost her password but has set an email address, an email with a customizable recover password URL can be sent to the email address with the following command:
SwellRT.recoverPassword('[email protected]','http://myappserver.net/recovery?token=$token&user-id=$user-id', function(success){console.log('success', success)}, function(error){console.log('error', error)});
where the second parameter is an arbitrary url where $token and $user-id will be replaced by the actual recovery secret token and the user id
then, the token passed through the url can be used to set a new password:
SwellRT.setPassword("<user-id>","<the-token>", "<new-password>", function(success){console.log('success', success)}, function(error){console.log('error', error)});
Also, a password can be changed passing the current password:
SwellRT.setPassword("<user-id>","<old-password>", "<new-password>", function(success){console.log('success', success)}, function(error){console.log('error', error)});
Texts and images of the SwellRT Wiki are released as open content, under the Creative Commons Attribution 4.0 International.