126 lines
3.5 KiB
C#
126 lines
3.5 KiB
C#
|
|
|
|
namespace VECV_WebApi.Controllers.Token
|
|
{
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
using DocumentFormat.OpenXml.EMMA;
|
|
using DocumentFormat.OpenXml.Office2010.ExcelAc;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
using ExcelHelper;
|
|
#region Namespaces
|
|
|
|
using LoggingHelper;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Configuration;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Helpers;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Results;
|
|
using System.Web.Mvc;
|
|
using VECV_WebApi.Common;
|
|
using VECV_WebApi.CommonAuthorization;
|
|
using VECV_WebApi.Models.BoatAPIModel;
|
|
using VECV_WebApi.Models.BoatAPIRepository;
|
|
using VECV_WebApi.Models.Notification;
|
|
using VECV_WebApi.Models.Ticket;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// This controller contain ticket related api
|
|
/// </summary>
|
|
|
|
//[JwtAuthentication]
|
|
//[System.Web.Http.Authorize]
|
|
[RoutePrefix("api/TokenJWT")]
|
|
public class TokenAPIController : ApiController
|
|
{
|
|
#region Global Variable
|
|
|
|
/// <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 data log file path available to this class
|
|
/// </summary>
|
|
string logtf = (ConfigurationManager.AppSettings["Log"]);
|
|
|
|
/// <summary>
|
|
/// making error log file path available to this class
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
string _appName = (ConfigurationManager.AppSettings["ApplicationName"]);
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
|
|
|
|
#endregion
|
|
|
|
|
|
#region APIs
|
|
|
|
|
|
[System.Web.Http.HttpPost]
|
|
[System.Web.Http.Route("token")]
|
|
public IHttpActionResult GetToken()
|
|
{
|
|
var auth = Request.Headers.Authorization;
|
|
if (auth == null || auth.Scheme != "Basic")
|
|
return ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized, "Missing Basic Auth"));
|
|
|
|
var encodedCredentials = auth.Parameter;
|
|
var credentialBytes = Convert.FromBase64String(encodedCredentials);
|
|
var credentials = Encoding.UTF8.GetString(credentialBytes).Split(':');
|
|
|
|
if (credentials.Length != 2)
|
|
return BadRequest("Invalid Basic Auth format");
|
|
|
|
var username = credentials[0];
|
|
var password = credentials[1];
|
|
|
|
// Replace this check with actual DB/user validation
|
|
if (username != ConfigurationManager.AppSettings["JWTAuthId"].ToString() || password != ConfigurationManager.AppSettings["JWTAuthPwd"].ToString())
|
|
return Unauthorized();
|
|
|
|
var token = JwtManager.GenerateToken(username);
|
|
return Ok(new { token });
|
|
}
|
|
|
|
public bool CheckUser(string username, string password)
|
|
{
|
|
// should check in the database
|
|
if (username == ConfigurationManager.AppSettings["JWTAuthId"].ToString() && password == ConfigurationManager.AppSettings["JWTAuthPwd"].ToString())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#endregion APIs
|
|
}
|
|
} |