new UsersAPI($rootScope, $http)

Warning! The SmartFlo™ APIs assume 2 global variables are set in $rootScope prior to using the APIs:

  1. $rootScope.credential
  2. set implicitely by the AuthAPI class upon success of the authenticate method
  3. $rootScope.site
  4. set by the calling application to the
    domain (e.g., www.smartflo.biz) or IP address of the target SmartFlo™ system, possibly when initializing the module that declares an API service

Example

//
// Warning! The global '$rootScope.site' field value must be set 
// to the target SmartFlo™ domain prior to using theSmartFlo™ APIs. In this 
// example it is set by the configuration block of the 'SFusersApi' 
// module.
//
angular.module('sf-users', [])
     // inject API as a service
     .service('SFusersApi', ['$rootScope', '$http', UsersAPI])
     .controller('SFUsersCtrl', UsersCtrl);
     .run(function ($rootScope, $location) { 
     // store the site for use by APIs
         $rootScope.site = $location.host();
         if ($location.port !== null & $location.port !== 80) {
         $rootScope.site += ':' + $location.port().toString();
    }
});

Parameters

Name Type Optional Description

$rootScope

object

 

The topmost parent scope in AngularJS.

$http

service

 

The core AngularJS service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

Copyright
© Chalex Corp. 2002 - 2017. All rights reserved.
Returns

class A constructor that will be instantiated.

Methods

deleteUser(params, successHandler[, failureHandler]) → object

Deletes a user from the system, this will set their status to ACCOUNT_DELETED preventing them from appearing as a result in any getUser() type calls.

Example

$scope.deleteUser = function() {
    var params = {
        userid: $scope.userID     
    };
    usersApi.deleteUser(params, deleteUserHandler);                
};
function deleteUserHandler(result){
    if (result.status === '0'){
        console.log("user deleted: " + $scope.userID);
        var msg = $translate.instant('user.deleted');
        $scope.feedbackMessage = msg;
        setTimeoutMessage();
        $scope.refreshUsers();
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }
}

Parameters

Name Type Optional Description

params

object

 

An object providing the userid for the user selected for deletion.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::delete::userregistrations,
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
};

getAffiliates(successHandler[, failureHandler]) → object

Retrieves a list of affiliates.

Example

usersApi.getAffiliates(getAffiliatesHandler);

function getAffiliatesHandler(result) {
    if (result.status === '0'){
        $scope.affiliates = result.affiliates;
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }
}

Parameters

Name Type Optional Description

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::affiliates,
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors",
     affiliates: [an array of strings]
};

getUserRegistrations(successHandler[, failureHandler]) → object

Retrieves a list of registered users as an array of objects with each element containing a set of fields for an individual user. These fields include the affiliate, email, status, user id, and name.

Example

usersApi.getUserRegistrations(getUserRegistrationsHandler);

function getUserRegistrationsHandler(result) {
    if (result.status === '0'){
        setUserData(result.userRegistrations);
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage;
    }
}

Parameters

Name Type Optional Description

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::get::userregistrations", // name of the call
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
     userRegistrations: [an array of objects describing user registration information

           - e.g., object1 {  affiliate: [the affiliate this user is a member of]
                              user_email: [the users email]
                              user_status: [current status of the user, either ACCOUNT_ACTIVE, ACCOUNT_SUSPENDED or ACCOUNT_DELETED]
                              userid: [the users id]
                              username: [the users name] 
                           }]

};

postAddUser(params, successHandler[, failureHandler]) → object

Registers a new user in a selected affiliate.

Example

$scope.registerUser = function(username, userid, useremail, affiliatepassword) {
    var param = {
           username: username,
           userid: userid,
           useremail: useremail,
           affiliate: $scope.affiliate,
           affiliatepassword: affiliatepassword
    };
    usersApi.postAddUser(params, registerUserHandler);
};

function registerUserHandler(result){
    if (result.status === '0'){
       $scope.msg = $translate.instant('user.registered');
       $scope.feedbackMessage = msg;
    } else {
        $scope.errorCode = result.status;
        $scope.errorMessage = result.statusMessage; 
    }
}

Parameters

Name Type Optional Description

params

object

 

An object providing the username, userid, useremail, affiliate, and affiliatepassword that is necessary to register a user in the system.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::post::userregistrations, 
     date: [Date object providing time call was made],
     status: '0',
     statusMessage: "adm.no.errors"
};

postChangeEmail(params, successHandler[, failureHandler]) → object

Changes a user's email address.

Example

$scope.changeEmail = function(newemail) {
     var param = {
         userid: $scope.userID,
         newemail: newemail
     };
     usersApi.postChangeEmail(param, changeEmailHandler);
 };

function changeEmailHandler(result){
     if (result.status === '0'){
         var msg = $translate.instant('user.email.changed');
         $scope.feedbackMessage = msg;
     } else {
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
 }

Parameters

Name Type Optional Description

params

object

 

An object providing the userid and email that is necessary to change a users email address.

successHandler

function()

 

A function that is called back upon success.

failureHandler

function()

Yes

An optional function that is called back upon failure. If none is specified, the success callback is called with failure data. On failure however, the only valid fields returned are: status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


result {
     api: "adm::post::userregistrations",
     date: [Date object providing time call was made], 
     status: '0',
     statusMessage: "adm.no.errors"
};