添加项目文件。

This commit is contained in:
zel
2025-03-05 19:42:01 +08:00
parent 659f1a2ad9
commit 47dcdeb55d
582 changed files with 242004 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace WaterCloud.Web
{
/// <summary>
/// 测试文件
/// </summary>
[Route("api/[controller]/[action]")]
[ApiExplorerSettings(GroupName = "V2")]
[ApiController]
[LoginFilter]
public class TestController : ControllerBase
{
// GET: api/<controller>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<controller>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<controller>
[HttpPost]
public void Post([FromBody, Required(ErrorMessage = "值不能为空")] string value)
{
}
// PUT api/<controller>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody, Required(ErrorMessage = "值不能为空")] string value)
{
}
// DELETE api/<controller>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

View File

@@ -0,0 +1,170 @@
using Jaina;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Domain.SystemSecurity;
using WaterCloud.Service.Event;
using WaterCloud.Service.SystemOrganize;
using WaterCloud.Service.SystemSecurity;
namespace WaterCloud.Web
{
/// <summary>
/// 用户接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiExplorerSettings(GroupName = "Default")]
[ApiController]
public class UserController : ControllerBase
{
//自动注入服务
public FilterIPService _filterIPService { get; set; }
public UserService _userService { get; set; }
public LogService _logService { get; set; }
public SystemSetService _setService { get; set; }
public IHttpContextAccessor _httpContextAccessor { get; set; }
#region
/// <summary>
/// 用户登录
/// </summary>
/// <param name="request">请求对象</param>
/// <returns></returns>
[HttpPost]
public async Task<AlwaysResult> Login([FromBody] LoginRequest request)
{
var apitoken = Utils.GuId();
if (!string.IsNullOrEmpty(OperatorProvider.Provider.GetToken()))
{
apitoken = OperatorProvider.Provider.GetToken();
}
LogEntity logEntity = new LogEntity();
logEntity.F_ModuleName = "用户Api";
logEntity.F_Type = DbLogType.Login.ToString();
try
{
if (!await CheckIP())
{
throw new Exception("IP受限");
}
UserEntity userEntity = await _userService.CheckLogin(request.userName, Md5.md5(request.password, 32), request.localurl);
OperatorModel operatorModel = new OperatorModel();
operatorModel.UserId = userEntity.F_Id;
operatorModel.UserCode = userEntity.F_Account;
operatorModel.UserName = userEntity.F_RealName;
operatorModel.CompanyId = userEntity.F_CompanyId;
operatorModel.OrganizeId = userEntity.F_OrganizeId;
operatorModel.RoleId = userEntity.F_RoleId;
operatorModel.LoginIPAddress = WebHelper.Ip;
if (GlobalContext.SystemConfig.LocalLAN != false)
{
operatorModel.LoginIPAddressName = "本地局域网";
}
else
{
operatorModel.LoginIPAddressName = WebHelper.GetIpLocation(operatorModel.LoginIPAddress);
}
operatorModel.LoginTime = DateTime.Now;
operatorModel.DdUserId = userEntity.F_DingTalkUserId;
operatorModel.WxOpenId = userEntity.F_WxOpenId;
operatorModel.IsAdmin = userEntity.F_IsAdmin.Value;
operatorModel.IsBoss = userEntity.F_IsBoss.Value;
operatorModel.IsSenior = userEntity.F_IsSenior.Value;
SystemSetEntity setEntity = await _setService.GetForm(userEntity.F_CompanyId);
operatorModel.DbNumber = setEntity.F_DbNumber;
if (operatorModel.IsAdmin && operatorModel.DbNumber == GlobalContext.SystemConfig.MainDbNumber)
{
operatorModel.IsSuperAdmin = true;
}
else
{
operatorModel.IsSuperAdmin = false;
}
await OperatorProvider.Provider.AddLoginUser(operatorModel, apitoken, "api_");
logEntity.F_Account = userEntity.F_Account;
logEntity.F_NickName = userEntity.F_RealName;
logEntity.F_Result = true;
logEntity.F_Description = "登录成功";
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity, operatorModel));
// 设置刷新Token令牌
_httpContextAccessor.HttpContext.Response.Headers[GlobalContext.SystemConfig.TokenName] = apitoken;
return new AlwaysResult<string> { state = ResultType.success.ToString(), message = "登录成功。", data = apitoken };
}
catch (Exception ex)
{
logEntity.F_Account = request.userName;
logEntity.F_NickName = request.userName;
logEntity.F_Result = false;
logEntity.F_Description = "登录失败," + ex.Message;
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity));
return new AlwaysResult<string> { state = ResultType.error.ToString(), message = ex.Message, data = apitoken };
}
}
private async Task<bool> CheckIP()
{
string ip = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString();
return await _filterIPService.CheckIP(ip);
}
/// <summary>
/// 用户退出登录
/// </summary>
/// <returns></returns>
[HttpPost]
[LoginFilter]
public async Task<AlwaysResult> LoginOff()
{
var logEntity = new LogEntity
{
F_ModuleName = "用户Api",
F_Type = DbLogType.Exit.ToString(),
F_Account = _userService.currentuser.UserCode,
F_NickName = _userService.currentuser.UserName,
F_Result = true,
F_Description = "安全退出系统",
};
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity, _userService.currentuser));
await OperatorProvider.Provider.EmptyCurrent("api_");
return new AlwaysResult { state = ResultType.success.ToString() };
}
#endregion
#region
/// <summary>
/// 登录请求对象
/// </summary>
public class LoginRequest
{
/// <summary>
/// 用户名
/// </summary>
[Required(ErrorMessage = "用户名不能为空")]
public string userName { get; set; }
/// <summary>
/// 密码
/// </summary>
[Required(ErrorMessage = "密码不能为空")]
public string password { get; set; }
/// <summary>
/// 域名
/// </summary>
public string localurl { get; set; }
}
#endregion
}
}

