131 lines
4.2 KiB
C#
131 lines
4.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Security;
|
|
using Models;
|
|
using Models.ModelItems;
|
|
using Models.View;
|
|
using Services.Api;
|
|
using Services.Cache;
|
|
using Services.Extensions;
|
|
using Services.Manager;
|
|
using Services.Tool;
|
|
using Newtonsoft.Json;
|
|
using static Services.Tool.HttpRequestHelp;
|
|
|
|
public class LoginController : Controller
|
|
{
|
|
public ActionResult Index(string Token = "")
|
|
{
|
|
|
|
//SqlSugarBase.Db.Queryable<View_AppAutho>().ToList();
|
|
//HotelServer.FindGSQX(45);
|
|
Logs.WriteLog("Token_________" + Token);
|
|
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(Token))
|
|
{
|
|
string Ip = IPHelper.GetIP();
|
|
var userinfo = RedisHelper.StringGet<UserInfo>(Token);
|
|
RedisHelper.RemoveKey(Token);
|
|
if (userinfo != default(UserInfo)) {
|
|
ReturnResult returnResult = new ReturnResult();
|
|
DL(ref returnResult, userinfo.Uid, userinfo.Pwd,1);
|
|
if(returnResult.Status == 200)
|
|
{
|
|
return Redirect("/");
|
|
}
|
|
}
|
|
}
|
|
View_UserInfo view_UserInfo = UserLoginHelper.CurrentUser();
|
|
if (view_UserInfo != null)
|
|
{
|
|
Logs.WriteLog("Ö÷Ò³Á÷³Ì"+view_UserInfo.Uid);
|
|
base.Response.Redirect("/");
|
|
//return View();
|
|
}
|
|
RSA rSA = new RSA(512);
|
|
base.ViewBag.publicYS = rSA.ToPEM().ToPEM_PKCS8(convertToPublic: true).Replace("\r\n", "")
|
|
.Replace(Convert.ToChar(10).ToString(), "")
|
|
.Replace(Convert.ToChar(13).ToString(), "");
|
|
base.Session["ras"] = rSA;
|
|
return View();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logs.WriteLog("µÇ¼Ö÷Ò³±¨´í"+ex.Message);
|
|
throw;
|
|
}
|
|
}
|
|
public ActionResult Logout()
|
|
{
|
|
UserLoginHelper.UserLogout();
|
|
Response.Redirect("/Login/Index");
|
|
return null;
|
|
}
|
|
[HttpPost]
|
|
public ActionResult AuthorityLogin(string Uid, string Pwd)
|
|
{
|
|
try
|
|
{
|
|
Logs.WriteLog("µÇ¼³É¹¦");
|
|
ReturnResult returnResult = new ReturnResult();
|
|
DL(ref returnResult, Uid, Pwd);
|
|
return Json(returnResult);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logs.WriteLog(ex.ToString());
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
private void DL(ref ReturnResult returnResult, string Uid, string Pwd,int TYPE=0) {
|
|
DbLog log = new DbLog() { Uid = Uid, Ip = IPHelper.GetIP(), Client = HttpContext.Request.UserAgent };
|
|
try
|
|
{
|
|
View_UserInfo userLoginBy = UserLoginHelper.GetUserLoginBy(Uid, Pwd, TYPE);
|
|
ViewBag.ToNone = userLoginBy.CreatedBy;
|
|
returnResult.Status = 200;
|
|
var session = Session;
|
|
Task.Run(() =>
|
|
{
|
|
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
|
if (loc.status == 0)
|
|
{
|
|
if (loc.data.Count > 0)
|
|
{
|
|
log.location = loc.data[0].location;
|
|
}
|
|
}
|
|
session["log"] = log;
|
|
DbLogServer.WriteDbLog((TYPE == 0 ? "" : "ͨ¹ýÌø×ª")+$"µÇ¼ÁËϵͳ~", 0, log);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
|
if (loc.status == 0)
|
|
{
|
|
if (loc.data.Count > 0)
|
|
{
|
|
log.location = loc.data[0].location;
|
|
}
|
|
}
|
|
DbLogServer.WriteDbLog($"µÇ¼ϵͳʧ°Ü~", 0, log);
|
|
});
|
|
LogHelp.WriteExceptionLog(ex);
|
|
returnResult.Message = ex.Message;
|
|
returnResult.Status = 500;
|
|
}
|
|
Logs.WriteTimingUDPLog(JsonConvert.SerializeObject(returnResult));
|
|
}
|
|
}
|