예제 #1
0
        public async Task <ActionResult> SubmitForm(SystemSetEntity entity, string keyValue)
        {
            try
            {
                await _service.SubmitForm(entity, keyValue);

                return(await Success("操作成功。", "", keyValue));
            }
            catch (Exception ex)
            {
                return(await Error(ex.Message, "", keyValue));
            }
        }
예제 #2
0
        public async Task <ActionResult> SetSubmitForm(SystemSetEntity entity)
        {
            var keyValue = _service.currentuser.CompanyId;

            try
            {
                entity.F_DeleteMark  = false;
                entity.F_EnabledMark = null;
                entity.F_EndTime     = null;
                await _service.SubmitForm(entity, keyValue);

                return(await Success("操作成功。", "", keyValue));
            }
            catch (Exception ex)
            {
                return(await Error(ex.Message, "", keyValue));
            }
        }
예제 #3
0
        public async Task <ActionResult> Login([FromQuery] string userName, [FromQuery] string password, [FromQuery] string localurl)
        {
            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(userName, Md5.md5(password, 32).ToLower(), localurl);

                OperatorModel operatorModel = new OperatorModel();
                operatorModel.UserId             = userEntity.F_Id;
                operatorModel.UserCode           = userEntity.F_Account;
                operatorModel.UserName           = userEntity.F_RealName;
                operatorModel.CompanyId          = userEntity.F_OrganizeId;
                operatorModel.DepartmentId       = userEntity.F_DepartmentId;
                operatorModel.RoleId             = userEntity.F_RoleId;
                operatorModel.LoginIPAddress     = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString();
                operatorModel.LoginIPAddressName = "本地局域网";//Net.GetLocation(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.IsLeaderInDepts    = userEntity.F_IsLeaderInDepts.Value;
                operatorModel.IsSenior           = userEntity.F_IsSenior.Value;
                SystemSetEntity setEntity = await _setService.GetForm(userEntity.F_OrganizeId);

                operatorModel.DbString   = setEntity.F_DbString;
                operatorModel.DBProvider = setEntity.F_DBProvider;
                if (userEntity.F_Account == "admin")
                {
                    operatorModel.IsSystem = true;
                }
                else
                {
                    operatorModel.IsSystem = false;
                }
                await OperatorProvider.Provider.AddLoginUser(operatorModel, apitoken, "api_", false);

                logEntity.F_Account     = userEntity.F_Account;
                logEntity.F_NickName    = userEntity.F_RealName;
                logEntity.F_Result      = true;
                logEntity.F_Description = "登录成功";
                await _logService.WriteDbLog(logEntity);

                return(Content(new AjaxResult <string> {
                    state = ResultType.success.ToString(), message = "登录成功。", data = apitoken
                }.ToJson()));
            }
            catch (Exception ex)
            {
                logEntity.F_Account     = userName;
                logEntity.F_NickName    = userName;
                logEntity.F_Result      = false;
                logEntity.F_Description = "登录失败," + ex.Message;
                await _logService.WriteDbLog(logEntity);

                return(Content(new AjaxResult <string> {
                    state = ResultType.error.ToString(), message = ex.Message, data = apitoken
                }.ToJson()));
            }
        }
