refact
This commit is contained in:
parent
1aafb7cc7d
commit
e24208e77b
32 changed files with 96 additions and 94 deletions
|
|
@ -198,7 +198,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
/// <summary>
|
||||
/// Entry point into the login workflow
|
||||
/// </summary>
|
||||
[HttpGet(Constants.SigninPath)]
|
||||
[HttpGet(YavscConstants.SigninPath)]
|
||||
public async Task<IActionResult> Signin(SignInModel model)
|
||||
{
|
||||
// build a model so we know what to show on the login page
|
||||
|
|
@ -217,7 +217,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
/// Handle postback from username/password login
|
||||
/// </summary>
|
||||
///
|
||||
[HttpPost(Constants.SigninPath)]
|
||||
[HttpPost(YavscConstants.SigninPath)]
|
||||
[ValidateAntiForgeryToken]
|
||||
[AllowAnonymous]
|
||||
|
||||
|
|
@ -659,7 +659,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
}
|
||||
//
|
||||
// POST: /Account/LogOff
|
||||
[HttpPost(Constants.LogoutPath)]
|
||||
[HttpPost(YavscConstants.LogoutPath)]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> LogOff(string returnUrl = null)
|
||||
{
|
||||
|
|
@ -829,7 +829,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = await _userManager.VerifyTwoFactorTokenAsync(user, Constants.DefaultFactor, code);
|
||||
result = await _userManager.VerifyTwoFactorTokenAsync(user, YavscConstants.DefaultFactor, code);
|
||||
_dbContext.SaveChanges(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1024,12 +1024,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
}
|
||||
|
||||
// Generate the token and send it
|
||||
if (model.SelectedProvider == Constants.MobileAppFactor)
|
||||
if (model.SelectedProvider == YavscConstants.MobileAppFactor)
|
||||
{
|
||||
return View("Error", new Exception("No mobile app service was activated"));
|
||||
}
|
||||
else
|
||||
if (model.SelectedProvider == Constants.SMSFactor)
|
||||
if (model.SelectedProvider == YavscConstants.SMSFactor)
|
||||
{
|
||||
return View("Error", new Exception("No SMS service was activated"));
|
||||
// await _smsSender.SendSmsAsync(_twilioSettings, await _userManager.GetPhoneNumberAsync(user), message);
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
// ensure all roles existence
|
||||
foreach (string roleName in new string[] {
|
||||
Constants.AdminGroupName,
|
||||
Constants.StarGroupName,
|
||||
Constants.PerformerGroupName,
|
||||
Constants.FrontOfficeGroupName,
|
||||
Constants.StarHunterGroupName,
|
||||
Constants.BlogModeratorGroupName
|
||||
YavscConstants.AdminGroupName,
|
||||
YavscConstants.StarGroupName,
|
||||
YavscConstants.PerformerGroupName,
|
||||
YavscConstants.FrontOfficeGroupName,
|
||||
YavscConstants.StarHunterGroupName,
|
||||
YavscConstants.BlogModeratorGroupName
|
||||
})
|
||||
if (!await _roleManager.RoleExistsAsync(roleName))
|
||||
{
|
||||
|
|
@ -80,11 +80,11 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Take()
|
||||
{
|
||||
// If some amdin already exists, make this method disapear
|
||||
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName);
|
||||
var admins = await _userManager.GetUsersInRoleAsync(YavscConstants.AdminGroupName);
|
||||
if (admins != null && admins.Count > 0)
|
||||
{
|
||||
// All is ok, nothing to do here.
|
||||
if (User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
|
||||
return Ok(new { message = "you already got it." });
|
||||
|
|
@ -100,7 +100,7 @@ namespace Yavsc.Controllers
|
|||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName);
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, YavscConstants.AdminGroupName);
|
||||
if (!addToRoleResult.Succeeded)
|
||||
{
|
||||
AddErrors(addToRoleResult);
|
||||
|
|
@ -114,11 +114,11 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var adminCount = await _userManager.GetUsersInRoleAsync(
|
||||
Constants.AdminGroupName);
|
||||
YavscConstants.AdminGroupName);
|
||||
var userCount = await _dbContext.Users.CountAsync();
|
||||
var youAreAdmin = await _userManager.IsInRoleAsync(
|
||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||
Constants.AdminGroupName);
|
||||
YavscConstants.AdminGroupName);
|
||||
|
||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
private async Task SetupView(Announce announce)
|
||||
{
|
||||
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName);
|
||||
ViewBag.IsPerformer = User.IsInMsRole(Constants.PerformerGroupName);
|
||||
ViewBag.IsAdmin = User.IsInMsRole(YavscConstants.AdminGroupName);
|
||||
ViewBag.IsPerformer = User.IsInMsRole(YavscConstants.PerformerGroupName);
|
||||
ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted;
|
||||
List<SelectListItem> dl = new List<SelectListItem>();
|
||||
var rnames = System.Enum.GetNames(typeof(Reason));
|
||||
|
|
@ -82,14 +82,14 @@ namespace Yavsc.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
// Only allow admin to create corporate annonces
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
|
||||
return View(announce);
|
||||
}
|
||||
|
||||
// Only allow performers to create ServiceProposal
|
||||
if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(Constants.PerformerGroupName))
|
||||
if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(YavscConstants.PerformerGroupName))
|
||||
{
|
||||
ModelState.AddModelError("For", _localizer["YourNotAPerformer"]);
|
||||
return View(announce);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
var blog = await blogSpotService.Details(User, id.Value);
|
||||
ViewData["apicmtctlr"] = "/api/blogcomments";
|
||||
ViewData["moderatoFlag"] = User.IsInMsRole(Constants.BlogModeratorGroupName);
|
||||
ViewData["moderatoFlag"] = User.IsInMsRole(YavscConstants.BlogModeratorGroupName);
|
||||
|
||||
return View(blog);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Yavsc.Controllers
|
|||
Value = pt.FullName,
|
||||
Selected = currentCode == pt.FullName
|
||||
}).ToList();
|
||||
items.Add(new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode, Selected = currentCode == null});
|
||||
items.Add(new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode, Selected = currentCode == null});
|
||||
ViewBag.SettingsClassName = items;
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ namespace Yavsc.Controllers
|
|||
Text = a.Name,
|
||||
Value = a.Code
|
||||
}).ToList();
|
||||
var nullItem = new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode };
|
||||
var nullItem = new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode };
|
||||
acts.Add(nullItem);
|
||||
if (code == null) return acts;
|
||||
var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code);
|
||||
|
|
@ -124,9 +124,9 @@ namespace Yavsc.Controllers
|
|||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Create(Activity activity)
|
||||
{
|
||||
if (activity.ParentCode==Constants.NoneCode)
|
||||
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||
activity.ParentCode=null;
|
||||
if (activity.SettingsClassName==Constants.NoneCode)
|
||||
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||
activity.SettingsClassName=null;
|
||||
|
||||
if (ModelState.IsValid)
|
||||
|
|
@ -162,9 +162,9 @@ namespace Yavsc.Controllers
|
|||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Edit(Activity activity)
|
||||
{
|
||||
if (activity.ParentCode==Constants.NoneCode)
|
||||
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||
activity.ParentCode=null;
|
||||
if (activity.SettingsClassName==Constants.NoneCode)
|
||||
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||
activity.SettingsClassName=null;
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ namespace Yavsc.Controllers
|
|||
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(Constants.SshHeaderKey) && Request.Headers[Constants.SshHeaderKey] == "on";
|
||||
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(YavscConstants.SshHeaderKey) && Request.Headers[YavscConstants.SshHeaderKey] == "on";
|
||||
ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
|
||||
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
|
||||
ViewBag.SshHeaderKey = Request.Headers[YavscConstants.SshHeaderKey];
|
||||
var uid = User.GetUserId();
|
||||
long[] clicked = null;
|
||||
if (uid == null)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace Yavsc.Controllers
|
|||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
|
||||
_context.Instrumentation.Add(model);
|
||||
|
|
@ -82,7 +82,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (id != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (id != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||
if (musicianSettings == null)
|
||||
|
|
@ -98,7 +98,7 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Edit(Instrumentation musicianSettings)
|
||||
{
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
|
@ -124,7 +124,7 @@ namespace Yavsc.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
return View(musicianSettings);
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ namespace Yavsc.Controllers
|
|||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public static class HostingExtensions
|
|||
new()
|
||||
{
|
||||
ValidateAudience = false,
|
||||
RoleClaimType = Constants.RoleClaimType
|
||||
RoleClaimType = YavscConstants.RoleClaimType
|
||||
};
|
||||
options.MapInboundClaims = true;
|
||||
});
|
||||
|
|
@ -141,7 +141,7 @@ public static class HostingExtensions
|
|||
public static IdentityBuilder AddIdentityDBAndStores(this WebApplicationBuilder builder)
|
||||
{
|
||||
IServiceCollection services = builder.Services;
|
||||
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
|
||||
var connectionString = builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName);
|
||||
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
{
|
||||
|
|
@ -162,7 +162,7 @@ public static class HostingExtensions
|
|||
options.SignIn.RequireConfirmedAccount = builder.Environment.IsEnvironment(
|
||||
builder.Environment.EnvironmentName);
|
||||
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.PreferredUserName;
|
||||
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
||||
options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType;
|
||||
}
|
||||
)
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
|
|
@ -186,18 +186,18 @@ public static class HostingExtensions
|
|||
{
|
||||
policy
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireClaim(Constants.RoleClaimType,
|
||||
new string[] { Constants.PerformerGroupName, Constants.AdminGroupName })
|
||||
.RequireClaim(YavscConstants.RoleClaimType,
|
||||
new string[] { YavscConstants.PerformerGroupName, YavscConstants.AdminGroupName })
|
||||
;
|
||||
});
|
||||
options.AddPolicy("AdministratorOnly", policy =>
|
||||
{
|
||||
_ = policy
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireClaim(Constants.RoleClaimType, Constants.AdminGroupName);
|
||||
.RequireClaim(YavscConstants.RoleClaimType, YavscConstants.AdminGroupName);
|
||||
});
|
||||
|
||||
options.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName));
|
||||
options.AddPolicy("FrontOffice", policy => policy.RequireRole(YavscConstants.FrontOfficeGroupName));
|
||||
|
||||
// options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
|
||||
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
|
||||
|
|
@ -269,10 +269,10 @@ public static class HostingExtensions
|
|||
{
|
||||
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
|
||||
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
|
||||
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
||||
options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType;
|
||||
});
|
||||
var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name;
|
||||
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
|
||||
var connectionString = builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName);
|
||||
|
||||
string sqliteConnectionString = $"Data Source={Path.Combine(Path.GetTempPath(), "yavsc_test.db")}";
|
||||
|
||||
|
|
@ -503,7 +503,7 @@ public static class HostingExtensions
|
|||
Config.UserFilesOptions = new FileServerOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
||||
RequestPath = PathString.FromUriComponent(Constants.UserFilesPath),
|
||||
RequestPath = PathString.FromUriComponent(YavscConstants.UserFilesPath),
|
||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||
};
|
||||
Config.UserFilesOptions.EnableDefaultFiles = true;
|
||||
|
|
@ -516,7 +516,7 @@ public static class HostingExtensions
|
|||
Config.AvatarsOptions = new FileServerOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Config.AvatarsDirName),
|
||||
RequestPath = PathString.FromUriComponent(Constants.AvatarsPath),
|
||||
RequestPath = PathString.FromUriComponent(YavscConstants.AvatarsPath),
|
||||
EnableDirectoryBrowsing = enableDirectoryBrowsing
|
||||
};
|
||||
|
||||
|
|
@ -527,7 +527,7 @@ public static class HostingExtensions
|
|||
Config.GitOptions = new FileServerOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Config.GitDirName),
|
||||
RequestPath = PathString.FromUriComponent(Constants.GitPath),
|
||||
RequestPath = PathString.FromUriComponent(YavscConstants.GitPath),
|
||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||
};
|
||||
Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md");
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ namespace Yavsc
|
|||
else
|
||||
builder.Services.AddScoped<IModerationService, ClaudeModerationService>();
|
||||
|
||||
builder.Configuration
|
||||
var rootConfig = builder.Configuration
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
rootConfig.GetConnectionString(YavscConstants.YavscConnectionStringName);
|
||||
|
||||
var app = await builder.ConfigureWebAppServices().ConfigurePipeline();
|
||||
app.Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Yavsc.ViewModels.Manage
|
|||
public class SetUserNameViewModel
|
||||
{
|
||||
[Required]
|
||||
[Display(Name = "User name"),RegularExpression(Constants.UserNameRegExp)]
|
||||
[Display(Name = "User name"),RegularExpression(YavscConstants.UserNameRegExp)]
|
||||
public string UserName { get; set; }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<li><a class="dropdown-item" asp-controller="Feature" asp-action="Index">Features</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@if (User.IsInMsRole(Constants.AdminGroupName)) {
|
||||
@if (User.IsInMsRole(YavscConstants.AdminGroupName)) {
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="dropdown05" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Administration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue