Пример #1
0
        public IActionResult Login([FromBody] LoginDto parm)
        {
            var captchaCode = RedisServer.Cache.Get($"Captcha:{parm.Uuid}");

            RedisServer.Cache.Del($"Captcha:{parm.Uuid}");

            if (parm.Code.ToUpper() != captchaCode)
            {
                return(ToResponse(StatusCodeType.Error, "输入验证码无效"));
            }
            var userInfo = _userService.GetFirst(o => o.UserID == parm.UserName.Trim() || o.Phone == parm.UserName.Trim());

            if (userInfo == null)
            {
                return(ToResponse(StatusCodeType.Error, "用户名或密码错误"));
            }

            if (!PasswordUtil.ComparePasswords(userInfo.UserID, userInfo.Password, parm.PassWord.Trim()))
            {
                return(ToResponse(StatusCodeType.Error, "用户名或密码错误"));
            }

            if (!userInfo.Enabled)
            {
                return(ToResponse(StatusCodeType.Error, "用户未启用,请联系管理员!"));
            }

            var userToken = _tokenManager.CreateSession(userInfo, SourceType.Web, Convert.ToInt32(AppSettings.Configuration["AppSettings:WebSessionExpire"]));

            return(ToResponse(userToken));
        }
Пример #2
0
        public JsonResult Login(LoginRequest req)
        {
            var returnUrl    = "/";
            var referral     = Request.QueryString["ref"];
            var responseData = new LoginResponse();

            if (req.Type == "web")
            {
                var loginService = new LoginService();
                responseData = loginService.WebLogin(req.UserName, EncryptionClass.Md5Hash(req.Password), returnUrl, req.KeepMeSignedInCheckBox);
            }

            if (responseData.Code == "200")
            {
                var session = new M2ESession(req.UserName);
                TokenManager.CreateSession(session);
                responseData.UTMZT = session.SessionId;
            }
            var response = new ResponseModel <LoginResponse> {
                Status = Convert.ToInt32(responseData.Code), Message = "success", Payload = responseData
            };

            return(Json(response));
        }