예제 #1
0
        public ResponseResult Register(
            [FromServices] ICheckCodeService checkCodeService,
            [FromForm] string codeid,
            [FromForm] string code,
            [FromForm] string userName
            )
        {
            if (!checkCodeService.IsValidCode(codeid, code))
            {
                return(ResponseResult.Error);
            }

            return(ResponseResult.Success);
        }
예제 #2
0
        public ResponseResult GetCheckCode(
            [FromServices] ICheckCodeService checkCodeService,
            [FromForm] int width  = 0,
            [FromForm] int height = 30
            )
        {
            var capcha = new Captcha();
            var code   = capcha.GenerateCode(4);
            var codeid = checkCodeService.SetCheckCode(code);
            var base64 = "data:image/png;base64," + capcha.GenerateImage(code, width, height);

            return(_response.Success(new
            {
                codeid,
                image = base64
            }));
        }
예제 #3
0
        public ResponseResult Login(
            [FromServices] ILoginService loginService,
            [FromServices] ICheckCodeService checkCodeService,
            [FromForm] string codeid,
            [FromForm] string code,
            [FromForm] string userName
            )
        {
            // 验证->验证码
            if (!checkCodeService.IsValidCode(codeid, code))
            {
                return(ResponseResult.Error);
            }

            // 登录成功,保存登录信息
            var token = loginService.Login(new UserInfo(userName.GetHashCode(), userName, UserRole.User, 1));

            return(_response.Success(new
            {
                token
            }));
        }