FalconSSO/FAuth/Controllers/api/UserController.cs

74 lines
2.6 KiB
C#

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;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using FAuth.Extensions.Decryptor;
namespace FAuth.Controllers.api
{
/// <summary>
/// 用户相关api控制器接口
/// </summary>
public class UserController:ApiControllerBase<UserController>
{
public IUserTicketDryptor UserTicketDryptor { get; set; }
public UserController(ILogger<UserController> logger,IServiceProvider service,IUserTicketDryptor userTicketDryptor)
: base(logger,service) {
if(logger is null)
throw new ArgumentNullException(nameof(logger));
if(service is null)
throw new ArgumentNullException(nameof(service));
this.UserTicketDryptor = userTicketDryptor ?? throw new ArgumentNullException(nameof(userTicketDryptor));
}
/// <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 = this.UserTicketDryptor.Encrypt(new UserTicketModel {
UserName = userName,
}),
};
}
/// <summary>
/// 根据用户凭据获取用户信息
/// </summary>
/// <param name="ticket">登录票据</param>
/// <returns>用户信息</returns>
[HttpPost]
[ProducesResponseType(typeof(UserInfo),200)]
public UserInfo GetUserByTicket([BindRequired]string ticket) {
var userTicketModel = this.UserTicketDryptor.Decrypt(ticket);
return new UserInfo {
UserName = userTicketModel.UserName,
};
}
/// <summary>
/// 根据提供的登陆票据修改用户密码
/// </summary>
/// <param name="ticket">票据</param>
/// <param name="nPassword">新密码</param>
/// <returns>是否成功</returns>
[HttpPost]
public bool ChangePassword(string ticket,string nPassword) {
return true;
}
}
}