View File

@@ -0,0 +1,125 @@
using Jaina;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Serenity.Data;
using SqlSugar;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Service.Event;
using WaterCloud.Service.SystemSecurity;
namespace WaterCloud.Web
{
[HandlerLogin]
public abstract class BaseController : Controller
{
public LogService _logService { get; set; }
/// <summary>
/// 演示模式过滤
/// </summary>
/// <param name="context"></param>
/// <param name="next"></param>
/// <returns></returns>
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Stopwatch sw = new Stopwatch();
sw.Start();
string action = context.RouteData.Values["Action"].ParseToString();
OperatorModel user = OperatorProvider.Provider.GetCurrent();
if (GlobalContext.SystemConfig.Demo)
{
if (context.HttpContext.Request.Method.ToUpper() == "POST")
{
string[] allowAction = new string[] { "LoginJson", "ExportUserJson", "CodePreviewJson" };
if (!allowAction.Select(p => p.ToUpper()).Contains(action.ToUpper()))
{
string Message = "演示模式,不允许操作";
context.Result = new JsonResult(new AlwaysResult
{
state = ResultType.error.ToString(),
message = Message
});
return;
}
}
}
var resultContext = await next();
sw.Stop();
}
public override void OnActionExecuted(ActionExecutedContext context)
{
base.OnActionExecuted(context);
}
[HttpGet]
[HandlerAuthorize]
public virtual ActionResult Index()
{
return View();
}
[HttpGet]
[HandlerAuthorize]
public virtual ActionResult Form()
{
return View();
}
[HttpGet]
[HandlerAuthorize]
public virtual ActionResult Details()
{
return View();
}
protected virtual async Task<ActionResult> Success(string message, string className = "", object keyValue = null, DbLogType? logType = null)
{
className = string.IsNullOrEmpty(className) ? ReflectionHelper.GetModuleName(isReplace: false, prefix: "Controller") : className;
var log = await _logService.CreateLog(message, className, keyValue != null && keyValue.ToString() != "0" ? keyValue.ToString() : "", logType);
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", log, _logService.currentuser));
return Content(new AlwaysResult { state = ResultType.success.ToString(), message = message }.ToJson());
}
protected virtual ActionResult Success(string message)
{
return Content(new AlwaysResult { state = ResultType.success.ToString(), message = message }.ToJson());
}
protected virtual ActionResult Success<T>(string message, T data)
{
return Content(new AlwaysResult<T> { state = ResultType.success.ToString(), message = message, data = data }.ToJson());
}
protected virtual ActionResult Success<T>(int total, T data)
{
return Content(new AlwaysResult<T> { state = 0, message = "", count = total, data = data }.ToJson());
}
protected virtual ActionResult DTreeResult(object data)
{
return Content(new DTreeResult { status = new StatusInfo { code = 200, message = "操作成功" }, data = data }.ToJson());
}
protected virtual async Task<ActionResult> Error(string message, string className, object keyValue = null, DbLogType? logType = null)
{
className = string.IsNullOrEmpty(className) ? ReflectionHelper.GetModuleName(isReplace: false, prefix: "Controller") : className;
var log = await _logService.CreateLog(message, className, keyValue != null && keyValue.ToString() != "0" ? keyValue.ToString() : "", logType, true);
await GlobalContext.GetService<ISqlSugarClient>().Ado.RollbackTranAsync();
await GlobalContext.GetService<ISqlSugarClient>().AsTenant().RollbackTranAsync();
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", log, _logService.currentuser));
return Content(new AlwaysResult { state = ResultType.error.ToString(), message = LogHelper.ExMsgFormat(message) }.ToJson());
}
protected virtual ActionResult Error(string message)
{
return Content(new AlwaysResult { state = ResultType.error.ToString(), message = LogHelper.ExMsgFormat(message) }.ToJson());
}
}
}

