添加验证码
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Hei.Captcha;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
@@ -30,11 +31,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
private IUserService _iUserService;
|
private IUserService _iUserService;
|
||||||
private JwtInvoker _jwtInvoker;
|
private JwtInvoker _jwtInvoker;
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
private SecurityCodeHelper _securityCode;
|
||||||
|
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker, SecurityCodeHelper securityCode)
|
||||||
{
|
{
|
||||||
_iUserService = iUserService;
|
_iUserService = iUserService;
|
||||||
_jwtInvoker = jwtInvoker;
|
_jwtInvoker = jwtInvoker;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_securityCode = securityCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -45,7 +48,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<Result> RestCC()
|
public async Task<Result> RestCC()
|
||||||
{
|
{
|
||||||
var user= await _iUserService._repository.GetFirstAsync(u => u.UserName == "cc");
|
var user = await _iUserService._repository.GetFirstAsync(u => u.UserName == "cc");
|
||||||
user.Password = "123456";
|
user.Password = "123456";
|
||||||
user.BuildPassword();
|
user.BuildPassword();
|
||||||
await _iUserService._repository.UpdateIgnoreNullAsync(user);
|
await _iUserService._repository.UpdateIgnoreNullAsync(user);
|
||||||
@@ -174,9 +177,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<Result> CaptchaImage()
|
public Result CaptchaImage()
|
||||||
{
|
{
|
||||||
return Result.Success().SetData(new { uuid=123,img="123456789"});
|
var uuid = Guid.NewGuid();
|
||||||
|
var code = _securityCode.GetRandomEnDigitalText(4);
|
||||||
|
//将uuid与code中心化保存起来,登录根据uuid比对即可
|
||||||
|
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
|
||||||
|
return Result.Success().SetData(new { uuid = uuid, img = imgbyte });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export function logout() {
|
|||||||
// 获取验证码
|
// 获取验证码
|
||||||
export function getCodeImg() {
|
export function getCodeImg() {
|
||||||
return request({
|
return request({
|
||||||
url: '/captchaImage',
|
url: '/account/captchaImage',
|
||||||
headers: {
|
headers: {
|
||||||
isToken: false
|
isToken: false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -129,8 +129,8 @@ function getCode() {
|
|||||||
getCodeImg().then(res => {
|
getCodeImg().then(res => {
|
||||||
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
||||||
if (captchaEnabled.value) {
|
if (captchaEnabled.value) {
|
||||||
codeUrl.value = "data:image/gif;base64," + res.img;
|
codeUrl.value = "data:image/gif;base64," + res.data.img;
|
||||||
loginForm.value.uuid = res.uuid;
|
loginForm.value.uuid = res.data.uuid;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -188,10 +188,13 @@ getCookie();
|
|||||||
color: #bfbfbf;
|
color: #bfbfbf;
|
||||||
}
|
}
|
||||||
.login-code {
|
.login-code {
|
||||||
|
|
||||||
width: 33%;
|
width: 33%;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
float: right;
|
float: right;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user