59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
using VirtualTask.Models;
|
|
|
|
namespace VirtualTask.Controllers
|
|
{
|
|
public class LoginController : Controller
|
|
{
|
|
|
|
string apiUrl=string.Empty;
|
|
HttpClient client;
|
|
SessionHelper helper;
|
|
public LoginController()
|
|
{
|
|
apiUrl = "http://10.0.0.187:8000/api/Polo/";
|
|
client = new HttpClient();
|
|
helper = new SessionHelper(this);
|
|
}
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
public IActionResult Login()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Login(Login model)
|
|
{
|
|
string url = apiUrl + "loginTechnical";
|
|
Uri baseAddress = new Uri(url);
|
|
client.BaseAddress = baseAddress;
|
|
|
|
//SessionHelper helper = new SessionHelper(this);
|
|
LoginOut loginOut = new LoginOut();
|
|
string data = JsonConvert.SerializeObject(model);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
//HttpContext.Session.SetString("tok", "Jarvik");
|
|
//string t= HttpContext.Session.GetString("tok");
|
|
|
|
string risultato = response.Content.ReadAsStringAsync().Result;
|
|
loginOut = JsonConvert.DeserializeObject<LoginOut>(risultato);
|
|
//HttpContext.Session.SetString("tok", loginOut.Tok);
|
|
//ViewBag.Token = loginOut.Tok;
|
|
helper.SetStringValue("tok", loginOut.Tok);
|
|
helper.SetStringValue("apiUrl", apiUrl);
|
|
helper.SetStringValue("tenant", model.Tenant);
|
|
return RedirectToAction("Index","Home");
|
|
}
|
|
return View();
|
|
}
|
|
}
|
|
}
|