View File

@@ -0,0 +1,408 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Service.InfoManage;
using WaterCloud.Service.SystemManage;
using WaterCloud.Service.SystemOrganize;
using WaterCloud.Service.SystemSecurity;
namespace WaterCloud.Web.Controllers
{
[HandlerLogin]
public class ClientsDataController : Controller
{
/// <summary>
/// 缓存操作类
/// </summary>
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
public QuickModuleService _quickModuleService { get; set; }
public NoticeService _noticeService { get; set; }
public UserService _userService { get; set; }
public ModuleService _moduleService { get; set; }
public LogService _logService { get; set; }
public RoleAuthorizeService _roleAuthorizeService { get; set; }
public ItemsDataService _itemsDetailService { get; set; }
public ItemsTypeService _itemsService { get; set; }
public SystemSetService _setService { get; set; }
public MessageService _msgService { get; set; }
/// <summary>
/// 初始数据加载请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
[HandlerAjaxOnly]
[AllowAnonymous]
public async Task<ActionResult> GetClientsDataJson()
{
var data = new
{
dataItems = await this.GetDataItemList(),
authorizeButton = await this.GetMenuButtonListNew(),
moduleFields = await this.GetMenuFields(),
authorizeFields = await this.GetMenuFieldsListNew(),
};
return Content(data.ToJson());
}
/// <summary>
/// 清空缓存请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> ClearCache()
{
try
{
if (!_setService.currentuser.IsSuperAdmin)
{
return Content(new { code = 0, msg = "此功能需要管理员权限" }.ToJson());
}
await CacheHelper.FlushAllAsync();
await OperatorProvider.Provider.EmptyCurrent("pc_");
return Content(new { code = 1, msg = "服务端清理缓存成功" }.ToJson());
}
catch (Exception)
{
return Content(new { code = 0, msg = "此功能需要管理员权限" }.ToJson());
}
}
/// <summary>
/// 模块字段权限
/// </summary>
/// <returns></returns>
private async Task<object> GetMenuFields()
{
var roleId = _userService.currentuser.RoleId;
if (roleId == null && _userService.currentuser.IsAdmin)
{
roleId = "admin";
}
else if (roleId == null && !_userService.currentuser.IsSuperAdmin)
{
roleId = "visitor";
}
Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
var list = await _roleAuthorizeService.GetMenuList(roleId);
foreach (ModuleEntity item in list.Where(a => !string.IsNullOrEmpty(a.F_UrlAddress)))
{
dictionary.Add(item.F_UrlAddress, item.F_IsFields ?? false);
}
return dictionary;
}
/// <summary>
/// 快捷菜单列表
/// </summary>
/// <returns></returns>
private async Task<object> GetQuickModuleList()
{
var currentuser = _userService.currentuser;
if (currentuser.UserId == null)
{
return null;
}
var userId = currentuser.UserId;
var data = await _quickModuleService.GetQuickModuleList(userId);
return data;
}
/// <summary>
/// 获取公告信息
/// </summary>
/// <returns></returns>
private async Task<object> GetNoticeList()
{
var data = (await _noticeService.GetList("")).Where(a => a.F_EnabledMark == true).OrderByDescending(a => a.F_CreatorTime).Take(6).ToList();
return data;
}
/// <summary>
/// 初始菜单列表请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> GetInitDataJson()
{
var currentuser = _userService.currentuser;
if (currentuser.UserId == null)
{
return Content("");
}
var data = await GetMenuListNew();
return Content(data);
}
/// <summary>
/// 获取公告信息请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> GetNoticeInfo()
{
var data = await this.GetNoticeList();
return Content(data.ToJson());
}
/// <summary>
/// 获取当前用户信息请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
[HandlerAjaxOnly]
[AllowAnonymous]
public async Task<ActionResult> GetUserCode()
{
var currentuser = _userService.currentuser;
if (currentuser.UserId == null)
{
return Content("");
}
var data = await _userService.GetFormExtend(currentuser.UserId);
var msglist = await _msgService.GetUnReadListJson();
data.MsgCout = msglist.Count();
return Content(data.ToJson());
}
/// <summary>
/// 获取快捷菜单请求方法
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> GetQuickModule()
{
try
{
var data = await this.GetQuickModuleList();
return Content(data.ToJson());
}
catch (Exception)
{
return Content("");
}
}
/// <summary>
/// 获取数据信息接口
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> GetCoutData()
{
var currentuser = _userService.currentuser;
if (currentuser.UserId == null)
{
return Content("");
}
int usercout = (await _userService.GetUserList("")).Count();
var temp = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + currentuser.UserId);
int logincout = temp != null && temp.F_LogOnCount != null ? (int)temp.F_LogOnCount : 0;
int modulecout = (await _moduleService.GetList()).Where(a => a.F_EnabledMark == true && a.F_UrlAddress != null).Count();
int logcout = (await _logService.GetList()).Count();
var data = new { usercout = usercout, logincout = logincout, modulecout = modulecout, logcout = logcout };
return Content(data.ToJson());
}
/// <summary>
/// 菜单按钮信息
/// </summary>
/// <returns></returns>
private async Task<string> GetMenuListNew()
{
var currentuser = _userService.currentuser;
var roleId = currentuser.RoleId;
StringBuilder sbJson = new StringBuilder();
InitEntity init = new InitEntity();
init.homeInfo = new HomeInfoEntity();
init.homeInfo.href = GlobalContext.SystemConfig.HomePage;
init.logoInfo = new LogoInfoEntity();
var systemset = await _setService.GetForm(currentuser.CompanyId);
//修改主页及logo参数
init.logoInfo.title = systemset.F_LogoCode;
init.logoInfo.image = ".." + systemset.F_Logo;
init.menuInfo = new List<MenuInfoEntity>();
init.menuInfo = ToMenuJsonNew(await _roleAuthorizeService.GetMenuList(roleId), "0");
sbJson.Append(init.ToJson());
return sbJson.ToString();
}
/// <summary>
/// 菜单信息
/// </summary>
/// <param name="data"></param>
/// <param name="parentId"></param>
/// <returns></returns>
private List<MenuInfoEntity> ToMenuJsonNew(List<ModuleEntity> data, string parentId)
{
List<MenuInfoEntity> list = new List<MenuInfoEntity>();
List<ModuleEntity> entitys = data.FindAll(t => t.F_ParentId == parentId);
if (entitys.Count > 0)
{
foreach (var item in entitys)
{
MenuInfoEntity munu = new MenuInfoEntity();
munu.title = item.F_FullName;
munu.icon = item.F_Icon;
munu.href = item.F_UrlAddress;
switch (item.F_Target)
{
case "iframe":
munu.target = "_self";
break;
case "open":
munu.target = "_open";
break;
case "blank":
munu.target = "_blank";
break;
default:
munu.target = "_self";
break;
}
if (data.FindAll(t => t.F_ParentId == item.F_Id).Count > 0)
{
munu.child = new List<MenuInfoEntity>();
munu.child = ToMenuJsonNew(data, item.F_Id);
}
if (item.F_IsMenu == true)
{
list.Add(munu);
}
};
}
return list;
}
/// <summary>
/// 字段信息
/// </summary>
/// <returns></returns>
private async Task<object> GetDataItemList()
{
var itemdata = await _itemsDetailService.GetList();
Dictionary<string, object> dictionaryItem = new Dictionary<string, object>();
var itemlist = await _itemsService.GetList();
foreach (var item in itemlist.Where(a => a.F_EnabledMark == true).ToList())
{
var dataItemList = itemdata.FindAll(t => t.F_ItemId == item.F_Id);
Dictionary<string, string> dictionaryItemList = new Dictionary<string, string>();
foreach (var itemList in dataItemList)
{
dictionaryItemList.Add(itemList.F_ItemCode, itemList.F_ItemName);
}
dictionaryItem.Add(item.F_EnCode, dictionaryItemList);
}
return dictionaryItem;
}
/// <summary>
/// 菜单按钮信息
/// </summary>
/// <returns></returns>
private async Task<object> GetMenuButtonListNew()
{
var currentuser = _userService.currentuser;
var roleId = currentuser.RoleId;
if (roleId == null && currentuser.IsAdmin)
{
roleId = "admin";
}
else if (roleId == null && !currentuser.IsAdmin)
{
roleId = "visitor";
}
var rolelist = roleId.Split(',');
var dictionarylist = new Dictionary<string, List<ModuleButtonEntity>>();
if (currentuser.UserId == null)
{
return dictionarylist;
}
foreach (var roles in rolelist)
{
var dictionarytemp = new Dictionary<string, List<ModuleButtonEntity>>();
var data = await _roleAuthorizeService.GetButtonList(roles);
var dataModuleId = data.Where(a => a.F_ModuleId != null && a.F_ModuleId != "" && a.F_EnabledMark == true).Distinct(new ExtList<ModuleButtonEntity>("F_ModuleId"));
foreach (ModuleButtonEntity item in dataModuleId)
{
var buttonList = data.Where(t => t.F_ModuleId == item.F_ModuleId && t.F_EnabledMark == true).ToList();
dictionarytemp.Add(item.F_ModuleId, buttonList);
if (dictionarylist.ContainsKey(item.F_ModuleId))
{
dictionarylist[item.F_ModuleId].AddRange(buttonList);
dictionarylist[item.F_ModuleId] = dictionarylist[item.F_ModuleId].GroupBy(p => p.F_Id).Select(q => q.First()).ToList();
}
else
{
dictionarylist.Add(item.F_ModuleId, buttonList);
}
}
}
return dictionarylist;
}
/// <summary>
/// 菜单字段信息
/// </summary>
/// <returns></returns>
private async Task<object> GetMenuFieldsListNew()
{
var currentuser = _userService.currentuser;
var roleId = currentuser.RoleId;
if (roleId == null && currentuser.IsAdmin)
{
roleId = "admin";
}
else if (roleId == null && !currentuser.IsAdmin)
{
roleId = "visitor";
}
var rolelist = roleId.Split(',');
var dictionarylist = new Dictionary<string, List<ModuleFieldsEntity>>();
if (currentuser.UserId == null)
{
return dictionarylist;
}
foreach (var roles in rolelist)
{
var dictionarytemp = new Dictionary<string, List<ModuleFieldsEntity>>();
var data = await _roleAuthorizeService.GetFieldsList(roles);
var dataModuleId = data.Where(a => a.F_ModuleId != null && a.F_ModuleId != "" && a.F_EnabledMark == true).Distinct(new ExtList<ModuleFieldsEntity>("F_ModuleId"));
foreach (ModuleFieldsEntity item in dataModuleId)
{
var buttonList = data.Where(t => t.F_ModuleId == item.F_ModuleId && t.F_EnabledMark == true).ToList();
dictionarytemp.Add(item.F_ModuleId, buttonList);
if (dictionarylist.ContainsKey(item.F_ModuleId))
{
dictionarylist[item.F_ModuleId].AddRange(buttonList);
dictionarylist[item.F_ModuleId] = dictionarylist[item.F_ModuleId].GroupBy(p => p.F_Id).Select(q => q.First()).ToList();
}
else
{
dictionarylist.Add(item.F_ModuleId, buttonList);
}
}
}
return dictionarylist;
}
}
}

