Click or drag to resize

AuthenticateControllerLoginUser Method

Authenticate and create a session for the User.

Namespace:  MedTunnelSvc.Controllers
Assembly:  MedTunnelSvc (in MedTunnelSvc.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public Result LoginUser(
	UserCredentials UserCredentials
)

Parameters

UserCredentials
Type: MedTunnelSvc.ModelsUserCredentials
The UserCredentials object of the user to be authenticated. Passed in the Request body

Return Value

Type: Result
Result.Data contains the UserToken object. Result.ReturnCode values:
  • 0 = An unknown error occurred
  • 1 = Success
  • 2 = User Not Found / User Not Verified / No Login Permission
  • 4 = Invalid Application Id
  • 11 = Account Locked
Examples
C#
private string LoginUser(string applicationId, string locationId, string medTunnelId, string password, int expiration = 10)
{
    //namespaces to include
    //using System;
    //using System.Net;
    //using System.Web.Script.Serialization;

    string url;
    string downloadString;
    Result webResult;
    string token = "";
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    UserCredentials userLoginInfo = new UserCredentials();
    UserToken userToken = new UserToken();

    using (WebClient client = new WebClient())
    {
        client.Headers[HttpRequestHeader.ContentType] = "application/json";

        userLoginInfo.ApplicationId = applicationId;
        userLoginInfo.LocationId = locationId;
        userLoginInfo.MedTunnelId = medTunnelId;
        userLoginInfo.Password = password;
        userLoginInfo.ExpirationInMinutes = expiration;

        var data = serializer.Serialize(userLoginInfo);

        url = "https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/LoginUser";

        //send the PUT request to the API
        downloadString = client.UploadString(url, "PUT", data);

        //get the Result object
        webResult = serializer.Deserialize<Result>(downloadString);

        if (webResult.ReturnCode == 1)
        {
            userToken = (UserToken)serializer.Deserialize<UserToken>(webResult.Data.ToString());

            if (userToken != null && userToken.UserId > 0)
            {
                token = userToken.Token;
            }
            else
            {
                token = "";
            }
        }
        else
        {
            token = "";
        }
    }

    return token;
}
PHP/Curl
curl -X PUT -k 
        -H "Content-Type: application/json" 
        -d "{        'MedTunnelId':'yourMedTunnelId@yourGroup',
                        'Password':'yourPassword',
                        'ApplicationId':'yourApplicationId',
                        'LocationId':'yourLocationId',
                        'ExpirationInMinutes':'50'
                }" 
        https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/LoginUser
See Also