Exemplo n.º 1
0
        public ResultClass <UserEntity> CheckLogin(string username, string password)
        {
            ResultClass <UserEntity> _ret = new ResultClass <UserEntity>();
            UserApp bll = new UserApp();

            try
            {
                _ret.ResultData = bll.CheckLogin(username, password);
                if (_ret.ResultData != null)
                {
                    _ret.Result = true;
                    #region 生成且保存用户票据
                    _ret.ErrorMessage = "20171225";                                   //System.DateTime.Now.ToString("yyyyMMddHHmmss");//把票据返回给前端
                    HttpContext.Current.Session[_ret.ErrorMessage] = _ret.ResultData; //保存票据信息
                    #endregion
                }
            }
            catch (Exception ex)
            {
                _ret.ErrorMessage = ex.Message;
            }
            finally
            {
                bll.Dispose();
            }
            return(_ret);
        }
        public async Task <ActionResult> CheckLogin(string username, string password, string code)
        {
            //初始化登录日志
            LogEntity logEntity = new LogEntity();

            logEntity.ModuleName = "系统登录";
            logEntity.Type       = DbLogType.Login.ToString();
            try
            {
                //验证 '验证码'
                var verifyCodeInSession = WebHelper.GetSession("evolution_session_verifycode", HttpContext);
                if (verifyCodeInSession.IsEmpty() || Md5.md5(code.ToLower(), 16) != verifyCodeInSession)
                {
                    throw new Exception("验证码错误,请重新输入!");
                }
                //验证用户名密码
                var userEntity = await userApp.CheckLogin(username, password);

                var role = await roleApp.GetRoleById(userEntity.RoleId);

                //设置登录对象
                LoginModel operatorModel = CreateLoginModel(userEntity, role);
                //写入登录日志
                logEntity.Account     = userEntity.Account;
                logEntity.NickName    = userEntity.RealName;
                logEntity.Result      = true;
                logEntity.Description = "登录成功";
                await logApp.WriteDbLog(logEntity, HttpContext);

                //登录
                logonApp.SignIn(operatorModel, HttpContext);

                return(Content(new AjaxResult {
                    state = ResultType.success.ToString(), message = "登录成功。"
                }.ToJson()));
            }
            catch (Exception ex)
            {
                logEntity.Account     = username;
                logEntity.NickName    = username;
                logEntity.Result      = false;
                logEntity.Description = "登录失败," + ex.Message;
                await logApp.WriteDbLog(logEntity, HttpContext);

                return(Content(new AjaxResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> CheckLogin(string username, string password, string code)
        {
            LogEntity logEntity = new LogEntity();

            logEntity.F_ModuleName = "系统登录";
            logEntity.F_Type       = DbLogType.Login.ToString();
            try
            {
                if (NFine.Code.WebHelper.GetSession("nfine_session_verifycode").IsEmpty() || EncryptProvider.Md5(code.ToLower(), Code.Internal.MD5Length.L16) != NFine.Code.WebHelper.GetSession("nfine_session_verifycode").ToString())
                {
                    throw new Exception("验证码错误,请重新输入");
                }

                UserEntity userEntity = userApp.CheckLogin(username, password);
                if (userEntity != null)
                {
                    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     = Net.Ip;
                    operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress);
                    operatorModel.LoginTime          = DateTime.Now;
                    operatorModel.LoginToken         = EncryptProvider.DESEncrypt(Guid.NewGuid().ToString());
                    if (userEntity.F_Account == "admin")
                    {
                        operatorModel.IsSystem = true;
                    }
                    else
                    {
                        operatorModel.IsSystem = false;
                    }
                    await OperatorProvider.Provider.AddCurrent(operatorModel);

                    logEntity.F_Account         = userEntity.F_Account;
                    logEntity.F_NickName        = userEntity.F_RealName;
                    logEntity.F_Result          = true;
                    logEntity.F_Description     = "登录成功";
                    logEntity.F_CreatorUserId   = operatorModel.UserId;
                    logEntity.F_CreatorUserName = operatorModel.UserName;
                    logApp.WriteDbLog(logEntity);
                }
                return(Content(new AjaxResult {
                    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;
                logEntity.F_CreatorUserId   = username;
                logEntity.F_CreatorUserName = username;
                logApp.WriteDbLog(logEntity);
                return(Content(new AjaxResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }
Exemplo n.º 4
0
 public NFine.Domain.Entity.SystemManage.UserEntity Login(string UserName, string PassWord)
 {
     return(UserApp.CheckLogin(UserName, PassWord));
 }