namespace VECV_WebApi.Models.Authorization
{
#region Namespaces
using LoggingHelper;
using System;
using System.Configuration;
using System.Web;
#endregion
#region Class
///
/// This class is used to authorize the service user
///
public class AuthenticationRepository
{
#region Global Variables
///
/// making object of LoggingUtility class available to this class
///
LoggingUtility objLog = new LoggingUtility();
///
/// making the data-log file path available to this class
///
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
///
/// making error log file path available to this class
///
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
///
/// making the security code for authorization available to this class
///
private string _token;
///
/// making Authenticate model object available to this class
///
AutheticateModel objAuth;
#endregion
#region Constructor
///
/// Default constructor intialize security token value
///
public AuthenticationRepository()
{
_token = ConfigurationManager.AppSettings["Token"];
}
#endregion
#region API Methods
///
/// To authenticate service user by matching security token
///
/// security token which is send by service user
/// True if security token are matched elxe False
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);
}
}
///
/// To autheticate user id and password on sign in
///
/// login id and password info
/// authenticate status
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
}