UGC Website Users API

Follow

The user profile API provides the ability to interact with the User Content section of User Generated Content without having to custom code standard usage scenarios. The user profile API provides simple authentication, authentication validation and password reset.

The API is available in the WCF API and REST API.

Methods

Authenticate(string profileTypeName, string login, string password)
The Authenticate method is used to authorize a user against a particular User Content Profile Type. For this method to work it is required that there exists a field marked as a login field and a field marked as a password field within the user profile record type.
 
IsAuthenticated(string authenticationToken, string profileRecordType)
The IsAuthenticated Method is used to check a Authentication token that was generated with the Authenticate method. The result that is returned is a fully qualified DataServiceAuthorization object which can be used to authenticate with the UGC API on behalf of the currently logged in user.
 
ChangePassword(int profileRecordID, string currentPassword, string newPassword)
The ChangePassword method is used to change a current users password. This method requires a valid users profileRecordID and their current password. If those match properly the password will be changed to the newPassword variable. Please note that passwords are encrypted with the UGC database.
 
RetrievePassword(string profileTypeName, string login)
The RetrievePassword method is used to retrieve a password for a current user. This method will send an email to the requested user login with their password credentials. For this method to work the user profile type must have a field marked as an Email Field which is properly populated. By default, the current password is sent to the user. If configured in Agility the password can be automatically reset when this call is made.
 

API Samples

JavaScript API

The JavaScript User Profile API allows users to perform authentication, authentication validation as well as some basic profile related functions all through JavaScript. 

JavaScript is highly recommended over using the .NET API for performance reasons.

Agility.UGC.API.GetAuthCookieName()
This method will return the authentication Cookie name that automatically stores the authentication token when the Authenticate method is called.
 
var cookieName = Agility.UGC.API.GetAuthCookieName();

 

Agility.UGC.API.SetAuthCookieName(cookieName)
This method lets you set a custom Cookie name to store the authentication token into when the Authenticate method is called.

var cookieName = Agility.UGC.API.SetAuthCookieName("MyAuthCookieName");

 

Agility.UGC.API.Logout(websiteUserTypeName)
This method will clear your current authentication cookie that the user is currently logged in as. You must pass the websiteUserTypeName in case there are multiple authentication points (User Types) within your system.

Agility.UGC.API.Logout("Profile");

 

Agility.UGC.API.Authenticate(websiteUserTypeName, login, password, persistCookie, callback)
This method is used to authenticate a user against a specific website user type within the UGC system. An authentication token will be generated if successful and will set the authentication cookie defined by Agility.UGC.API.GetAuthCookieName();
Agility.UGC.API.Authenticate("Profile", "Username", "Password", true, function(data){
   if(data.ResponseType == Agility.UGC.API.ResponseType.OK){
         alert("Login Successful! Your Authentication Token is: " + data.ResponseData);
   }
});

 

Agility.UGC.API.IsAuthenticated(websiteUserTypeName, callback)
This method will return a fully qualified Authentication Object which can be used to re-initialize the UGC API with the user's unique profile ID and hash code. This is important as updates to profile related data can only be done if authenticated as an Administrator or the user who owns the profile record.

Agility.UGC.API.IsAuthenticated("Profile", function(data){
 if(data.ResponseType == Agiltity.UGC.API.ResponseType.OK){
   //User is authenticated.. and API access data has been refreshed to use the currently logged in users credentials.
 }
});

 

Agility.UGC.API.ChangePassword(currentPassword, newPassword, callback)
This method is used to change a users password. A user must be properly authenticated for this to work.
var currentPassword = "myCurrentPass";
var newPassword = "myNewPass";
 
Agility.UGC.API.IsAuthenticated("Profile", function(data){
  if(data.ResponseType == Agility.UGC.API.ResponseType.OK){
        Agility.UGC.API.ChangePassword(currentPassword, newPassword, function(cpData){
              if(cpData.ResponseType == Agility.UGC.API.ResponseType.OK){
                      alert("Your password has been updated.");
              }
        });
  }
});

 

Agility.UGC.API.RetrievePassword(websiteUserTypeName, login, callback)
This method will send an email to the user to retrieve their password.
Agility.UGC.API.RetrievePassword("Profile", "MyLoginName", function(data){
  if(data.ResponseType == Agility.UGC.API.ResponseType.OK){
      alert("Your password has been sent to your email");
  }
});

 

.NET API

Below are example usages of the User Profile API using the WCF API.

Authenticate(DataServiceAuthorization auth, string profileTypeName, string login, string password)

using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient)
{
   DataServiceAuthorization auth =
     UGCAPIUtil.GetDataServiceAuthorization(-1);
                     
    string AuthenticationToken = client.Authenticate(auth, "Profile", "miskiw", "Password");
    if(AuthenticationToken!=null){
             //Authentication Successful
             PerformLoginFunction(AuthenticationToken);
    }
   
}

 

IsAuthenticated(DataServiceAuthorization auth, string authenticationToken, string profileRecordType)

public bool IsUserAuthenticated()
{
    string websiteUserTypeName = "Profile";
    string cookieName = string.Format("UGC_AUTH_{0}{1}", UGCAPIUtil.Agility_API_Key, websiteUserTypeName);

    HttpCookie authenticationCookie = Request.Cookies[cookieName];
    if (authenticationCookie == null) return false;
    string token = HttpUtility.UrlDecode(authenticationCookie.Value);

    using (Agility_UGC_API_WCFClient client = UGCAPIUtil.APIClient)
    {
        DataServiceAuthorization auth = UGCAPIUtil.GetDataServiceAuthorization(-1);

        var auth2 = client.IsAuthenticated(auth, token, websiteUserTypeName);
        if (auth2 != null && auth2.ProfileRecordID > 0)
        {
             //Is Authenticated and has a valid auth object
             return true;
        }

    }
    return false;
}

 

ChangePassword(DataServiceAuthorization auth, int profileRecordID, string currentPassword, string newPassword)

using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient)
{
   DataServiceAuthorization auth =
     UGCAPIUtil.GetDataServiceAuthorization(-1);
                     
    bool success= client.ChangePassword(auth, profileRecordID, currentPassword, newPassword);
    if(success){
         ///Password changed successfully
    }
   
}

 

RetrievePassword(DataServiceAuthorization auth, string profileTypeName, string login) 

using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient)
{
   DataServiceAuthorization auth =
     UGCAPIUtil.GetDataServiceAuthorization(-1);
                     
    bool success= client.RetrievePassword(auth, "Profile", "miskiw");
    if(success){
         ///Password was successfully emailed to the user
    }
   
}

 

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.