-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathAuthenticationController.cs
More file actions
42 lines (40 loc) · 1.01 KB
/
AuthenticationController.cs
File metadata and controls
42 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace MvcApplication.Controllers {
public class AuthenticationController : Controller {
SecurityProvider securityProvider;
public AuthenticationController(SecurityProvider securityProvider){
this.securityProvider = securityProvider;
}
[HttpPost]
[Route("Login")]
[AllowAnonymous]
public ActionResult Login(string userName, string password) {
ActionResult result;
if(securityProvider.InitConnection(userName, password)) {
result = Ok();
}
else {
result = Unauthorized();
}
return result;
}
[HttpGet]
[Route("Logout")]
public async Task<ActionResult> Logout() {
await HttpContext.SignOutAsync();
return Ok();
}
[Route("Authentication")]
public IActionResult Authentication() {
return View();
}
protected override void Dispose(bool disposing) {
if(disposing) {
securityProvider?.Dispose();
}
base.Dispose(disposing);
}
}
}