public async Task <IActionResult> Login([FromBody] TaiKhoanForLoginDto taiKhoan) { try { var taiKhoanDuocDangNhap = await _repo.DangNhap(taiKhoan.TenDangNhap.ToLower(), taiKhoan.MatKhau); if (taiKhoanDuocDangNhap == null) { return(StatusCode(500, new FailedResponseDto { Message = "Đăng nhập vào hệ thống thất bại!" })); } //var claims = new[] //{ // new Claim(ClaimTypes.NameIdentifier, taiKhoanDuocDangNhap.MaTaiKhoan.ToString()), // new Claim(ClaimTypes.Name, taiKhoanDuocDangNhap.TenDangNhap), // new Claim(ClaimTypes.Role, taiKhoanDuocDangNhap.PhanQuyen) //}; //var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value)); //var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); //var tokenDescriptor = new SecurityTokenDescriptor //{ // Subject = new ClaimsIdentity(claims), // Expires = DateTime.Now.AddDays(1), // SigningCredentials = creds //}; //var tokenHandler = new JwtSecurityTokenHandler(); //var token = tokenHandler.CreateToken(tokenDescriptor); return(StatusCode(200, new SuccessResponseDto { Message = "Đăng nhập vào hệ thống thành công!", Result = new SuccessResponseResultWithSingleDataDto { Data = taiKhoanDuocDangNhap } })); } catch (Exception e) { return(StatusCode(500, new FailedResponseDto { Message = "Đăng nhập vào hệ thống thất bại!", Result = new FailedResponseResultDto { Errors = e } })); } }
public TaiKhoan DangNhap(TaiKhoan taiKhoan) { return(_taiKhoanRepository.DangNhap(taiKhoan)); }