Exemplo n.º 1
0
        public ActionResult LoginOn(string username, string password, string captcha)
        {
            LogonLogModel logEntity        = new LogonLogModel();
            var           OperatorProvider = new OperatorProvider(HttpContext);

            logEntity.LogType = DbLogType.Login.ToString();
            try
            {
                if (OperatorProvider.WebHelper.GetSession("session_verifycode").IsEmpty() || Md5.md5(captcha.ToLower(), 16) != OperatorProvider.WebHelper.GetSession("session_verifycode"))
                {
                    throw new Exception("验证码错误");
                }
                UserModel userEntity = UserService.LoginOn(username, Md5.md5(password, 32));
                if (userEntity != null)
                {
                    if (userEntity.EnabledMark == 1)
                    {
                        throw new Exception("账号被锁定,禁止登录");
                    }
                    OperatorModel operatorModel = new OperatorModel();
                    operatorModel.UserId             = userEntity.Id;
                    operatorModel.Account            = userEntity.Account;
                    operatorModel.RealName           = userEntity.RealName;
                    operatorModel.HeadIcon           = userEntity.HeadIcon;
                    operatorModel.RoleId             = userEntity.RoleId;
                    operatorModel.LoginIPAddress     = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    operatorModel.LoginIPAddressName = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    OperatorProvider.AddCurrent(operatorModel);
                    logEntity.Account     = userEntity.Account;
                    logEntity.RealName    = userEntity.RealName;
                    logEntity.Description = "登陆成功";
                    LogonLogService.WriteDbLog(logEntity, operatorModel.LoginIPAddress, operatorModel.LoginIPAddressName);
                    return(Content(new AjaxResult {
                        state = ResultType.success.ToString(), message = "登录成功"
                    }.ToJson()));
                }
                else
                {
                    throw new Exception("用户名或密码错误");
                }
            }
            catch (Exception ex)
            {
                logEntity.Account     = username;
                logEntity.RealName    = username;
                logEntity.Description = "登录失败," + ex.Message;
                LogonLogService.WriteDbLog(logEntity, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.Connection.RemoteIpAddress.ToString());
                return(Content(new AjaxResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }
Exemplo n.º 2
0
        public ActionResult UserLogin(string str, string pwd, string isCheck, string vcode)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(Content("no,提示:请输入您的用户名或手机号!"));
            }
            if (string.IsNullOrEmpty(pwd))
            {
                return(Content("no,提示:请输入您的登录密码!"));
            }
            // 校验验证码
            var session = Session["user_vcode"].ToString() == null?"": Session["user_vcode"].ToString();

            if (string.IsNullOrEmpty(vcode) || session != vcode.ToString())
            {
                return(Content("no,提示:验证码错误!"));
            }
            string msg      = string.Empty;
            User   userInfo = null;
            Log    log      = new Log();

            if (IocUtils.Resolve <IUserService>().Login(str, pwd, out msg, out userInfo))
            {
                //添加当前用户
                FrontCurrentUser currentUser = new FrontCurrentUser()
                {
                    UserId          = userInfo.UserId,
                    UserAccount     = userInfo.UserName,
                    UserPwd         = userInfo.Password,
                    Last_Login_IP   = userInfo.Last_Login_IP,
                    Last_Login_Time = userInfo.Last_Login_Time,
                    Intro           = userInfo.Intro,
                    HomePage_Img    = userInfo.HomePage_Img,
                    HeadImg         = userInfo.HeadImg,
                    CurrentCity     = userInfo.CurrentCity,
                    LoginToken      = DESEncrypt.Encrypt(Guid.NewGuid().ToString())
                };
                OperatorProvider <FrontCurrentUser> provider = new OperatorProvider <FrontCurrentUser>();
                provider.AddCurrent(currentUser);
                //写日志
                log.Title = userInfo.UserName;
                log.Msg   = "个人中心用户登录成功";
                log.IP    = Net.Ip;
                IocUtils.Resolve <ILogService>().Insert(log);
                // Session["current_user"] = userInfo;
                if (!string.IsNullOrEmpty(isCheck))
                {
                    CookieHelper.SetCookie("sb1", userInfo.UserName, DateTime.Now.AddDays(7));
                    CookieHelper.SetCookie("sb2", DESEncrypt.Encrypt(userInfo.Password), DateTime.Now.AddDays(7));
                }
                return(Content(msg));
            }
            else
            {
                log.Title = userInfo.UserName;
                log.Msg   = "个人中心用户登录失败" + msg;
                log.IP    = Net.Ip;
                IocUtils.Resolve <ILogService>().Insert(log);
                return(Content(msg));
            }
        }
Exemplo n.º 3
0
        public ActionResult CheckLogin(string username, string password, string code)
        {
            LogModel logEntity        = new LogModel();
            var      OperatorProvider = new OperatorProvider(HttpContext);

            logEntity.ModuleName = "系统登录";
            logEntity.LogType    = DbLogType.Login.ToString();
            try
            {
                if (OperatorProvider.WebHelper.GetSession("session_verifycode").IsEmpty() || Md5.md5(code.ToLower(), 16) != OperatorProvider.WebHelper.GetSession("session_verifycode"))
                {
                    throw new Exception("验证码错误,请重新输入");
                }
                UserModel userEntity = userService.CheckLogin(username, password);
                if (userEntity != null)
                {
                    OperatorModel operatorModel = new OperatorModel();
                    operatorModel.UserId         = userEntity.Id;
                    operatorModel.UserName       = userEntity.UserName;
                    operatorModel.RealName       = userEntity.RealName;
                    operatorModel.RoleId         = userEntity.RoleId;
                    operatorModel.HeadShot       = userEntity.HeadShot;
                    operatorModel.LoginIPAddress = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    //operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress);
                    operatorModel.LoginIPAddressName = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                    operatorModel.LoginTime          = DateTime.Now;
                    operatorModel.LoginToken         = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
                    if (userEntity.UserName == "admin")
                    {
                        operatorModel.IsSystem = true;
                    }
                    else
                    {
                        operatorModel.IsSystem = false;
                    }
                    OperatorProvider.AddCurrent(operatorModel);
                    logEntity.UserName    = userEntity.UserName;
                    logEntity.RealName    = userEntity.RealName;
                    logEntity.Status      = true;
                    logEntity.Description = "登录成功";
                    logEntity.CreateBy    = userEntity.Id;
                    logService.WriteDbLog(logEntity, operatorModel.LoginIPAddress, operatorModel.LoginIPAddressName);
                    return(Content(new AjaxResult {
                        state = ResultType.success.ToString(), message = "登录成功。"
                    }.ToJson()));
                }
                else
                {
                    throw new Exception("用户名或密码错误。");
                }
            }
            catch (Exception ex)
            {
                logEntity.UserName    = username;
                logEntity.RealName    = username;
                logEntity.Status      = false;
                logEntity.Description = "登录失败," + ex.Message;
                logService.WriteDbLog(logEntity, HttpContext.Connection.RemoteIpAddress.ToString(), HttpContext.Connection.RemoteIpAddress.ToString());
                return(Content(new AjaxResult {
                    state = ResultType.error.ToString(), message = ex.Message
                }.ToJson()));
            }
        }