完成范例接口
This commit is contained in:
parent
e8b2796f66
commit
5fc4020f46
|
@ -7,7 +7,7 @@ namespace FAuth.Controllers
|
|||
/// <summary>
|
||||
/// 控制器类基类
|
||||
/// </summary>
|
||||
public abstract class ControllerBase:Controller
|
||||
public abstract class ControllerBase<LoggerType>:Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志记录服务
|
||||
|
@ -23,7 +23,7 @@ namespace FAuth.Controllers
|
|||
/// </summary>
|
||||
/// <param name="logger">控制器日志组件</param>
|
||||
/// <param name="service">服务集合</param>
|
||||
public ControllerBase(ILogger logger,IServiceProvider service) {
|
||||
public ControllerBase(ILogger<LoggerType> logger,IServiceProvider service) {
|
||||
this.Logger = logger;
|
||||
this.Services = service;
|
||||
}
|
||||
|
|
|
@ -12,14 +12,9 @@ namespace FAuth.Controllers
|
|||
/// <summary>
|
||||
/// Home控制器
|
||||
/// </summary>
|
||||
public class HomeController:ControllerBase
|
||||
public class HomeController:ControllerBase<HomeController>
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成控制器
|
||||
/// </summary>
|
||||
/// <param name="logger">日志组件</param>
|
||||
/// <param name="service">服务集合</param>
|
||||
public HomeController(ILogger logger,IServiceProvider service) : base(logger,service) {
|
||||
public HomeController(ILogger<HomeController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
|
||||
public IActionResult Index() {
|
||||
|
|
14
FAuth/Controllers/api/AccountController.cs
Normal file
14
FAuth/Controllers/api/AccountController.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
public class AccountController:ApiControllerBase<AccountController>
|
||||
{
|
||||
public AccountController(ILogger<AccountController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
}
|
||||
}
|
16
FAuth/Controllers/api/ApiControllerBase.cs
Normal file
16
FAuth/Controllers/api/ApiControllerBase.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
/// <summary>
|
||||
/// api控制器基类
|
||||
/// </summary>
|
||||
[ApiController, Route("api/[Controller]/[Action]")]
|
||||
public abstract class ApiControllerBase<LoggerType>:ControllerBase<LoggerType>
|
||||
{
|
||||
public ApiControllerBase(ILogger<LoggerType> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
}
|
||||
}
|
59
FAuth/Controllers/api/UserController.cs
Normal file
59
FAuth/Controllers/api/UserController.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FAuth.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FAuth.DataBase.Tables;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户相关api控制器接口
|
||||
/// </summary>
|
||||
public class UserController:ApiControllerBase<UserController>
|
||||
{
|
||||
public UserController(ILogger<UserController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证用户名密码是否匹配
|
||||
/// </summary>
|
||||
/// <param name="userName">用户名</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <returns>是否匹配</returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(CheckUserResult),200)]
|
||||
public CheckUserResult CheckUser(string userName,string password) {
|
||||
return new CheckUserResult {
|
||||
Result = userName == password,
|
||||
Ticket = Guid.NewGuid().ToString(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户凭据获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="ticket">登录票据</param>
|
||||
/// <returns>用户信息</returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(UserInfo),200)]
|
||||
public UserInfo GetUserByTicket(string ticket) {
|
||||
return new UserInfo {
|
||||
UserName = "aaa"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据提供的登陆票据修改用户密码
|
||||
/// </summary>
|
||||
/// <param name="ticket">票据</param>
|
||||
/// <param name="nPassword">新密码</param>
|
||||
/// <returns>是否成功</returns>
|
||||
[HttpPost]
|
||||
public bool ChangePassword(string ticket,string nPassword) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
27
FAuth/DataBase/Tables/FUser.cs
Normal file
27
FAuth/DataBase/Tables/FUser.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
|
||||
namespace FAuth.DataBase.Tables
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户信息
|
||||
/// </summary>
|
||||
public class FUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户流水编号
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 用户安全编号
|
||||
/// </summary>
|
||||
public Guid SId { get; set; }
|
||||
/// <summary>
|
||||
/// 用户登录名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
/// <summary>
|
||||
/// 登录密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
|
@ -15,10 +15,6 @@
|
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\api\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
|
22
FAuth/Models/CheckUserResult.cs
Normal file
22
FAuth/Models/CheckUserResult.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FAuth.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户密码验证结果
|
||||
/// </summary>
|
||||
public class CheckUserResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证结果
|
||||
/// </summary>
|
||||
public bool Result { get; set; }
|
||||
/// <summary>
|
||||
/// 票据
|
||||
/// </summary>
|
||||
public string Ticket { get; set; }
|
||||
}
|
||||
}
|
19
FAuth/Models/UserInfo.cs
Normal file
19
FAuth/Models/UserInfo.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FAuth.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户信息
|
||||
/// </summary>
|
||||
public class UserInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户登录名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using FAuth.DataBase;
|
|||
using FAuth.Extensions;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.Extensions.Caching.Redis;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -53,7 +54,11 @@ namespace FAuth
|
|||
c.SwaggerDoc("V1",new OpenApiInfo {
|
||||
Title = "½Ó¿ÚÎĵµ",
|
||||
Version = "1.0",
|
||||
Description = "",
|
||||
Description = "api",
|
||||
Contact = new OpenApiContact {
|
||||
Name = "Falcon",
|
||||
Url = new Uri("http://39.105.71.191/Falcon/FAuth"),
|
||||
},
|
||||
});
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory,typeof(Program).Assembly.GetName().Name + ".xml");
|
||||
c.IncludeXmlComments(xmlPath,true);
|
||||
|
@ -78,7 +83,7 @@ namespace FAuth
|
|||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => {
|
||||
c.SwaggerEndpoint("/swagger/V1/swagger.json","½Ó¿ÚÎĵµ");
|
||||
c.RoutePrefix = "";
|
||||
c.RoutePrefix = "api";
|
||||
});
|
||||
|
||||
app.UseAuthorization();
|
||||
|
|
Loading…
Reference in New Issue
Block a user