View File

@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using Microsoft.AspNetCore.Mvc;
using WaterCloud.Service.SystemOrganize;
namespace WaterCloud.Web.Controllers
{
public class HomeController : Controller
{
public SystemSetService _setService { get; set; }
[HttpGet]
[HandlerLogin]
public ActionResult Index()
{
//主页信息获取
if (_setService.currentuser.UserId == null)
{
return View();
}
var systemset = _setService.GetForm(_setService.currentuser.CompanyId).GetAwaiter().GetResult();
ViewBag.ProjectName = systemset.F_ProjectName;
ViewBag.LogoIcon = ".." + systemset.F_Logo;
return View();
}
[HttpGet]
[HandlerLogin]
public ActionResult Default()
{
return View();
}
[HttpGet]
[HandlerLogin]
public ActionResult UserSetting()
{
return View();
}
[HttpGet]
public ActionResult Error()
{
return View();
}
[HttpGet]
[HandlerLogin]
public ActionResult Message()
{
return View();
}
}
}

View File

@@ -0,0 +1,234 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using Jaina;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Domain.SystemSecurity;
using WaterCloud.Service.Event;
using WaterCloud.Service.SystemOrganize;
using WaterCloud.Service.SystemSecurity;
namespace WaterCloud.Web.Controllers
{
public class LoginController : Controller
{
public UserService _userService { get; set; }
public LogService _logService { get; set; }
public SystemSetService _setService { get; set; }
public RoleAuthorizeService _roleAuthServuce { get; set; }
public ISqlSugarClient _context { get; set; }
[HttpGet]
public virtual async Task<ActionResult> Index()
{
//登录页获取logo和项目名称
try
{
var systemset = await _setService.GetFormByHost("");
if (GlobalContext.SystemConfig.Demo)
{
ViewBag.UserName = systemset.F_AdminAccount;
ViewBag.Password = systemset.F_AdminPassword;
}
ViewBag.SqlMode = GlobalContext.SystemConfig.SqlMode;
ViewBag.ProjectName = systemset.F_ProjectName;
ViewBag.LogoIcon = ".." + systemset.F_Logo;
return View();
}
catch (Exception)
{
ViewBag.ProjectName = "水之云信息系统";
ViewBag.LogoIcon = "../icon/favicon.ico";
return View();
}
}
[HttpGet]
[HandlerAjaxOnly]
public async Task<ActionResult> GetListJsonByLogin(string keyword)
{
var data = await _setService.GetList(keyword);
data = data.OrderBy(a => a.F_DbNumber).ToList();
foreach (var item in data)
{
item.F_AdminAccount = null;
item.F_AdminPassword = null;
item.F_DBProvider = null;
item.F_DbString = null;
item.F_PrincipalMan = null;
item.F_MobilePhone = null;
item.F_CompanyName = null;
item.F_LogoCode = null;
}
return Content(data.ToJson());
}
/// <summary>
/// 验证码获取(此接口已弃用)
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult GetAuthCode()
{
return File(new VerifyCodeHelper().GetVerifyCode(), @"image/Gif");
}
[HttpGet]
public async Task<ActionResult> OutLogin()
{
var logEntity = new LogEntity
{
F_ModuleName = "系统登录",
F_Type = DbLogType.Exit.ToString(),
F_Account = _setService.currentuser.UserCode,
F_NickName = _setService.currentuser.UserName,
F_Result = true,
F_Description = "安全退出系统",
};
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity, _userService.currentuser));
await OperatorProvider.Provider.EmptyCurrent("pc_");
return Content(new AlwaysResult { state = ResultType.success.ToString() }.ToJson());
}
/// <summary>
/// 验证登录状态请求接口
/// </summary>
/// <returns></returns>
[HttpPost]
[HandlerAjaxOnly]
[IgnoreAntiforgeryToken]
public async Task<ActionResult> CheckLoginState()
{
try
{
if (_setService.currentuser.UserId == null)
{
return Content(new AlwaysResult { state = ResultType.error.ToString() }.ToJson());
}
//登录检测
if ((await OperatorProvider.Provider.IsOnLine("pc_")).stateCode <= 0)
{
await OperatorProvider.Provider.EmptyCurrent("pc_");
return Content(new AlwaysResult { state = ResultType.error.ToString() }.ToJson());
}
else
{
//验证回退路由是否有权限,没有就删除
await CheckReturnUrl(_setService.currentuser.UserId);
return Content(new AlwaysResult { state = ResultType.success.ToString() }.ToJson());
}
}
catch (Exception)
{
return Content(new AlwaysResult { state = ResultType.error.ToString() }.ToJson());
}
}
/// <summary>
/// 登录验证
/// </summary>
/// <param name="username">用户</param>
/// <param name="password">密码</param>
/// <param name="localurl">域名</param>
/// <returns></returns>
[HttpPost]
[HandlerAjaxOnly]
[IgnoreAntiforgeryToken]
public async Task<ActionResult> CheckLogin(string username, string password, string localurl)
{
//根据域名判断租户
LogEntity logEntity = new LogEntity();
logEntity.F_ModuleName = "系统登录";
logEntity.F_Type = DbLogType.Login.ToString();
if (GlobalContext.SystemConfig.SqlMode == Define.SQL_MORE)
{
localurl = "";
}
try
{
UserEntity userEntity = await _userService.CheckLogin(username, password, localurl);
OperatorModel operatorModel = new OperatorModel();
operatorModel.UserId = userEntity.F_Id;
operatorModel.UserCode = userEntity.F_Account;
operatorModel.UserName = userEntity.F_RealName;
operatorModel.CompanyId = userEntity.F_CompanyId;
operatorModel.OrganizeId = userEntity.F_OrganizeId;
operatorModel.RoleId = userEntity.F_RoleId;
operatorModel.LoginIPAddress = WebHelper.Ip;
if (GlobalContext.SystemConfig.LocalLAN != false)
{
operatorModel.LoginIPAddressName = "本地局域网";
}
else
{
operatorModel.LoginIPAddressName = WebHelper.GetIpLocation(operatorModel.LoginIPAddress);
}
operatorModel.LoginTime = DateTime.Now;
operatorModel.DdUserId = userEntity.F_DingTalkUserId;
operatorModel.WxOpenId = userEntity.F_WxOpenId;
//各租户的管理员也是当前数据库的全部权限
operatorModel.IsSuperAdmin = userEntity.F_IsAdmin.Value;
operatorModel.IsAdmin = userEntity.F_IsAdmin.Value;
operatorModel.IsBoss = userEntity.F_IsBoss.Value;
operatorModel.IsSenior = userEntity.F_IsSenior.Value;
SystemSetEntity setEntity = await _setService.GetForm(userEntity.F_CompanyId);
operatorModel.DbNumber = setEntity.F_DbNumber;
if (operatorModel.IsAdmin && operatorModel.DbNumber == GlobalContext.SystemConfig.MainDbNumber)
{
operatorModel.IsSuperAdmin = true;
}
else
{
operatorModel.IsSuperAdmin = false;
}
//缓存保存用户信息
await OperatorProvider.Provider.AddLoginUser(operatorModel, "", "pc_");
//防重复token
string token = Utils.GuId();
HttpContext.Response.Cookies.Append("pc_" + GlobalContext.SystemConfig.TokenName, token);
await CacheHelper.SetAsync("pc_" + GlobalContext.SystemConfig.TokenName + "_" + operatorModel.UserId + "_" + operatorModel.LoginTime, token, GlobalContext.SystemConfig.LoginExpire, true);
logEntity.F_Account = userEntity.F_Account;
logEntity.F_NickName = userEntity.F_RealName;
logEntity.F_Result = true;
logEntity.F_Description = "登录成功";
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity, operatorModel));
//验证回退路由是否有权限,没有就删除
await CheckReturnUrl(operatorModel.UserId);
return Content(new AlwaysResult { state = ResultType.success.ToString(), message = "登录成功。" }.ToJson());
}
catch (Exception ex)
{
logEntity.F_Account = username;
logEntity.F_NickName = username;
logEntity.F_Result = false;
logEntity.F_Description = "登录失败," + ex.Message;
await GlobalContext.GetService<IEventPublisher>().PublishAsync(new BaseEventSource("Log:create", logEntity));
return Content(new AlwaysResult { state = ResultType.error.ToString(), message = ex.Message }.ToJson());
}
}
private async Task CheckReturnUrl(string userId)
{
var realurl = WebHelper.GetCookie("wc_realreturnurl");
var url = WebHelper.GetCookie("wc_returnurl");
if (!string.IsNullOrEmpty(realurl) && !await _roleAuthServuce.CheckReturnUrl(userId, realurl))
{
WebHelper.RemoveCookie("wc_realreturnurl");
}
if (!string.IsNullOrEmpty(url) && !await _roleAuthServuce.CheckReturnUrl(userId, url))
{
WebHelper.RemoveCookie("wc_returnurl");
}
}
}
}