new AuthAPI($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 'sfauth' module.'
//
angular.module('sfauth', [])
     // inject API as a service
     .service('SFauthApi', ['$rootScope', '$http', AuthAPI]) 
     .controller('SFauthCtrl', AuthCtrl)
 .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

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

Authenticate a user based upon username/password or an accessid provided by the SmartFlo system.

Example

function authenticate(userid, userpassword) {
     var params {
         username: userid,
         userpwd: userpassword
     };
     // alternately:
     // var params {
     //      40 character hash - 
     //      e.g., '4a9fe33129e58339Ba99af16dec8bf6b72975fd6'
     //      accessid: [SmartFlo™ accessid]
     // };
     SFauthApi.authenticate(params, handleAuthentication);
}

function handleAuthentication(credential) {
     if ('0' === credential.status) {
         $scope.$emit(SF_EVENTS().LOGIN_SUCCESS, credential);
     } else {
         $scope.$emit(SF_EVENTS().LOGIN_FAILURE, credential);
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
}

Parameters

Name Type Optional Description

params

object

 

An object providing either a userid

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 that contains a credential object providing the user's access permissions. For conveniance, this method also implicitly assigns this same credential object to global scope using a $rootScope.credential field.


var result {
     status: 0,
     statusMessage: "auth.no.errors", 
     api: "auth::post::users::passwords", // name of the call
     date: [Date object providing time call was made]
     credential: userCredential
};

var userCredential { status: 0, statusMessage: "auth.no.errors", api: "auth::post::users", // name of the call date: [Date object providing time call was made], token: "694b", // accessid token userid: [SmartFlo™ userid], username: [SmartFlo™ user name], userGroups: [Array of SmartFlo™ groups that the user belongs to], affiliate: [SmartFlo™ affiliate of user], isPrivateCommentsUser: [true or false], // whether or not the user can access private comments isVproofUser: [true or false], // whether or not the user can access online Viki Proofing isReviewStudioUser: [true or false] //whether or not the user can access online ReviewStudio Proofing };

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

Change a user's password.

Note: this method for changing a password requires that the user be logged into the SmartFlo™ system.

Example

function changePassword(newpassword) {
     var params = {
         newpwd: newpassword
     };
     SFauthApi.changePassword(params, handleChangePassword);
}

function handleChangePassword(result) {
     // '0' is success
     if ('0' === status) {
         $scope.passwordChangeSuccessful = true;
     } else {
         $scope.passwordChangeSuccessful = false;
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
}

Parameters

Name Type Optional Description

params

object

 

An object providing the new password.

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. status, statusMessage, api and date.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.


var result {
     status: 0,
     statusMessage: "auth.no.errors", 
     api: "auth::post::users::passwords", // name of the call
     date: [Date object providing time call was made]
};

getPanAffiliates(successHandler[, failureHandler]) → object

Retrieves the complete list of affiliates to which the user has access. Affiliates are hierarchically ordered so the user's affiliate can have child affiliates and each of its children affiliates can have thier own children affiliates and so on. The Array(string) returned is a flat list however, with none of the hierarchical relationsships shown.

Example

function getPanAffiliates() {
     SFauthApi.getPanAffiliates(handleGetPanAffiliates);
}

function handleGetPanAffiliatesd(result) {
     // '0' is success
     if ('0' === result.status) {
         $scope.panAffiliates = result.panAffiliates;
     } else {
         $scope.panAffiliates = [];
         $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.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.

var result {
     status: 0,
     statusMessage: "auth.no.errors", 
     api: "auth::get::panaffiliates", // name of the call
     date: [Date object providing time call was made],
     panAffiliates: [Array of user accessible pan-affiliates]
};

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

Resets a user's password. This method for changing a password emails a secure URL to the requesting user that contains a "one-time' hash-token. When this link is followed, a Change Password screen is displayed that permits the user to change their password.

Note: this method can be used without first logging into the SmartFlo™ system.

Example

function resetPassword(useridoremail) {
     var params = {
         useroremail: useridoremail
     };
     SFauthApi.resetPassword(params, handleResetPassword);
}

function handleResetPassword(result) {
     // '0' is success
     if ('0' === result.status) {
         $scope.passwordResetSuccessful = true;
     } else {
         $scope.passwordResetSuccessful = false;
         $scope.errorCode = result.status;
         $scope.errorMessage = result.statusMessage;
     }
}

Parameters

Name Type Optional Description

params

object

 

An object providing either the user's SmartFlo™ userid or the user's SmartFlo™ 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.

Throws

(string) "missing.callback.exception"

$http errors

Returns

object A result object.

var result {
     status: 0,
     statusMessage: "auth.no.errors", 
     api: "auth::post::resetpasswords", // name of the call
     date: [Date object providing time call was made]
};