128 lines
4.0 KiB
C#
128 lines
4.0 KiB
C#
namespace VECV_WebApi.Models.Authorization
|
|
{
|
|
#region Namespaces
|
|
|
|
using LoggingHelper;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Web;
|
|
|
|
#endregion
|
|
|
|
#region Class
|
|
|
|
/// <summary>
|
|
/// This class is used to authorize the service user
|
|
/// </summary>
|
|
public class AuthenticationRepository
|
|
{
|
|
#region Global Variables
|
|
|
|
/// <summary>
|
|
/// making object of LoggingUtility class available to this class
|
|
/// </summary>
|
|
LoggingUtility objLog = new LoggingUtility();
|
|
|
|
/// <summary>
|
|
/// making the data-log file path available to this class
|
|
/// </summary>
|
|
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
|
|
|
|
/// <summary>
|
|
/// making error log file path available to this class
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
/// <summary>
|
|
/// making the security code for authorization available to this class
|
|
/// </summary>
|
|
private string _token;
|
|
|
|
/// <summary>
|
|
/// making Authenticate model object available to this class
|
|
/// </summary>
|
|
AutheticateModel objAuth;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Default constructor intialize security token value
|
|
/// </summary>
|
|
public AuthenticationRepository()
|
|
{
|
|
_token = ConfigurationManager.AppSettings["Token"];
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region API Methods
|
|
|
|
/// <summary>
|
|
/// To authenticate service user by matching security token
|
|
/// </summary>
|
|
/// <param name="token">security token which is send by service user</param>
|
|
/// <returns>True if security token are matched elxe False</returns>
|
|
public bool AuthenticateDevice(string token)
|
|
{
|
|
try
|
|
{
|
|
if (token == _token)
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("AuthenticateDevice", Ex.Message, path, errorlogtf);
|
|
throw new Exception(Ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// To autheticate user id and password on sign in
|
|
/// </summary>
|
|
/// <param name="model">login id and password info</param>
|
|
/// <returns>authenticate status</returns>
|
|
public AutheticateModel AutheticateUser(LoginModel model)
|
|
{
|
|
objAuth = new AutheticateModel();
|
|
try
|
|
{
|
|
if (AuthenticateDevice(model.Token))
|
|
{
|
|
if (model.UserName == ConfigurationManager.AppSettings["Login"].ToString() && model.Password == ConfigurationManager.AppSettings["Password"].ToString())
|
|
{
|
|
objAuth.Status = ConfigurationManager.AppSettings["LoginSuccess"].ToString();
|
|
objAuth.Message = ConfigurationManager.AppSettings["LoginSuccessMsg"].ToString();
|
|
return objAuth;
|
|
}
|
|
else
|
|
{
|
|
objAuth.Status = ConfigurationManager.AppSettings["LoginFail"].ToString();
|
|
objAuth.Message = ConfigurationManager.AppSettings["LoginFailMsg"].ToString();
|
|
return objAuth;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
objAuth.Status = ConfigurationManager.AppSettings["LoginFail"].ToString();
|
|
objAuth.Message = ConfigurationManager.AppSettings["DeviceConfigurationTokenMessage"].ToString();
|
|
return objAuth;
|
|
}
|
|
}
|
|
catch(Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("AutheticateUser", Ex.Message, path, errorlogtf);
|
|
throw new Exception(Ex.Message);
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |