Example #1
0
        private bool AnalogLogon(AuthorizationContext filterContext, string LoginName, Operator Current)
        {
            bool needLogin = false;

            //当前用户未登录且SSO登录用户信息不为空,需要进行模拟登录
            if (Current == null && !string.IsNullOrEmpty(LoginName))
            {
                needLogin = true;
            }
            //判断当前用户是否登录如果登录了,检查当前登录的用户是否和SSO用户不一致,如果不一致就进行重写登录
            else if (Current != null && (Current.Account != LoginName))
            {
                LoginOut(filterContext);
                needLogin = true;
            }
            // 当前用户已经登录且用户相同,不需要登录
            else if (Current != null && (Current.Account == LoginName))
            {
                needLogin = false;
            }
            #region  模拟登录

            if (needLogin)
            {
                var userEntity = new UserBLL().CheckLogin(LoginName);
                if (userEntity != null)
                {
                    AuthorizeBLL authorizeBLL = new AuthorizeBLL();
                    Operator     operators    = new Operator();
                    operators.UserId       = userEntity.UserId;
                    operators.Account      = userEntity.Account;
                    operators.UserName     = userEntity.RealName;
                    operators.DepartmentId = userEntity.DepartmentId;
                    //operators.IPAddress = Net.Ip;
                    //operators.IPAddressName = IPLocation.GetLocation(Net.Ip);
                    operators.LogTime        = DateTime.Now;
                    operators.DepartmentName = userEntity.DepartmentName;
                    //写入当前用户数据权限
                    AuthorizeDataModel dataAuthorize = new AuthorizeDataModel();
                    //dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators);
                    dataAuthorize.GetReadProjectId = authorizeBLL.GetReadProjectId(operators);
                    //dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true);
                    //dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true);
                    operators.DataAuthorize = dataAuthorize;

                    OperatorProvider.Provider.AddCurrent(operators);
                    #region 写入登录日志
                    LogEntity logEntity = new LogEntity();
                    logEntity.CategoryId     = 1;
                    logEntity.OperateTypeId  = ((int)OperationType.Login).ToString();
                    logEntity.OperateType    = EnumAttribute.GetDescription(OperationType.Login);
                    logEntity.OperateAccount = userEntity.RealName;
                    logEntity.OperateUserId  = userEntity.UserId;
                    logEntity.Module         = "SSOLogin=>System";
                    //写入日志
                    logEntity.ExecuteResult     = 1;
                    logEntity.ExecuteResultJson = "登录成功";
                    logEntity.WriteLog();
                    #endregion
                }
            }
            #endregion
            return(true);
        }
Example #2
0
        public ActionResult CheckLogin(string username, string password, int autologin)
        {
            LogEntity logEntity = new LogEntity();

            logEntity.CategoryId     = 1;
            logEntity.OperateTypeId  = ((int)OperationType.Login).ToString();
            logEntity.OperateType    = EnumAttribute.GetDescription(OperationType.Login);
            logEntity.OperateAccount = username;
            logEntity.OperateUserId  = username;
            logEntity.Module         = Config.GetValue("SoftName");

            try
            {
                //#region 验证码验证
                //if (autologin == 0)
                //{
                //    verifycode = Md5Helper.MD5(verifycode.ToLower(), 16);
                //    if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString())
                //    {
                //        throw new Exception("验证码错误,请重新输入");
                //    }
                //}
                //#endregion

                #region 第三方账户验证 关闭该验证
                //AccountEntity accountEntity = accountBLL.CheckLogin(username, password);
                //if (accountEntity != null)
                //{
                //    Operator operators = new Operator();
                //    operators.UserId = accountEntity.AccountId;
                //    operators.Code = accountEntity.MobileCode;
                //    operators.Account = accountEntity.MobileCode;
                //    operators.UserName = accountEntity.FullName;
                //    operators.Password = accountEntity.Password;
                //    operators.IPAddress = Net.Ip;
                //    operators.IPAddressName = IPLocation.GetLocation(Net.Ip);
                //    operators.LogTime = DateTime.Now;
                //    operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
                //    operators.IsSystem = true;
                //    OperatorProvider.Provider.AddCurrent(operators);
                //    //登录限制
                //    LoginLimit(username, operators.IPAddress, operators.IPAddressName);
                //    return Success("登录成功。");
                //}
                #endregion

                #region 内部账户验证
                UserEntity userEntity = new UserBLL().CheckLogin(username, password);
                if (userEntity != null)
                {
                    AuthorizeBLL authorizeBLL = new AuthorizeBLL();
                    Operator     operators    = new Operator();
                    operators.UserId       = userEntity.UserId;
                    operators.Code         = userEntity.EnCode;
                    operators.Account      = userEntity.Account;
                    operators.UserName     = userEntity.RealName;
                    operators.Password     = userEntity.Password;
                    operators.Secretkey    = userEntity.Secretkey;
                    operators.CompanyId    = userEntity.OrganizeId;
                    operators.DepartmentId = userEntity.DepartmentId;
                    //operators.IPAddress = Net.Ip;
                    //operators.IPAddressName = IPLocation.GetLocation(Net.Ip);
                    operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId);
                    operators.LogTime  = DateTime.Now;
                    operators.Token    = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
                    //写入当前用户数据权限
                    AuthorizeDataModel dataAuthorize = new AuthorizeDataModel();
                    //dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators);
                    dataAuthorize.GetReadProjectId = authorizeBLL.GetReadProjectId(operators);
                    //dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators);
                    //dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true);
                    //dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true);
                    operators.DataAuthorize = dataAuthorize;
                    //判断是否系统管理员
                    if (userEntity.Account == "System")
                    {
                        operators.IsSystem = true;
                    }
                    else
                    {
                        operators.IsSystem = false;
                    }
                    OperatorProvider.Provider.AddCurrent(operators);

                    //写入日志
                    logEntity.ExecuteResult     = 1;
                    logEntity.ExecuteResultJson = "登录成功";
                    logEntity.WriteLog();
                }
                return(Success("登录成功。"));

                #endregion
            }
            catch (Exception ex)
            {
                WebHelper.RemoveCookie("movit_autologin");                  //清除自动登录
                logEntity.ExecuteResult     = -1;
                logEntity.ExecuteResultJson = ex.Message;
                logEntity.WriteLog();
                return(Error(ex.Message));
            }
        }