예제 #4
0
        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.Debug)
            {
                localurl = "";
            }
            try
            {
                if (!await CheckIP())
                {
                    throw new Exception("IP受限");
                }
                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_OrganizeId;
                operatorModel.DepartmentId   = userEntity.F_DepartmentId;
                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.IsSystem        = userEntity.F_IsAdmin.Value;
                operatorModel.IsAdmin         = userEntity.F_IsAdmin.Value;
                operatorModel.IsBoss          = userEntity.F_IsBoss.Value;
                operatorModel.IsLeaderInDepts = userEntity.F_IsLeaderInDepts.Value;
                operatorModel.IsSenior        = userEntity.F_IsSenior.Value;
                SystemSetEntity setEntity = await _setService.GetForm(userEntity.F_OrganizeId);

                operatorModel.DbString   = setEntity.F_DbString;
                operatorModel.DBProvider = setEntity.F_DBProvider;
                if (userEntity.F_Account == GlobalContext.SystemConfig.SysemUserCode)
                {
                    operatorModel.IsSystem = true;
                }
                else
                {
                    operatorModel.IsSystem = false;
                }
                //缓存保存用户信息
                await OperatorProvider.Provider.AddLoginUser(operatorModel, "", "pc_");

                //防重复token
                string token = Utils.GuId();
                HttpContext.Response.Cookies.Append("pc_" + GlobalContext.SystemConfig.TokenName, token);
                await CacheHelper.Set("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 _logService.WriteDbLog(logEntity);

                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 _logService.WriteDbLog(logEntity);

                return(Content(new AlwaysResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }
예제 #5
0
        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.Debug)
            {
                localurl = "";
            }
            try
            {
                if (!await CheckIP())
                {
                    throw new Exception("IP受限");
                }
                UserEntity userEntity = await _userService.CheckLogin(username, password, localurl);

                var data = await _roleService.GetListOne(userEntity.F_DutyId);

                OperatorModel operatorModel = new OperatorModel();
                operatorModel.UserId             = userEntity.F_Id;
                operatorModel.UserCode           = userEntity.F_Account;
                operatorModel.UserName           = userEntity.F_RealName;
                operatorModel.CompanyId          = userEntity.F_OrganizeId;
                operatorModel.DepartmentId       = userEntity.F_DepartmentId;
                operatorModel.RoleId             = userEntity.F_RoleId;
                operatorModel.DefaultUrl         = data != null && data.Count > 0 ? data[0].F_Description : ""; //根据当前账号的“岗位”备注(URL),登录跳转默认首页。
                operatorModel.LoginIPAddress     = WebHelper.Ip;
                operatorModel.LoginIPAddressName = "本地局域网";                                                     //Net.GetLocation(operatorModel.LoginIPAddress);
                operatorModel.LoginTime          = DateTime.Now;
                operatorModel.DdUserId           = userEntity.F_DingTalkUserId;
                operatorModel.WxOpenId           = userEntity.F_WxOpenId;
                //各租户的管理员也是当前数据库的全部权限
                operatorModel.IsSystem        = userEntity.F_IsAdmin.Value;
                operatorModel.IsAdmin         = userEntity.F_IsAdmin.Value;
                operatorModel.IsBoss          = userEntity.F_IsBoss.Value;
                operatorModel.IsLeaderInDepts = userEntity.F_IsLeaderInDepts.Value;
                operatorModel.IsSenior        = userEntity.F_IsSenior.Value;
                SystemSetEntity setEntity = await _setService.GetForm(userEntity.F_OrganizeId);

                operatorModel.DbString   = setEntity.F_DbString;
                operatorModel.DBProvider = setEntity.F_DBProvider;
                if (userEntity.F_Account == "admin")
                {
                    operatorModel.IsSystem = true;
                }
                else
                {
                    operatorModel.IsSystem = false;
                }
                //缓存保存用户信息
                await OperatorProvider.Provider.AddLoginUser(operatorModel, "", "pc_");

                logEntity.F_Account     = userEntity.F_Account;
                logEntity.F_NickName    = userEntity.F_RealName;
                logEntity.F_Result      = true;
                logEntity.F_Description = "登录成功";
                await _logService.WriteDbLog(logEntity);

                return(Content(new AjaxResultUrl {
                    state = ResultType.success.ToString(), message = "登录成功。", url = operatorModel.DefaultUrl
                }.ToJson()));
            }
            catch (Exception ex)
            {
                logEntity.F_Account     = username;
                logEntity.F_NickName    = username;
                logEntity.F_Result      = false;
                logEntity.F_Description = "登录失败," + ex.Message;
                await _logService.WriteDbLog(logEntity);

                return(Content(new AjaxResultUrl {
                    state = ResultType.error.ToString(), message = ex.Message, url = ""
                }.ToJson()));
            }
        }