12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using AuthorizeCenter.Services;
- using DllUfpEntity;
- using DllUfpEntity.Dto;
- using Microsoft.AspNetCore.Authentication;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AuthorizeCenter.Controllers
- {
- public class AccountController : Controller
- {
- public AccountService AccountService { get; set; }
- public AccountController(AccountService accountService)
- {
- AccountService = accountService;
- }
- public async Task<IActionResult> Login(string returnUrl = null)
- {
- ViewData["ReturnUrl"] = returnUrl;
- return View();
- }
- [HttpPost]
- public async Task<IActionResult> Login(UserLoginDto userLoginDto)
- {
- ViewData["ReturnUrl"] = userLoginDto.ReturnUrl;
- string errorinfo = string.Empty;
- var res = AccountService.Login(new Staff()
- {
- FCode = userLoginDto.Account,
- Password = userLoginDto.Password
- }, ref errorinfo);
- if (res != null)
- {
- AuthenticationProperties props = new AuthenticationProperties
- {
- IsPersistent = true,
- ExpiresUtc = DateTimeOffset.UtcNow.Add(TimeSpan.FromDays(1))
- };
- await HttpContext.SignInAsync(res.ID.ToString(), new System.Security.Claims.ClaimsPrincipal(new BinaryReader(new MemoryStream(Encoding.UTF8.GetBytes(res.FCode)))), props);
- if (!string.IsNullOrEmpty(userLoginDto.ReturnUrl))
- {
- return Redirect(userLoginDto.ReturnUrl);
- }
- return View();
- }
- else
- {
- return View();
- }
- }
- }
- }
|