完成范例接口

This commit is contained in:
falcon 2020-03-30 16:10:51 +08:00
parent e8b2796f66
commit 5fc4020f46
10 changed files with 168 additions and 15 deletions

View File

@ -7,7 +7,7 @@ namespace FAuth.Controllers
/// <summary> /// <summary>
/// 控制器类基类 /// 控制器类基类
/// </summary> /// </summary>
public abstract class ControllerBase:Controller public abstract class ControllerBase<LoggerType>:Controller
{ {
/// <summary> /// <summary>
/// 日志记录服务 /// 日志记录服务
@ -23,7 +23,7 @@ namespace FAuth.Controllers
/// </summary> /// </summary>
/// <param name="logger">控制器日志组件</param> /// <param name="logger">控制器日志组件</param>
/// <param name="service">服务集合</param> /// <param name="service">服务集合</param>
public ControllerBase(ILogger logger,IServiceProvider service) { public ControllerBase(ILogger<LoggerType> logger,IServiceProvider service) {
this.Logger = logger; this.Logger = logger;
this.Services = service; this.Services = service;
} }

View File

@ -12,14 +12,9 @@ namespace FAuth.Controllers
/// <summary> /// <summary>
/// Home控制器 /// Home控制器
/// </summary> /// </summary>
public class HomeController:ControllerBase public class HomeController:ControllerBase<HomeController>
{ {
/// <summary> public HomeController(ILogger<HomeController> logger,IServiceProvider service) : base(logger,service) {
/// 生成控制器
/// </summary>
/// <param name="logger">日志组件</param>
/// <param name="service">服务集合</param>
public HomeController(ILogger logger,IServiceProvider service) : base(logger,service) {
} }
public IActionResult Index() { public IActionResult Index() {

View 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) {
}
}
}

View 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) {
}
}
}

View 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;
}
}
}

View 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; }
}
}

View File

@ -15,10 +15,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Controllers\api\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" /> <None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup> </ItemGroup>

View 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
View 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; }
}
}

View File

@ -6,6 +6,7 @@ using FAuth.DataBase;
using FAuth.Extensions; using FAuth.Extensions;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -53,7 +54,11 @@ namespace FAuth
c.SwaggerDoc("V1",new OpenApiInfo { c.SwaggerDoc("V1",new OpenApiInfo {
Title = "½Ó¿ÚÎĵµ", Title = "½Ó¿ÚÎĵµ",
Version = "1.0", 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"); var xmlPath = Path.Combine(AppContext.BaseDirectory,typeof(Program).Assembly.GetName().Name + ".xml");
c.IncludeXmlComments(xmlPath,true); c.IncludeXmlComments(xmlPath,true);
@ -78,7 +83,7 @@ namespace FAuth
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => { app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/V1/swagger.json","½Ó¿ÚÎĵµ"); c.SwaggerEndpoint("/swagger/V1/swagger.json","½Ó¿ÚÎĵµ");
c.RoutePrefix = ""; c.RoutePrefix = "api";
}); });
app.UseAuthorization(); app.UseAuthorization();