51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
using VirtualTask.Models;
|
|
|
|
namespace VirtualTask.Controllers
|
|
{
|
|
public class LoginController : Controller
|
|
{
|
|
|
|
//https://localhost:7068/api/Polo/loginTechnical
|
|
Uri baseAddress = new Uri("http://10.0.0.187:5068/api/Polo/loginTechnical");
|
|
HttpClient client;
|
|
public LoginController()
|
|
{
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
}
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
public IActionResult Login()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Login(Login model)
|
|
{
|
|
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);
|
|
|
|
|
|
return RedirectToAction("Index","Home");
|
|
}
|
|
return View();
|
|
}
|
|
}
|
|
}
|