Пример #1
0
        public IActionResult Login(LoginRequest request)
        {
            if (ModelState.IsValid)
            {
                var ip = _qqWry.GetCurrentIP();


                if (_userInfoService.CheckPassword(request.UserName, request.Password))
                {
                    string loginInfo = "{0}-{1}-{2}";
                    var    result    = string.Format(loginInfo, request.UserName, ip, DateTime.Now.AddDays(30).Ticks);
                    return(Json(new
                    {
                        code = 0,
                        msg = "登录成功,",
                        data = new
                        {
                            token = _encryptionService.CommonEncrypt(result)
                        }
                    }));
                }


                return(Json(new
                {
                    code = -1,
                    msg = "登录失败;用户名、密码错误",
                    data = ""
                }));
            }
            else
            {
                return(Json(new
                {
                    code = -1,
                    msg = "登录失败;请输入用户名、密码",
                    data = ""
                }));
            }
        }