修改授权方式为手机号码和验证码方式
测试出的问题修复
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Service;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DataEncryption;
|
||||
using Furion.DataEncryption.Extensions;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
@@ -9,9 +11,11 @@ using Furion.RemoteRequest.Extensions;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Minio;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -39,6 +43,9 @@ namespace Vote.Services.ApiController
|
||||
private readonly SqlSugarRepository<SysFile> rep_SysFile;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
readonly IOptions<UploadFileOptions> _options;
|
||||
private readonly SqlSugarRepository<Entities.nbzc_sms_code> repSmsCode;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IUserManager _userManager; // 用户管理
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -47,7 +54,7 @@ namespace Vote.Services.ApiController
|
||||
/// <param name="_repoutside_wall_building_photo"></param>
|
||||
/// <param name="_repoutside_wall_photo"></param>
|
||||
/// <param name="memoryCache"></param>
|
||||
public OutsideWallService(SqlSugarRepository<Entities.Experts> repoutsideExperts, SqlSugarRepository<Entities.outside_wall> _repoutside_wall, SqlSugarRepository<Entities.outside_wall_building> _repoutside_wall_building, SqlSugarRepository<Entities.outside_wall_building_photo> _repoutside_wall_building_photo, SqlSugarRepository<Entities.outside_wall_photo> _repoutside_wall_photo, IMemoryCache memoryCache, SqlSugarRepository<SysFile> _rep_SysFile, IOptions<UploadFileOptions> options)
|
||||
public OutsideWallService(SqlSugarRepository<Entities.Experts> repoutsideExperts, SqlSugarRepository<Entities.outside_wall> _repoutside_wall, SqlSugarRepository<Entities.outside_wall_building> _repoutside_wall_building, SqlSugarRepository<Entities.outside_wall_building_photo> _repoutside_wall_building_photo, SqlSugarRepository<Entities.outside_wall_photo> _repoutside_wall_photo, IMemoryCache memoryCache, SqlSugarRepository<SysFile> _rep_SysFile, IOptions<UploadFileOptions> options, SqlSugarRepository<Entities.nbzc_sms_code> _repSmsCode, IHttpContextAccessor httpContextAccessor, IUserManager userManager)
|
||||
{
|
||||
_repoutsideExperts = repoutsideExperts;
|
||||
repoutside_wall = _repoutside_wall;
|
||||
@@ -57,6 +64,9 @@ namespace Vote.Services.ApiController
|
||||
_memoryCache = memoryCache;
|
||||
_options = options;
|
||||
rep_SysFile = _rep_SysFile;
|
||||
this.repSmsCode = _repSmsCode;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userManager = userManager;
|
||||
}
|
||||
/// <summary>
|
||||
/// 导出Excel
|
||||
@@ -206,7 +216,7 @@ namespace Vote.Services.ApiController
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
//[AllowAnonymous]
|
||||
[HttpPost("sysFileInfo/upload")]
|
||||
public async Task<string> UploadFileDefault(IFormFile file)
|
||||
{
|
||||
@@ -315,7 +325,61 @@ namespace Vote.Services.ApiController
|
||||
|
||||
|
||||
|
||||
#region 调查页
|
||||
#region 调查页
|
||||
|
||||
/// <summary>
|
||||
/// 授权验证
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("VerifyIsLogin")]
|
||||
public async Task<bool> VerifyIsLogin()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 授权验证
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("VerifyLogin")]
|
||||
[AllowAnonymous]
|
||||
public async Task<dynamic> VerifyLogin(VerifyLoginInput args)
|
||||
{
|
||||
_ = args == null ? throw Oops.Oh("参数异常") : 1;
|
||||
var passed = false;
|
||||
var entity = await repSmsCode.AsQueryable().Where(p => p.phone == args.phone && !p.IsDeleted && p.code.Trim() == args.code.Trim() && p.expire_time > DateTime.Now).FirstAsync();
|
||||
if (entity != null)
|
||||
{
|
||||
passed = true;
|
||||
entity.IsDeleted = true;
|
||||
await repSmsCode.UpdateAsync(entity);
|
||||
var token = await HandlerLoginAsync(args);
|
||||
return new { passed, token };
|
||||
}
|
||||
return new { passed, token = "" };
|
||||
}
|
||||
private async Task<string> HandlerLoginAsync(VerifyLoginInput args)
|
||||
{
|
||||
// 生成Token令牌
|
||||
//var accessToken = await _jwtBearerManager.CreateTokenAdmin(user);
|
||||
var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>
|
||||
{
|
||||
{ ClaimConst.CLAINM_USERID, args.phone },
|
||||
{ ClaimConst.CLAINM_ACCOUNT, args.phone},
|
||||
{ ClaimConst.CLAINM_NAME, args.phone},
|
||||
{ ClaimConst.ExpireTime,DateTime.Now.AddMinutes(60)},
|
||||
});
|
||||
|
||||
// 设置Swagger自动登录
|
||||
_httpContextAccessor.HttpContext.SigninToSwagger(accessToken);
|
||||
|
||||
// 生成刷新Token令牌
|
||||
var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30);
|
||||
|
||||
// 设置刷新Token令牌
|
||||
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
/// <summary>
|
||||
/// 授权验证
|
||||
/// </summary>
|
||||
@@ -331,7 +395,7 @@ namespace Vote.Services.ApiController
|
||||
/// 获取三居系统中的社区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
//[AllowAnonymous]
|
||||
[HttpGet("communitys")]
|
||||
public async Task<List<SanjuCommunity>> GetCommunitys(string searchkey)
|
||||
{
|
||||
@@ -396,20 +460,15 @@ namespace Vote.Services.ApiController
|
||||
/// <returns></returns>
|
||||
[Consumes("application/json", "multipart/form-data")]
|
||||
[HttpPost("submit")]
|
||||
[AllowAnonymous]
|
||||
public async Task<dynamic> Submit([FromForm] OutsideWallInput args, [FromQuery] string key)
|
||||
//[AllowAnonymous]
|
||||
public async Task<dynamic> Submit([FromForm] OutsideWallInput args)
|
||||
{
|
||||
var verifyKey = await _repoutsideExperts.IsExistsAsync(f => f.login_code.ToUpper() == key.ToUpper());
|
||||
if (!verifyKey)
|
||||
{
|
||||
throw Oops.Oh("授权码错误");
|
||||
}
|
||||
try
|
||||
{
|
||||
//string key = GetCode(6, true);
|
||||
repoutside_wall.Ado.BeginTran();
|
||||
var wall = args.Adapt<outside_wall>();
|
||||
wall.submitCode = key;
|
||||
wall.submitCode = _userManager.Account;
|
||||
wall.Id = Guid.NewGuid().ToString();
|
||||
wall.createtime = DateTime.Now;
|
||||
wall.isdeleted = 0;
|
||||
@@ -425,31 +484,34 @@ namespace Vote.Services.ApiController
|
||||
});
|
||||
}
|
||||
}
|
||||
foreach (var item in args.buildings)
|
||||
if (args.buildings != null)
|
||||
{
|
||||
if (!item.curwallproblems.Any())
|
||||
continue;
|
||||
var build = item.Adapt<outside_wall_building>();
|
||||
build.Id = Guid.NewGuid().ToString();
|
||||
build.outsidewallId = wall.Id;
|
||||
build.BuildingId = build.Id;
|
||||
build.createtime = DateTime.Now;
|
||||
build = await repoutside_wall_building.InsertReturnEntityAsync(build);
|
||||
if (item.problemfiles != null)
|
||||
foreach (var item in args.buildings)
|
||||
{
|
||||
foreach (var item1 in item.problemfiles)
|
||||
if (!item.curwallproblems.Any())
|
||||
continue;
|
||||
var build = item.Adapt<outside_wall_building>();
|
||||
build.Id = Guid.NewGuid().ToString();
|
||||
build.outsidewallId = wall.Id;
|
||||
build.BuildingId = build.Id;
|
||||
build.createtime = DateTime.Now;
|
||||
build = await repoutside_wall_building.InsertReturnEntityAsync(build);
|
||||
if (item.problemfiles != null)
|
||||
{
|
||||
await repoutside_wall_building_photo.InsertReturnEntityAsync(new outside_wall_building_photo
|
||||
foreach (var item1 in item.problemfiles)
|
||||
{
|
||||
outsidewallBuildingId = build.Id,
|
||||
sysfileid = item1.file,
|
||||
toward = item1.Toward
|
||||
});
|
||||
await repoutside_wall_building_photo.InsertReturnEntityAsync(new outside_wall_building_photo
|
||||
{
|
||||
outsidewallBuildingId = build.Id,
|
||||
sysfileid = item1.file,
|
||||
toward = item1.Toward
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repoutside_wall.Ado.CommitTran();
|
||||
return key;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user