Repository navigation
Expand file tree
/
Copy pathUserController.cs
More file actions
79 lines (59 loc) · 2.02 KB
/
Copy pathUserController.cs
File metadata and controls
79 lines (59 loc) · 2.02 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Emma.Blog.Data.Models;
using Emma.Blog.Service.Account;
using Emma.Blog.Service.Auth;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Security.Claims;
namespace Emma.Blog.Web.Controllers
{
public class UserController : Controller
{
private readonly JwtSettings _jwtSettings;
public UserController(IOptions<JwtSettings> jwtSettingsAccessor)
{
_jwtSettings = jwtSettingsAccessor.Value;
}
public IActionResult Jwt()
{
return Ok(_jwtSettings);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(User user)
{
UserService service = new UserService();
var claimUser = service.Register(user);
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claimUser.GetClaims(), CookieAuthenticationDefaults.AuthenticationScheme));
HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties()
{
IsPersistent = true,
ExpiresUtc = DateTime.UtcNow.AddSeconds(_jwtSettings.Expires)
});
return RedirectToAction("List");
}
public IActionResult List()
{
UserService service = new UserService();
var list = service.GetPageList(1, 10);
return View(list);
}
public IActionResult Delete(long id)
{
UserService service = new UserService();
service.Delete(id);
return RedirectToAction("List");
}
public IActionResult Info()
{
return View();
}
}
}