refacto API prefix + nav.back
This commit is contained in:
parent
bd6ca9d11f
commit
6825f74308
78 changed files with 770 additions and 222 deletions
|
|
@ -90,7 +90,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
"ConfirmYourAccountTitle"
|
||||
})
|
||||
Debug.Assert(!_localizer[name].ResourceNotFound);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName, clientId: context?.Client.ClientId));
|
||||
|
||||
// only set explicit expiration here if user chooses "remember me".
|
||||
// only set explicit expiration here if user chooses "remember me".
|
||||
// otherwise we rely upon expiration configured in cookie middleware.
|
||||
await HttpContext.SignInAsync(user, _roleManager, model.RememberMe, _dbContext);
|
||||
var authResult = await HttpContext.AuthenticateAsync();
|
||||
|
|
@ -198,7 +198,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
/// <summary>
|
||||
/// Entry point into the login workflow
|
||||
/// </summary>
|
||||
[HttpGet(YavscConstants.SigninPath)]
|
||||
[HttpGet(Constants.SigninPath)]
|
||||
public async Task<IActionResult> Signin(SignInModel model)
|
||||
{
|
||||
// build a model so we know what to show on the login page
|
||||
|
|
@ -216,11 +216,11 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
/// <summary>
|
||||
/// Handle postback from username/password login
|
||||
/// </summary>
|
||||
///
|
||||
[HttpPost(YavscConstants.SigninPath)]
|
||||
///
|
||||
[HttpPost(Constants.SigninPath)]
|
||||
[ValidateAntiForgeryToken]
|
||||
[AllowAnonymous]
|
||||
|
||||
|
||||
public async Task<IActionResult> Signin([FromForm] SignInModel model, [FromForm] string button)
|
||||
{
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
if (context != null)
|
||||
{
|
||||
// if the user cancels, send a result back into IdentityServer as if they
|
||||
// if the user cancels, send a result back into IdentityServer as if they
|
||||
// denied the consent (even if this client does not require consent).
|
||||
// this will send back an access denied OIDC error response to the client.
|
||||
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);
|
||||
|
|
@ -269,7 +269,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
{
|
||||
await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName, clientId: context?.Client.ClientId));
|
||||
|
||||
// only set explicit expiration here if user chooses "remember me".
|
||||
// only set explicit expiration here if user chooses "remember me".
|
||||
// otherwise we rely upon expiration configured in cookie middleware.
|
||||
await HttpContext.SignInAsync(user, _roleManager, model.RememberMe, _dbContext);
|
||||
|
||||
|
|
@ -396,7 +396,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
var local = context.IdP == IdentityServer8.IdentityServerConstants.LocalIdentityProvider;
|
||||
|
||||
// this is meant to short circuit the UI and only trigger the one external IdP
|
||||
|
||||
|
||||
model.EnableLocalLogin = local;
|
||||
model.UserName = context?.LoginHint;
|
||||
model.IsExternalLoginOnly = false;
|
||||
|
|
@ -579,7 +579,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
// Send an email with this link
|
||||
|
||||
Uri authority = new Uri(Config.Authority);
|
||||
|
||||
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
var callbackUrl = Url.Action("ConfirmEmail", "Account",
|
||||
new { userId = user.Id, code },
|
||||
|
|
@ -659,7 +659,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
}
|
||||
//
|
||||
// POST: /Account/LogOff
|
||||
[HttpPost(YavscConstants.LogoutPath)]
|
||||
[HttpPost(Constants.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, YavscConstants.DefaultFactor, code);
|
||||
result = await _userManager.VerifyTwoFactorTokenAsync(user, Constants.DefaultFactor, code);
|
||||
_dbContext.SaveChanges(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1024,12 +1024,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
|||
}
|
||||
|
||||
// Generate the token and send it
|
||||
if (model.SelectedProvider == YavscConstants.MobileAppFactor)
|
||||
if (model.SelectedProvider == Constants.MobileAppFactor)
|
||||
{
|
||||
return View("Error", new Exception("No mobile app service was activated"));
|
||||
}
|
||||
else
|
||||
if (model.SelectedProvider == YavscConstants.SMSFactor)
|
||||
if (model.SelectedProvider == Constants.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[] {
|
||||
YavscConstants.AdminGroupName,
|
||||
YavscConstants.StarGroupName,
|
||||
YavscConstants.PerformerGroupName,
|
||||
YavscConstants.FrontOfficeGroupName,
|
||||
YavscConstants.StarHunterGroupName,
|
||||
YavscConstants.BlogModeratorGroupName
|
||||
Constants.AdminGroupName,
|
||||
Constants.StarGroupName,
|
||||
Constants.PerformerGroupName,
|
||||
Constants.FrontOfficeGroupName,
|
||||
Constants.StarHunterGroupName,
|
||||
Constants.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(YavscConstants.AdminGroupName);
|
||||
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName);
|
||||
if (admins != null && admins.Count > 0)
|
||||
{
|
||||
// All is ok, nothing to do here.
|
||||
if (User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
if (User.IsInMsRole(Constants.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, YavscConstants.AdminGroupName);
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName);
|
||||
if (!addToRoleResult.Succeeded)
|
||||
{
|
||||
AddErrors(addToRoleResult);
|
||||
|
|
@ -114,11 +114,11 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var adminCount = await _userManager.GetUsersInRoleAsync(
|
||||
YavscConstants.AdminGroupName);
|
||||
Constants.AdminGroupName);
|
||||
var userCount = await _dbContext.Users.CountAsync();
|
||||
var youAreAdmin = await _userManager.IsInRoleAsync(
|
||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||
YavscConstants.AdminGroupName);
|
||||
Constants.AdminGroupName);
|
||||
|
||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
using IdentityServer8.EntityFramework.Entities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Server.Helpers;
|
||||
using static Yavsc.Constants;
|
||||
|
||||
namespace Yavsc.Org.Controllers.Administration
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route(APIPrefix + "/[controller]")]
|
||||
[ApiController]
|
||||
public class ApiScopesApiController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ namespace Yavsc.Controllers
|
|||
readonly IStringLocalizer<AnnouncesController> _localizer;
|
||||
readonly IAuthorizationService _authorizationService;
|
||||
|
||||
public AnnouncesController(ApplicationDbContext context,
|
||||
public AnnouncesController(ApplicationDbContext context,
|
||||
IAuthorizationService authorizationService,
|
||||
IStringLocalizer<AnnouncesController> localizer)
|
||||
{
|
||||
_context = context;
|
||||
_context = context;
|
||||
_authorizationService = authorizationService;
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
|
@ -59,16 +59,16 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
private async Task SetupView(Announce announce)
|
||||
{
|
||||
ViewBag.IsAdmin = User.IsInMsRole(YavscConstants.AdminGroupName);
|
||||
ViewBag.IsPerformer = User.IsInMsRole(YavscConstants.PerformerGroupName);
|
||||
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName);
|
||||
ViewBag.IsPerformer = User.IsInMsRole(Constants.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));
|
||||
var rvalues = System.Enum.GetValues(typeof(Reason));
|
||||
|
||||
|
||||
for (int i = 0; i<rnames.Length; i++) {
|
||||
dl.Add(new SelectListItem { Text =
|
||||
_localizer[rnames[i]],
|
||||
dl.Add(new SelectListItem { Text =
|
||||
_localizer[rnames[i]],
|
||||
Value= rvalues.GetValue(i).ToString() });
|
||||
}
|
||||
|
||||
|
|
@ -82,14 +82,14 @@ namespace Yavsc.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
// Only allow admin to create corporate annonces
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminGroupName))
|
||||
{
|
||||
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
|
||||
return View(announce);
|
||||
}
|
||||
|
||||
// Only allow performers to create ServiceProposal
|
||||
if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(YavscConstants.PerformerGroupName))
|
||||
// Only allow performers to create ServiceProposal
|
||||
if (announce.For == Reason.ServiceProposal && ! User.IsInMsRole(Constants.PerformerGroupName))
|
||||
{
|
||||
ModelState.AddModelError("For", _localizer["YourNotAPerformer"]);
|
||||
return View(announce);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace Yavsc.Org.Controllers
|
|||
{
|
||||
var blog = await blogSpotService.Details(User, id.Value);
|
||||
ViewBag.apicmtctlr = "/api/v1/blogcomments";
|
||||
ViewBag.moderatoFlag = User.IsInMsRole(YavscConstants.BlogModeratorGroupName);
|
||||
ViewBag.moderatoFlag = User.IsInMsRole(Yavsc.Constants.BlogModeratorGroupName);
|
||||
|
||||
return View(blog);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Yavsc.Controllers
|
|||
Value = pt.FullName,
|
||||
Selected = currentCode == pt.FullName
|
||||
}).ToList();
|
||||
items.Add(new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode, Selected = currentCode == null});
|
||||
items.Add(new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode, Selected = currentCode == null});
|
||||
ViewBag.SettingsClassName = items;
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ namespace Yavsc.Controllers
|
|||
Text = a.Name,
|
||||
Value = a.Code
|
||||
}).ToList();
|
||||
var nullItem = new SelectListItem { Text = SR[YavscConstants.NoneCode], Value = YavscConstants.NoneCode };
|
||||
var nullItem = new SelectListItem { Text = SR[Constants.NoneCode], Value = Constants.NoneCode };
|
||||
acts.Add(nullItem);
|
||||
if (code == null) return acts;
|
||||
var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code);
|
||||
|
|
@ -123,9 +123,9 @@ namespace Yavsc.Controllers
|
|||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Create(Activity activity)
|
||||
{
|
||||
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||
if (activity.ParentCode==Constants.NoneCode)
|
||||
activity.ParentCode=null;
|
||||
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||
if (activity.SettingsClassName==Constants.NoneCode)
|
||||
activity.SettingsClassName=null;
|
||||
|
||||
if (ModelState.IsValid)
|
||||
|
|
@ -161,9 +161,9 @@ namespace Yavsc.Controllers
|
|||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Edit(Activity activity)
|
||||
{
|
||||
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||
if (activity.ParentCode==Constants.NoneCode)
|
||||
activity.ParentCode=null;
|
||||
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||
if (activity.SettingsClassName==Constants.NoneCode)
|
||||
activity.SettingsClassName=null;
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using Yavsc.Server.Helpers;
|
|||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/v1/dimiss")]
|
||||
[Route(Constants.APIPrefix + "/v1/dimiss")]
|
||||
public class DimissClicksApiController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
|
@ -140,7 +140,7 @@ namespace Yavsc.Controllers
|
|||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (!User.IsInRole("Administrator"))
|
||||
if (uid != id) return new ChallengeResult();
|
||||
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ namespace Yavsc.Controllers
|
|||
readonly IHtmlLocalizer _localizer;
|
||||
|
||||
private SiteSettings siteSettings;
|
||||
public HomeController(ILogger<HomeController> logger,
|
||||
IHtmlLocalizer<HomeController> localizer,
|
||||
public HomeController(ILogger<HomeController> logger,
|
||||
IHtmlLocalizer<HomeController> localizer,
|
||||
ApplicationDbContext context,
|
||||
IOptions<SiteSettings> settingsOptions,
|
||||
IOptions<SiteSettings> settingsOptions,
|
||||
IWebHostEnvironment env
|
||||
)
|
||||
{
|
||||
|
|
@ -37,9 +37,9 @@ namespace Yavsc.Controllers
|
|||
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(YavscConstants.SshHeaderKey) && Request.Headers[YavscConstants.SshHeaderKey] == "on";
|
||||
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(Constants.SshHeaderKey) && Request.Headers[Constants.SshHeaderKey] == "on";
|
||||
ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
|
||||
ViewBag.SshHeaderKey = Request.Headers[YavscConstants.SshHeaderKey];
|
||||
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
|
||||
var uid = User.GetUserId();
|
||||
long[] clicked = null;
|
||||
if (uid == null)
|
||||
|
|
@ -140,8 +140,8 @@ namespace Yavsc.Controllers
|
|||
errorViewModel.Description ??= string.Empty;
|
||||
errorViewModel.Description += " Page: Home.";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return View("~/Views/Shared/Error.cshtml", errorViewModel);
|
||||
}
|
||||
public IActionResult Status(int id)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
public InstrumentationController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: Instrumentation
|
||||
|
|
@ -50,7 +50,7 @@ namespace Yavsc.Controllers
|
|||
var owned = _context.Instrumentation.Include(i=>i.Tool).Where(i=>i.UserId==uid).Select(i=>i.InstrumentId);
|
||||
var ownedArray = owned.ToArray();
|
||||
|
||||
ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem
|
||||
ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem
|
||||
{ Text = k.Name, Value = k.Id.ToString(), Disabled = ownedArray.Contains(k.Id) });
|
||||
|
||||
return View(new Instrumentation { UserId = uid });
|
||||
|
|
@ -64,7 +64,7 @@ namespace Yavsc.Controllers
|
|||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
|
||||
_context.Instrumentation.Add(model);
|
||||
|
|
@ -82,7 +82,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (id != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
if (id != uid) if (!User.IsInMsRole(Constants.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(YavscConstants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.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(YavscConstants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
return View(musicianSettings);
|
||||
}
|
||||
|
|
@ -135,12 +135,12 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||
{
|
||||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||
|
||||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
return new ChallengeResult();
|
||||
|
||||
|
||||
|
||||
_context.Instrumentation.Remove(musicianSettings);
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
return RedirectToAction("Index");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue