-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathHomeController.cs
100 lines (84 loc) · 3.62 KB
/
HomeController.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2022 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/
// Licensed under MIT license. See License.txt in the project root for license information.
using System.Diagnostics;
using AuthPermissions.SupportCode.AddUsersServices;
using Example7.SingleLevelShardingOnly.Services;
using Example7.MvcWebApp.ShardingOnly.Models;
using Example7.MvcWebApp.ShardingOnly.PermissionsCode;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using AuthPermissions.AspNetCore.ShardingServices;
using AuthPermissions.BaseCode.PermissionsCode;
namespace Example7.MvcWebApp.ShardingOnly.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index(string message)
{
ViewBag.Message = message;
if (User.Claims.All(x => x.Type != PermissionConstants.DataKeyClaimType))
return View(new AppSummary());
return RedirectToAction("Index", "Invoice");
}
public IActionResult CreateTenant([FromServices] IGetSetShardingEntries service)
{
if (User.Identity.IsAuthenticated)
return RedirectToAction("Index", new { message = "You can't create a new tenant because you are all ready logged in." });
return View(new AddNewTenantDto
{
HasOwnDb = true,
PossibleRegions = service.GetConnectionStringNames()
});
}
[AllowAnonymous]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> CreateTenant([FromServices] ISignInAndCreateTenant userRegisterInvite,
AddNewTenantDto tenantDto, AddNewUserDto newUserDto)
{
var status = await userRegisterInvite.SignUpNewTenantWithVersionAsync(newUserDto, tenantDto,
Example7CreateTenantVersions.TenantSetupData);
if (status.HasErrors)
return RedirectToAction(nameof(ErrorDisplay),
new { errorMessage = status.GetAllErrors() });
return RedirectToAction(nameof(Index),
new { message = status.Message });
}
[AllowAnonymous]
public ActionResult AcceptInvite(string verify)
{
return View(new AcceptInviteDto { Verify = verify });
}
[AllowAnonymous]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> AcceptInvite([FromServices] IInviteNewUserService inviteUserServiceService,
string verify, string email, string userName, string password, bool isPersistent)
{
var status = await inviteUserServiceService.AddUserViaInvite(verify, email, null, password, isPersistent);
if (status.HasErrors)
return RedirectToAction(nameof(ErrorDisplay),
new { errorMessage = status.GetAllErrors() });
return RedirectToAction(nameof(Index),
new { message = status.Message });
}
public ActionResult ErrorDisplay(string errorMessage)
{
return View((object)errorMessage);
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}