DEV Community

Mahir Xalilov
Mahir Xalilov

Posted on

Acc Control

namespace PL.Controllers
{
public class AccountController : Controller
{
readonly IAuthService _authService;
public AccountController(IAuthService authService)
{
_authService = authService;
}
public IActionResult Login()
{
return View();
}
[HttpPost]
public async Task Login(LoginDTO userDTO)
{
try
{
if (!ModelState.IsValid)
{
return View();
}
await _authService.Login(userDTO);
return RedirectToAction("Index", "Home");
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
public IActionResult Register()
{
return View();
}
[HttpPost]
public async Task Register(RegisterDTO registerDTO)
{
try
{
if (!ModelState.IsValid)
{
return View();
}
await _authService.Register(registerDTO);
return RedirectToAction("Login","Account");
}catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
public async Task Logout()
{
try
{
await _authService.Logout();
return RedirectToAction("Index","Home");
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}

    public IActionResult AccessDenied()
    {
        return View();
    }

}
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)