添加验证码
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.Extensions.Logging;
|
||||
using System;
|
||||
@@ -30,11 +31,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
private IUserService _iUserService;
|
||||
private JwtInvoker _jwtInvoker;
|
||||
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;
|
||||
_jwtInvoker = jwtInvoker;
|
||||
_logger = logger;
|
||||
_securityCode = securityCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +48,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[AllowAnonymous]
|
||||
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.BuildPassword();
|
||||
await _iUserService._repository.UpdateIgnoreNullAsync(user);
|
||||
@@ -160,7 +163,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
public async Task<Result> UpdatePassword(UpdatePasswordDto dto)
|
||||
{
|
||||
long userId = HttpContext.GetUserIdInfo();
|
||||
|
||||
|
||||
if (await _iUserService.UpdatePassword(dto, userId))
|
||||
{
|
||||
return Result.Success();
|
||||
@@ -174,9 +177,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[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() {
|
||||
return request({
|
||||
url: '/captchaImage',
|
||||
url: '/account/captchaImage',
|
||||
headers: {
|
||||
isToken: false
|
||||
},
|
||||
|
||||
@@ -129,8 +129,8 @@ function getCode() {
|
||||
getCodeImg().then(res => {
|
||||
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
||||
if (captchaEnabled.value) {
|
||||
codeUrl.value = "data:image/gif;base64," + res.img;
|
||||
loginForm.value.uuid = res.uuid;
|
||||
codeUrl.value = "data:image/gif;base64," + res.data.img;
|
||||
loginForm.value.uuid = res.data.uuid;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -188,10 +188,13 @@ getCookie();
|
||||
color: #bfbfbf;
|
||||
}
|
||||
.login-code {
|
||||
|
||||
width: 33%;
|
||||
height: 40px;
|
||||
float: right;
|
||||
|
||||
img {
|
||||
|
||||
cursor: pointer;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user