Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public IActionResult ResetPassword([FromBody] UsersResetPasswordDto parm)
        {
            var userSession = _tokenManager.GetSessionInfo();

            if (_usersService.GetFirst(m => m.ID == parm.ID) == null)
            {
                return(toResponse(StatusCodeType.Error, "当前用户不存在,请核对"));
            }

            // 更新用户密码
            var response = _usersService.Update(m => m.UserID == parm.UserID, m => new Sys_Users()
            {
                Password = PasswordUtil.CreateDbPassword(parm.ID, parm.ConfirmPassword.Trim())
            });

            // 删除登录会话记录
            _tokenManager.RemoveAllSession(parm.UserID);

            return(toResponse(response));
        }