1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-13 12:45:04 -05:00
mail/src/js/dao/admin-dao.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
var AdminDAO = function(restDao) {
this._restDao = restDao;
};
/**
* Create a new email account.
* @param {String} options.emailAddress The desired email address
* @param {String} options.password The password to be used for the account.
* @param {String} options.phone The user's mobile phone number (required for verification and password reset).
* @param {Function} callback(error)
*/
AdminDAO.prototype.createUser = function(options, callback) {
var uri;
if (!options.emailAddress || !options.password || !options.phone) {
callback(new Error('Incomplete arguments!'));
return;
}
uri = '/user';
this._restDao.post(options, uri, function(err) {
if (err && err.code === 409) {
callback(new Error('User name is already taken!'));
return;
} else if (err) {
callback(new Error('Error creating new user!'));
return;
}
2014-10-02 16:05:44 -04:00
callback();
});
};
/**
* Verify a user's phone number by confirming a token to the server.
* @param {String} options.emailAddress The desired email address
* @param {String} options.token The validation token.
* @param {Function} callback(error)
*/
AdminDAO.prototype.validateUser = function(options, callback) {
var uri;
if (!options.emailAddress || !options.token) {
callback(new Error('Incomplete arguments!'));
return;
}
uri = '/user/validate';
this._restDao.post(options, uri, function(err) {
if (!err || (err && err.code === 202)) {
// success
callback();
2014-10-02 16:05:44 -04:00
} else {
callback(new Error('Validation failed!'));
2014-09-19 12:59:13 -04:00
}
2014-10-02 16:05:44 -04:00
});
};
2014-09-19 12:59:13 -04:00
2014-10-08 06:34:34 -04:00
module.exports = AdminDAO;