添加登录注册业务

This commit is contained in:
橙子
2022-04-07 22:48:10 +08:00
parent 4472e4aa6f
commit 0fba47207f
31 changed files with 24606 additions and 85 deletions

View File

@@ -4,5 +4,59 @@
<name>Yi.Framework.ApiMicroservice</name>
</assembly>
<members>
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
<summary>
6666
</summary>
<typeparam name="T"></typeparam>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.#ctor(Microsoft.Extensions.Logging.ILogger{`0},Yi.Framework.Repository.IRepository{`0})">
<summary>
jb
</summary>
<param name="logger"></param>
<param name="iRepository"></param>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Get(System.Object)">
<summary>
主键查询
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.GetList">
<summary>
列表查询
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Page(Yi.Framework.Model.Query.QueryCondition)">
<summary>
条件分页查询
</summary>
<param name="queryCondition"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Add(`0)">
<summary>
添加
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Update(`0)">
<summary>
修改
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.DeleteList(System.Object[])">
<summary>
列表删除
</summary>
<param name="ids"></param>
<returns></returns>
</member>
</members>
</doc>

View File

@@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class AccountController :ControllerBase
{
private IUserService _iUserService;
public AccountController(ILogger<UserEntity> logger, IUserService iUserService)
{
_iUserService = iUserService;
}
[AllowAnonymous]
[HttpPost]
public async Task<Result> Login(LoginDto loginDto)
{
UserEntity user=new();
if (await _iUserService.Login(loginDto.UserName, loginDto.Password,o=> user=o))
{
return Result.Success("登录成功!").SetData(user);
}
return Result.SuccessError("登录失败!用户名或者密码错误!");
}
[AllowAnonymous]
[HttpPost]
public async Task<Result> Register(RegisterDto registerDto)
{
UserEntity user = new();
if (await _iUserService.Register(WebCore.Mapper.MapperHelper.Map<UserEntity, RegisterDto>(registerDto), o => user = o))
{
return Result.Success("注册成功!").SetData(user);
}
return Result.SuccessError("注册失败!用户名已存在!");
}
}
}

View File

@@ -6,48 +6,92 @@ using Yi.Framework.WebCore.AttributeExtend;
namespace Yi.Framework.ApiMicroservice.Controllers
{
/// <summary>
/// 6666
/// </summary>
/// <typeparam name="T"></typeparam>
[ApiController]
[Route("api/[controller]/[action]")]
public class BaseCrudController<T> : ControllerBase where T : class,new()
{
private readonly ILogger<T> _logger;
public IRepository<T> _iRepository;
/// <summary>
/// jb
/// </summary>
/// <param name="logger"></param>
/// <param name="iRepository"></param>
public BaseCrudController(ILogger<T> logger, IRepository<T> iRepository)
{
_logger = logger;
_iRepository = iRepository;
}
[Permission($"{nameof(T)}:Get:One")]
/// <summary>
/// 主键查询
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[Permission($"{nameof(T)}:get:one")]
[HttpGet]
public async Task<Result> Get(object id)
{
return Result.Success().SetData(await _iRepository.GetByIdAsync(id));
}
[Permission($"{nameof(T)}:Get:List")]
/// <summary>
/// 列表查询
/// </summary>
/// <returns></returns>
[Permission($"{nameof(T)}:get:list")]
[HttpGet]
public async Task<Result> GetList()
{
return Result.Success().SetData(await _iRepository.GetListAsync());
}
[Permission($"{nameof(T)}:Get:Page")]
/// <summary>
/// 条件分页查询
/// </summary>
/// <param name="queryCondition"></param>
/// <returns></returns>
[Permission($"{nameof(T)}:get:page")]
[HttpPost]
public async Task<Result> Page(QueryCondition queryCondition)
{
return Result.Success().SetData(await _iRepository.CommonPage(queryCondition));
}
[Permission($"{nameof(T)}:Add")]
/// <summary>
/// 添加
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[Permission($"{nameof(T)}:add")]
[HttpPost]
public async Task<Result> Add(T entity)
{
return Result.Success().SetData(await _iRepository.InsertReturnEntityAsync(entity));
}
[Permission($"{nameof(T)}:Update")]
/// <summary>
/// 修改
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[Permission($"{nameof(T)}:update")]
[HttpPut]
public async Task<Result> Update(T entity)
{
return Result.Success().SetStatus(await _iRepository.UpdateAsync(entity));
}
[Permission($"{nameof(T)}:Delete:List")]
/// <summary>
/// 列表删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[Permission($"{nameof(T)}:delete:list")]
[HttpDelete]
public async Task<Result> DeleteList(object[] ids)
{

View File

@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class TenantController : BaseCrudController<TenantEntity>
{
public TenantController(ILogger<TenantEntity> logger, ITenantService iTenantService) : base(logger, iTenantService)
{
}
}
}

View File

@@ -22,12 +22,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
{
}
[HttpGet]
[Permission("user:query:list")]
public async Task<Result> PermissionTest()
{
return Result.Success().SetData( await _iRepository.GetListAsync());
}
}
}

View File

@@ -1,5 +1,5 @@
{
"StartUrl": "http://localohost:19001",
"StartUrl": "http://*:19001",
"Logging": {
"LogLevel": {
"Default": "Information",

View File

@@ -0,0 +1,8 @@
{
"apollo": {
"AppId": "ApiMicroservice",
"Env": "DEV",
"MetaServer": "http://119.91.207.67:18080",
"ConfigServer": [ "http://119.91.207.67:18080" ]
}
}