Ai
1 Star 1 Fork 50

mofees/CodeSpirit

forked from magicodes/CodeSpirit 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AuthController.cs 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
李文强 提交于 2025-02-18 21:10 +08:00 . 重构
// Controllers/AuthController.cs
using CodeSpirit.Core;
using CodeSpirit.IdentityApi.Data.Models;
using CodeSpirit.IdentityApi.Dtos.Auth;
using CodeSpirit.IdentityApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace CodeSpirit.IdentityApi.Controllers
{
[AllowAnonymous]
public class AuthController : ApiControllerBase
{
private readonly IAuthService _authService;
private readonly SignInManager<ApplicationUser> _signInManager;
public AuthController(IAuthService authService, SignInManager<ApplicationUser> signInManager)
{
_authService = authService;
_signInManager = signInManager;
}
/// <summary>
/// 用户登录方法。
/// </summary>
/// <param name="model">登录模型,包含用户名和密码。</param>
/// <returns>登录结果。</returns>
[HttpPost("login")]
[AllowAnonymous]
public async Task<ActionResult<ApiResponse<LoginResult>>> Login([FromBody] LoginModel model)
{
(bool success, string message, string token, UserDto user) = await _authService.LoginAsync(model.UserName, model.Password);
if (success)
{
LoginResult result = new()
{
Token = token,
};
return SuccessResponse(result);
}
return BadResponse<LoginResult>(message);
}
/// <summary>
/// 退出登录
/// </summary>
/// <returns></returns>
[HttpPost("logout")]
public async Task<ActionResult<ApiResponse>> Logout()
{
await _signInManager.SignOutAsync();
return SuccessResponse("退出登录成功!");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/mofees/code-spirit.git
git@gitee.com:mofees/code-spirit.git
mofees
code-spirit
CodeSpirit
master

搜索帮助