旧版报表、仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

171 lines
6.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Security;
using Warehouse.Code;
using Warehouse.DAL.Permission;
using Warehouse.DAL.Encrypt;
using Warehouse.Models.Permission;
namespace Warehouse.WebApi
{
public class AccountController : ApiController
{
[Route("api/Account/Login")]
[HttpPost]
public IHttpActionResult Login(dynamic para)
{
var UserName = Convert.ToString(para.username);
var Password = Convert.ToString(para.password);
var createtime = System.DateTime.Now;
string encryption = System.Web.Configuration.WebConfigurationManager.AppSettings["encryption"];
if (encryption == null || encryption == "")
{
return Json(new { res = "fail", info = "您无权打开报表平台" });
}
// string encipherment = AESHelper.Encrypt(encryption);
string decode = AESHelper.Decrypt(encryption);
DateTime dt = Convert.ToDateTime(decode);
dt = dt.AddDays(1);
if (createtime > dt)
{
return Json(new { res = "fail", info = "您的权限已到期" });
}
var infos = string.Empty;
var rematime = dt - createtime;
var day = rematime.Days;
if (day <= 7)
{
var hour = rematime.Hours;
var minutes = rematime.Minutes;
var second = rematime.Seconds;
infos = "您的剩余使用天数为:" + day + "天" + hour + "小时" + minutes + "分钟" + second + "秒";
}
else
{
infos = "";
}
if (Common.DBType == (int)DB.sqlserver)
{
Models.whMS.tuser res = new PermissionMSDal().GetUserInfoByName(UserName);
if (res == null)
{
return Json(new { res = "fail", info = "账号不存在" });
}
if (res.Password != Password)
{
return Json(new { res = "fail", info = "密码错误" });
}
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(Convert.ToString(res.UserId), false);
HttpContext.Current.Response.Cookies.Remove(authCookie.Name);
HttpContext.Current.Response.Cookies.Add(authCookie);
System.Web.HttpContext.Current.Response.Cookies["userid"].Value = Convert.ToString(res.UserId);
return Json(new { res = "success", info = infos, day = day });
}
else if (Common.DBType == (int)DB.mysql)
{
tuser res = new PermissionDal().GetUserInfoByName(UserName);
if (res == null)
{
return Json(new { res = "fail", info = "账号不存在" });
}
if (res.Password != Password)
{
return Json(new { res = "fail", info = "密码错误" });
}
//var res = LCLDalObj.QueryStockInfoByPallet(para.pallets.ToString());
//System.Web.Security.FormsAuthentication.SetAuthCookie(Convert.ToString(res.UserId), false);
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(Convert.ToString(res.UserId), false);
HttpContext.Current.Response.Cookies.Remove(authCookie.Name);
HttpContext.Current.Response.Cookies.Add(authCookie);
System.Web.HttpContext.Current.Response.Cookies["userid"].Value = Convert.ToString(res.UserId);
//FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(
// 1,
// "",
// DateTime.Now,
// DateTime.Now.AddMinutes(20),
// false,
// "admin"
// );
return Json(new { res = "success", info = "" });
}
else
{
return Json(new { res = "fail", info = "服务出错" }); ;
}
}
[Route("api/Account/GetUserName")]
[HttpPost]
public IHttpActionResult GetUserName(dynamic para)
{
int UserId = para.userid;
if (Common.DBType == (int)DB.sqlserver)
{
var res = new PermissionMSDal().GetUserInfo(UserId); //Models.whMS.tuser
return Json(new { UserName = res.DisplayName });
}
else if (Common.DBType == (int)DB.mysql)
{
tuser res = new PermissionDal().GetUserInfo(UserId);
return Json(new { UserName = res.DisplayName });
} else
{
return Json(new { res = "fail", info = "服务出错" });
}
}
PermissionMSDal DT = new PermissionMSDal();
PermissionDal msql = new PermissionDal();
[Route("api/Account/Permissions")]
[HttpPost]
//public IHttpActionResult Permission(dynamic para)
//{
// string UserId = para.userid;
// var res = DT.Permissions(UserId);
// return Json(res);
// //var res = new PermissionMSDal().GetUserInfo(UserId); //Models.whMS.tuser
// //return Json(new { UserName = res.DisplayName });
//}
public IHttpActionResult Permission(dynamic para)
{
string UserId = para.userid;
var res = new List<dynamic>() ;
if (Common.DBType == (int)DB.sqlserver)
{
res = DT.Permissions(UserId);
}else if ((Common.DBType == (int)DB.mysql))
{
res = msql.Permissions(UserId);
}
return Json(res);
//var res = new PermissionMSDal().GetUserInfo(UserId); //Models.whMS.tuser
//return Json(new { UserName = res.DisplayName });
}
//查询用户名
[Route("api/Account/SearchUserName")]
[HttpPost]
public IHttpActionResult SearchUserName(dynamic para)
{
int UserId = para.userId;
Models.whMS.tuser res = new PermissionMSDal().GetUserInfo(UserId);
return Json(new { result = "success", info = res.Username });
}
}
}