1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-10 11:15:01 -05:00
mail/src/js/service/admin.js

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
var ngModule = angular.module('woServices');
ngModule.service('admin', Admin);
module.exports = Admin;
function Admin(adminRestDao) {
this._restDao = adminRestDao;
}
2014-10-02 16:05:44 -04:00
/**
* 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).
*/
2014-12-11 13:07:04 -05:00
Admin.prototype.createUser = function(options) {
var self = this;
return new Promise(function(resolve) {
if (!options.emailAddress || !options.password || !options.phone) {
throw new Error('Incomplete arguments!');
}
resolve();
2014-10-02 16:05:44 -04:00
2014-12-11 13:07:04 -05:00
}).then(function() {
return self._restDao.post(options, '/user');
2014-10-02 16:05:44 -04:00
2014-12-11 13:07:04 -05:00
}).catch(function(err) {
2014-10-02 16:05:44 -04:00
if (err && err.code === 409) {
2014-12-11 13:07:04 -05:00
throw new Error('User name is already taken!');
}
throw new Error('Error creating new user! Reason: ' + err.message);
2014-10-02 16:05:44 -04:00
});
};
/**
* 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.
*/
2014-12-11 13:07:04 -05:00
Admin.prototype.validateUser = function(options) {
var self = this;
return new Promise(function(resolve) {
if (!options.emailAddress || !options.token) {
throw new Error('Incomplete arguments!');
}
resolve();
2014-10-02 16:05:44 -04:00
2014-12-11 13:07:04 -05:00
}).then(function() {
var uri = '/user/validate';
return self._restDao.post(options, uri);
2014-10-02 16:05:44 -04:00
2014-12-11 13:07:04 -05:00
}).catch(function(err) {
if (err && err.code === 202) {
2014-10-02 16:05:44 -04:00
// success
2014-12-11 13:07:04 -05:00
return;
2014-09-19 12:59:13 -04:00
}
2014-12-11 13:07:04 -05:00
throw new Error('Validation failed! Reason: ' + err.message);
2014-10-02 16:05:44 -04:00
});
};