refact
This commit is contained in:
parent
1aafb7cc7d
commit
e24208e77b
32 changed files with 96 additions and 94 deletions
|
|
@ -27,12 +27,12 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
bool UserIsAdminOrThis(string uid)
|
bool UserIsAdminOrThis(string uid)
|
||||||
{
|
{
|
||||||
if (User.IsInRole(Constants.AdminGroupName)) return true;
|
if (User.IsInRole(YavscConstants.AdminGroupName)) return true;
|
||||||
return uid == User.GetUserId();
|
return uid == User.GetUserId();
|
||||||
}
|
}
|
||||||
bool UserIsAdminOrInThese(string oid, string uid)
|
bool UserIsAdminOrInThese(string oid, string uid)
|
||||||
{
|
{
|
||||||
if (User.IsInRole(Constants.AdminGroupName)) return true;
|
if (User.IsInRole(YavscConstants.AdminGroupName)) return true;
|
||||||
var cuid = User.GetUserId();
|
var cuid = User.GetUserId();
|
||||||
return cuid == uid || cuid == oid;
|
return cuid == uid || cuid == oid;
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Yavsc.Controllers
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
{
|
{
|
||||||
if (uid != estimate.OwnerId)
|
if (uid != estimate.OwnerId)
|
||||||
{
|
{
|
||||||
|
|
@ -118,7 +118,7 @@ namespace Yavsc.Controllers
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (estimate.OwnerId == null) estimate.OwnerId = uid;
|
if (estimate.OwnerId == null) estimate.OwnerId = uid;
|
||||||
|
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
{
|
{
|
||||||
if (uid != estimate.OwnerId)
|
if (uid != estimate.OwnerId)
|
||||||
{
|
{
|
||||||
|
|
@ -187,7 +187,7 @@ namespace Yavsc.Controllers
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
{
|
{
|
||||||
if (uid != estimate.OwnerId)
|
if (uid != estimate.OwnerId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (estimateTemplate.OwnerId!=uid)
|
if (estimateTemplate.OwnerId!=uid)
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
||||||
|
|
||||||
_context.Entry(estimateTemplate).State = EntityState.Modified;
|
_context.Entry(estimateTemplate).State = EntityState.Modified;
|
||||||
|
|
@ -132,7 +132,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (estimateTemplate.OwnerId!=uid)
|
if (estimateTemplate.OwnerId!=uid)
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
||||||
|
|
||||||
_context.EstimateTemplates.Remove(estimateTemplate);
|
_context.EstimateTemplates.Remove(estimateTemplate);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT: api/ProductApi/5
|
// PUT: api/ProductApi/5
|
||||||
[HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
[HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult PutProduct(long id, [FromBody] Product product)
|
public IActionResult PutProduct(long id, [FromBody] Product product)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: api/ProductApi
|
// POST: api/ProductApi
|
||||||
[HttpPost,Authorize(Constants.FrontOfficeGroupName)]
|
[HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult PostProduct([FromBody] Product product)
|
public IActionResult PostProduct([FromBody] Product product)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE: api/ProductApi/5
|
// DELETE: api/ProductApi/5
|
||||||
[HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
[HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult DeleteProduct(long id)
|
public IActionResult DeleteProduct(long id)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (blogpost.AuthorId!=uid)
|
if (blogpost.AuthorId!=uid)
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
|
|
||||||
_context.SaveChanges(User.GetUserId());
|
_context.SaveChanges(User.GetUserId());
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (uid != blackListed.OwnerId)
|
if (uid != blackListed.OwnerId)
|
||||||
if (!User.IsInRole(Constants.AdminGroupName))
|
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||||
if (!User.IsInRole(Constants.FrontOfficeGroupName))
|
if (!User.IsInRole(YavscConstants.FrontOfficeGroupName))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (uid != chatRoomAccess.UserId && uid != chatRoomAccess.Room.OwnerId
|
if (uid != chatRoomAccess.UserId && uid != chatRoomAccess.Room.OwnerId
|
||||||
&& ! User.IsInMsRole(Constants.AdminGroupName))
|
&& ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
|
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("UserId","get refused");
|
ModelState.AddModelError("UserId","get refused");
|
||||||
|
|
@ -72,7 +72,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||||
|
|
||||||
if (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName))
|
if (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("ChannelName", "access put refused");
|
ModelState.AddModelError("ChannelName", "access put refused");
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||||
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName)))
|
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName)))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("ChannelName", "access post refused");
|
ModelState.AddModelError("ChannelName", "access post refused");
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||||
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(Constants.AdminGroupName)))
|
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(YavscConstants.AdminGroupName)))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError("UserId", "access drop refused");
|
ModelState.AddModelError("UserId", "access drop refused");
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
if (User.GetUserId() != chatRoom.OwnerId )
|
if (User.GetUserId() != chatRoom.OwnerId )
|
||||||
{
|
{
|
||||||
if (!User.IsInMsRole(Constants.AdminGroupName))
|
if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
return BadRequest(new {error = "OwnerId"});
|
return BadRequest(new {error = "OwnerId"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT: api/ServiceApi/5
|
// PUT: api/ServiceApi/5
|
||||||
[HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
[HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult PutService(long id, [FromBody] Service service)
|
public IActionResult PutService(long id, [FromBody] Service service)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: api/ServiceApi
|
// POST: api/ServiceApi
|
||||||
[HttpPost,Authorize(Constants.FrontOfficeGroupName)]
|
[HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult PostService([FromBody] Service service)
|
public IActionResult PostService([FromBody] Service service)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE: api/ServiceApi/5
|
// DELETE: api/ServiceApi/5
|
||||||
[HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
[HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||||
public IActionResult DeleteService(long id)
|
public IActionResult DeleteService(long id)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ internal class Program
|
||||||
options.IncludeErrorDetails = true;
|
options.IncludeErrorDetails = true;
|
||||||
options.Authority = "https://localhost:5001";
|
options.Authority = "https://localhost:5001";
|
||||||
options.TokenValidationParameters =
|
options.TokenValidationParameters =
|
||||||
new() { ValidateAudience = false, RoleClaimType = Constants.RoleClaimType };
|
new() { ValidateAudience = false, RoleClaimType = YavscConstants.RoleClaimType };
|
||||||
options.MapInboundClaims = true;
|
options.MapInboundClaims = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ namespace Yavsc.ViewModels.Account
|
||||||
public class RegisterModel
|
public class RegisterModel
|
||||||
{
|
{
|
||||||
|
|
||||||
[StringLength(Constants.MaxUserNameLength)]
|
[StringLength(YavscConstants.MaxUserNameLength)]
|
||||||
[RegularExpression(Constants.UserNameRegExp)]
|
[RegularExpression(YavscConstants.UserNameRegExp)]
|
||||||
[DataType(DataType.Text)]
|
[DataType(DataType.Text)]
|
||||||
[Display(Name = "UserName", Description = "User name")]
|
[Display(Name = "UserName", Description = "User name")]
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using Yavsc.Models.Auth;
|
||||||
namespace Yavsc
|
namespace Yavsc
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class Constants
|
public static class YavscConstants
|
||||||
{
|
{
|
||||||
public static readonly Scope[] SiteScopes = {
|
public static readonly Scope[] SiteScopes = {
|
||||||
new Scope { Id = "profile", Description = "Your profile informations" },
|
new Scope { Id = "profile", Description = "Your profile informations" },
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,12 @@ internal class Program
|
||||||
options.IncludeErrorDetails = true;
|
options.IncludeErrorDetails = true;
|
||||||
options.Authority = authority;
|
options.Authority = authority;
|
||||||
options.TokenValidationParameters =
|
options.TokenValidationParameters =
|
||||||
new() { ValidateAudience = false, RoleClaimType = Constants.RoleClaimType };
|
new() { ValidateAudience = false, RoleClaimType = YavscConstants.RoleClaimType };
|
||||||
options.MapInboundClaims = true;
|
options.MapInboundClaims = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
options.UseNpgsql(builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName)));
|
options.UseNpgsql(builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName)));
|
||||||
|
|
||||||
services.AddTransient<ITrueEmailSender, MailSender>()
|
services.AddTransient<ITrueEmailSender, MailSender>()
|
||||||
.AddTransient<IBillingService, BillingService>()
|
.AddTransient<IBillingService, BillingService>()
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Entry point into the login workflow
|
/// Entry point into the login workflow
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet(Constants.SigninPath)]
|
[HttpGet(YavscConstants.SigninPath)]
|
||||||
public async Task<IActionResult> Signin(SignInModel model)
|
public async Task<IActionResult> Signin(SignInModel model)
|
||||||
{
|
{
|
||||||
// build a model so we know what to show on the login page
|
// 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
|
/// Handle postback from username/password login
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
[HttpPost(Constants.SigninPath)]
|
[HttpPost(YavscConstants.SigninPath)]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
|
||||||
|
|
@ -659,7 +659,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// POST: /Account/LogOff
|
// POST: /Account/LogOff
|
||||||
[HttpPost(Constants.LogoutPath)]
|
[HttpPost(YavscConstants.LogoutPath)]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> LogOff(string returnUrl = null)
|
public async Task<IActionResult> LogOff(string returnUrl = null)
|
||||||
{
|
{
|
||||||
|
|
@ -829,7 +829,7 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
||||||
bool result = false;
|
bool result = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = await _userManager.VerifyTwoFactorTokenAsync(user, Constants.DefaultFactor, code);
|
result = await _userManager.VerifyTwoFactorTokenAsync(user, YavscConstants.DefaultFactor, code);
|
||||||
_dbContext.SaveChanges(userId);
|
_dbContext.SaveChanges(userId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -1024,12 +1024,12 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the token and send it
|
// 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"));
|
return View("Error", new Exception("No mobile app service was activated"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (model.SelectedProvider == Constants.SMSFactor)
|
if (model.SelectedProvider == YavscConstants.SMSFactor)
|
||||||
{
|
{
|
||||||
return View("Error", new Exception("No SMS service was activated"));
|
return View("Error", new Exception("No SMS service was activated"));
|
||||||
// await _smsSender.SendSmsAsync(_twilioSettings, await _userManager.GetPhoneNumberAsync(user), message);
|
// await _smsSender.SendSmsAsync(_twilioSettings, await _userManager.GetPhoneNumberAsync(user), message);
|
||||||
|
|
|
||||||
|
|
@ -50,12 +50,12 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
// ensure all roles existence
|
// ensure all roles existence
|
||||||
foreach (string roleName in new string[] {
|
foreach (string roleName in new string[] {
|
||||||
Constants.AdminGroupName,
|
YavscConstants.AdminGroupName,
|
||||||
Constants.StarGroupName,
|
YavscConstants.StarGroupName,
|
||||||
Constants.PerformerGroupName,
|
YavscConstants.PerformerGroupName,
|
||||||
Constants.FrontOfficeGroupName,
|
YavscConstants.FrontOfficeGroupName,
|
||||||
Constants.StarHunterGroupName,
|
YavscConstants.StarHunterGroupName,
|
||||||
Constants.BlogModeratorGroupName
|
YavscConstants.BlogModeratorGroupName
|
||||||
})
|
})
|
||||||
if (!await _roleManager.RoleExistsAsync(roleName))
|
if (!await _roleManager.RoleExistsAsync(roleName))
|
||||||
{
|
{
|
||||||
|
|
@ -80,11 +80,11 @@ namespace Yavsc.Controllers
|
||||||
public async Task<IActionResult> Take()
|
public async Task<IActionResult> Take()
|
||||||
{
|
{
|
||||||
// If some amdin already exists, make this method disapear
|
// 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)
|
if (admins != null && admins.Count > 0)
|
||||||
{
|
{
|
||||||
// All is ok, nothing to do here.
|
// 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." });
|
return Ok(new { message = "you already got it." });
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Yavsc.Controllers
|
||||||
return new BadRequestObjectResult(ModelState);
|
return new BadRequestObjectResult(ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName);
|
var addToRoleResult = await _userManager.AddToRoleAsync(user, YavscConstants.AdminGroupName);
|
||||||
if (!addToRoleResult.Succeeded)
|
if (!addToRoleResult.Succeeded)
|
||||||
{
|
{
|
||||||
AddErrors(addToRoleResult);
|
AddErrors(addToRoleResult);
|
||||||
|
|
@ -114,11 +114,11 @@ namespace Yavsc.Controllers
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var adminCount = await _userManager.GetUsersInRoleAsync(
|
var adminCount = await _userManager.GetUsersInRoleAsync(
|
||||||
Constants.AdminGroupName);
|
YavscConstants.AdminGroupName);
|
||||||
var userCount = await _dbContext.Users.CountAsync();
|
var userCount = await _dbContext.Users.CountAsync();
|
||||||
var youAreAdmin = await _userManager.IsInRoleAsync(
|
var youAreAdmin = await _userManager.IsInRoleAsync(
|
||||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||||
Constants.AdminGroupName);
|
YavscConstants.AdminGroupName);
|
||||||
|
|
||||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
private async Task SetupView(Announce announce)
|
private async Task SetupView(Announce announce)
|
||||||
{
|
{
|
||||||
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName);
|
ViewBag.IsAdmin = User.IsInMsRole(YavscConstants.AdminGroupName);
|
||||||
ViewBag.IsPerformer = User.IsInMsRole(Constants.PerformerGroupName);
|
ViewBag.IsPerformer = User.IsInMsRole(YavscConstants.PerformerGroupName);
|
||||||
ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted;
|
ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted;
|
||||||
List<SelectListItem> dl = new List<SelectListItem>();
|
List<SelectListItem> dl = new List<SelectListItem>();
|
||||||
var rnames = System.Enum.GetNames(typeof(Reason));
|
var rnames = System.Enum.GetNames(typeof(Reason));
|
||||||
|
|
@ -82,14 +82,14 @@ namespace Yavsc.Controllers
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
// Only allow admin to create corporate annonces
|
// 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"]);
|
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
|
||||||
return View(announce);
|
return View(announce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow performers to create ServiceProposal
|
// 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"]);
|
ModelState.AddModelError("For", _localizer["YourNotAPerformer"]);
|
||||||
return View(announce);
|
return View(announce);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
var blog = await blogSpotService.Details(User, id.Value);
|
var blog = await blogSpotService.Details(User, id.Value);
|
||||||
ViewData["apicmtctlr"] = "/api/blogcomments";
|
ViewData["apicmtctlr"] = "/api/blogcomments";
|
||||||
ViewData["moderatoFlag"] = User.IsInMsRole(Constants.BlogModeratorGroupName);
|
ViewData["moderatoFlag"] = User.IsInMsRole(YavscConstants.BlogModeratorGroupName);
|
||||||
|
|
||||||
return View(blog);
|
return View(blog);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Yavsc.Controllers
|
||||||
Value = pt.FullName,
|
Value = pt.FullName,
|
||||||
Selected = currentCode == pt.FullName
|
Selected = currentCode == pt.FullName
|
||||||
}).ToList();
|
}).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;
|
ViewBag.SettingsClassName = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ namespace Yavsc.Controllers
|
||||||
Text = a.Name,
|
Text = a.Name,
|
||||||
Value = a.Code
|
Value = a.Code
|
||||||
}).ToList();
|
}).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);
|
acts.Add(nullItem);
|
||||||
if (code == null) return acts;
|
if (code == null) return acts;
|
||||||
var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code);
|
var existing = _context.Activities.Include(a => a.Children).FirstOrDefault(a => a.Code == code);
|
||||||
|
|
@ -124,9 +124,9 @@ namespace Yavsc.Controllers
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public IActionResult Create(Activity activity)
|
public IActionResult Create(Activity activity)
|
||||||
{
|
{
|
||||||
if (activity.ParentCode==Constants.NoneCode)
|
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||||
activity.ParentCode=null;
|
activity.ParentCode=null;
|
||||||
if (activity.SettingsClassName==Constants.NoneCode)
|
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||||
activity.SettingsClassName=null;
|
activity.SettingsClassName=null;
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
|
|
@ -162,9 +162,9 @@ namespace Yavsc.Controllers
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public IActionResult Edit(Activity activity)
|
public IActionResult Edit(Activity activity)
|
||||||
{
|
{
|
||||||
if (activity.ParentCode==Constants.NoneCode)
|
if (activity.ParentCode==YavscConstants.NoneCode)
|
||||||
activity.ParentCode=null;
|
activity.ParentCode=null;
|
||||||
if (activity.SettingsClassName==Constants.NoneCode)
|
if (activity.SettingsClassName==YavscConstants.NoneCode)
|
||||||
activity.SettingsClassName=null;
|
activity.SettingsClassName=null;
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
public async Task<IActionResult> Index(string id)
|
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.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
|
||||||
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
|
ViewBag.SshHeaderKey = Request.Headers[YavscConstants.SshHeaderKey];
|
||||||
var uid = User.GetUserId();
|
var uid = User.GetUserId();
|
||||||
long[] clicked = null;
|
long[] clicked = null;
|
||||||
if (uid == null)
|
if (uid == null)
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Yavsc.Controllers
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
if (model.UserId != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
|
|
||||||
_context.Instrumentation.Add(model);
|
_context.Instrumentation.Add(model);
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
if (id != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
if (id != uid) if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||||
if (musicianSettings == null)
|
if (musicianSettings == null)
|
||||||
|
|
@ -98,7 +98,7 @@ namespace Yavsc.Controllers
|
||||||
public async Task<IActionResult> Edit(Instrumentation musicianSettings)
|
public async Task<IActionResult> Edit(Instrumentation musicianSettings)
|
||||||
{
|
{
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
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 new ChallengeResult();
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Yavsc.Controllers
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
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 new ChallengeResult();
|
||||||
return View(musicianSettings);
|
return View(musicianSettings);
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Yavsc.Controllers
|
||||||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||||
|
|
||||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
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 new ChallengeResult();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public static class HostingExtensions
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
ValidateAudience = false,
|
ValidateAudience = false,
|
||||||
RoleClaimType = Constants.RoleClaimType
|
RoleClaimType = YavscConstants.RoleClaimType
|
||||||
};
|
};
|
||||||
options.MapInboundClaims = true;
|
options.MapInboundClaims = true;
|
||||||
});
|
});
|
||||||
|
|
@ -141,7 +141,7 @@ public static class HostingExtensions
|
||||||
public static IdentityBuilder AddIdentityDBAndStores(this WebApplicationBuilder builder)
|
public static IdentityBuilder AddIdentityDBAndStores(this WebApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
IServiceCollection services = builder.Services;
|
IServiceCollection services = builder.Services;
|
||||||
var connectionString = builder.Configuration.GetConnectionString(Constants.YavscConnectionStringName);
|
var connectionString = builder.Configuration.GetConnectionString(YavscConstants.YavscConnectionStringName);
|
||||||
|
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -162,7 +162,7 @@ public static class HostingExtensions
|
||||||
options.SignIn.RequireConfirmedAccount = builder.Environment.IsEnvironment(
|
options.SignIn.RequireConfirmedAccount = builder.Environment.IsEnvironment(
|
||||||
builder.Environment.EnvironmentName);
|
builder.Environment.EnvironmentName);
|
||||||
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.PreferredUserName;
|
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.PreferredUserName;
|
||||||
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||||
|
|
@ -186,18 +186,18 @@ public static class HostingExtensions
|
||||||
{
|
{
|
||||||
policy
|
policy
|
||||||
.RequireAuthenticatedUser()
|
.RequireAuthenticatedUser()
|
||||||
.RequireClaim(Constants.RoleClaimType,
|
.RequireClaim(YavscConstants.RoleClaimType,
|
||||||
new string[] { Constants.PerformerGroupName, Constants.AdminGroupName })
|
new string[] { YavscConstants.PerformerGroupName, YavscConstants.AdminGroupName })
|
||||||
;
|
;
|
||||||
});
|
});
|
||||||
options.AddPolicy("AdministratorOnly", policy =>
|
options.AddPolicy("AdministratorOnly", policy =>
|
||||||
{
|
{
|
||||||
_ = policy
|
_ = policy
|
||||||
.RequireAuthenticatedUser()
|
.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("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
|
||||||
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
|
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
|
||||||
|
|
@ -269,10 +269,10 @@ public static class HostingExtensions
|
||||||
{
|
{
|
||||||
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
|
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Subject;
|
||||||
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
|
options.ClaimsIdentity.UserNameClaimType = JwtClaimTypes.Name;
|
||||||
options.ClaimsIdentity.RoleClaimType = Constants.RoleClaimType;
|
options.ClaimsIdentity.RoleClaimType = YavscConstants.RoleClaimType;
|
||||||
});
|
});
|
||||||
var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name;
|
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")}";
|
string sqliteConnectionString = $"Data Source={Path.Combine(Path.GetTempPath(), "yavsc_test.db")}";
|
||||||
|
|
||||||
|
|
@ -503,7 +503,7 @@ public static class HostingExtensions
|
||||||
Config.UserFilesOptions = new FileServerOptions()
|
Config.UserFilesOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
||||||
RequestPath = PathString.FromUriComponent(Constants.UserFilesPath),
|
RequestPath = PathString.FromUriComponent(YavscConstants.UserFilesPath),
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||||
};
|
};
|
||||||
Config.UserFilesOptions.EnableDefaultFiles = true;
|
Config.UserFilesOptions.EnableDefaultFiles = true;
|
||||||
|
|
@ -516,7 +516,7 @@ public static class HostingExtensions
|
||||||
Config.AvatarsOptions = new FileServerOptions()
|
Config.AvatarsOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(Config.AvatarsDirName),
|
FileProvider = new PhysicalFileProvider(Config.AvatarsDirName),
|
||||||
RequestPath = PathString.FromUriComponent(Constants.AvatarsPath),
|
RequestPath = PathString.FromUriComponent(YavscConstants.AvatarsPath),
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing
|
EnableDirectoryBrowsing = enableDirectoryBrowsing
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -527,7 +527,7 @@ public static class HostingExtensions
|
||||||
Config.GitOptions = new FileServerOptions()
|
Config.GitOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(Config.GitDirName),
|
FileProvider = new PhysicalFileProvider(Config.GitDirName),
|
||||||
RequestPath = PathString.FromUriComponent(Constants.GitPath),
|
RequestPath = PathString.FromUriComponent(YavscConstants.GitPath),
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||||
};
|
};
|
||||||
Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md");
|
Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md");
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,14 @@ namespace Yavsc
|
||||||
else
|
else
|
||||||
builder.Services.AddScoped<IModerationService, ClaudeModerationService>();
|
builder.Services.AddScoped<IModerationService, ClaudeModerationService>();
|
||||||
|
|
||||||
builder.Configuration
|
var rootConfig = builder.Configuration
|
||||||
.AddJsonFile("appsettings.json")
|
.AddJsonFile("appsettings.json")
|
||||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||||
.AddEnvironmentVariables()
|
.AddEnvironmentVariables()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
rootConfig.GetConnectionString(YavscConstants.YavscConnectionStringName);
|
||||||
|
|
||||||
var app = await builder.ConfigureWebAppServices().ConfigurePipeline();
|
var app = await builder.ConfigureWebAppServices().ConfigurePipeline();
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace Yavsc.ViewModels.Manage
|
||||||
public class SetUserNameViewModel
|
public class SetUserNameViewModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[Display(Name = "User name"),RegularExpression(Constants.UserNameRegExp)]
|
[Display(Name = "User name"),RegularExpression(YavscConstants.UserNameRegExp)]
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<li><a class="dropdown-item" asp-controller="Feature" asp-action="Index">Features</a></li>
|
<li><a class="dropdown-item" asp-controller="Feature" asp-action="Index">Features</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@if (User.IsInMsRole(Constants.AdminGroupName)) {
|
@if (User.IsInMsRole(YavscConstants.AdminGroupName)) {
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="dropdown05" data-bs-toggle="dropdown" aria-expanded="false">
|
<a class="nav-link dropdown-toggle" href="#" id="dropdown05" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
Administration
|
Administration
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace Yavsc.Helpers
|
||||||
public static string ToAbsolute(this HttpRequest request, string url)
|
public static string ToAbsolute(this HttpRequest request, string url)
|
||||||
{
|
{
|
||||||
var host = request.Host;
|
var host = request.Host;
|
||||||
var isSecure = request.Headers[Constants.SshHeaderKey] == "on";
|
var isSecure = request.Headers[YavscConstants.SshHeaderKey] == "on";
|
||||||
return (isSecure ? "https" : "http") + $"://{host}/{url}";
|
return (isSecure ? "https" : "http") + $"://{host}/{url}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ namespace Yavsc
|
||||||
var userId = _dbContext.Users.First(u => u.UserName == Context.User.Identity.Name).Id;
|
var userId = _dbContext.Users.First(u => u.UserName == Context.User.Identity.Name).Id;
|
||||||
|
|
||||||
await Clients.Group(ChatHubConstants.HubGroupFollowingPrefix + userId).SendAsync("notifyUser", NotificationTypes.Connected, userName, null);
|
await Clients.Group(ChatHubConstants.HubGroupFollowingPrefix + userId).SendAsync("notifyUser", NotificationTypes.Connected, userName, null);
|
||||||
isCop = Context.User.IsInMsRole(Constants.AdminGroupName) ;
|
isCop = Context.User.IsInMsRole(YavscConstants.AdminGroupName) ;
|
||||||
if (isCop)
|
if (isCop)
|
||||||
{
|
{
|
||||||
await Groups.AddToGroupAsync(Context.ConnectionId, ChatHubConstants.HubGroupCops);
|
await Groups.AddToGroupAsync(Context.ConnectionId, ChatHubConstants.HubGroupCops);
|
||||||
|
|
@ -353,7 +353,7 @@ namespace Yavsc
|
||||||
var identityUserName = Context.User.GetUserName();
|
var identityUserName = Context.User.GetUserName();
|
||||||
|
|
||||||
if (userName[0] != '?' && Context.User!=null)
|
if (userName[0] != '?' && Context.User!=null)
|
||||||
if (!Context.User.IsInMsRole(Constants.AdminGroupName))
|
if (!Context.User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||||
{
|
{
|
||||||
|
|
||||||
var bl = _dbContext.BlackListed
|
var bl = _dbContext.BlackListed
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,8 @@ namespace Yavsc.Models
|
||||||
builder.Entity<ApplicationUser>().Property(u => u.FullName).IsRequired(false);
|
builder.Entity<ApplicationUser>().Property(u => u.FullName).IsRequired(false);
|
||||||
builder.Entity<ApplicationUser>().Property(u => u.DedicatedGoogleCalendar).IsRequired(false);
|
builder.Entity<ApplicationUser>().Property(u => u.DedicatedGoogleCalendar).IsRequired(false);
|
||||||
builder.Entity<ApplicationUser>().HasMany<ChatConnection>(c => c.Connections);
|
builder.Entity<ApplicationUser>().HasMany<ChatConnection>(c => c.Connections);
|
||||||
builder.Entity<ApplicationUser>().Property(u => u.Avatar).HasDefaultValue(Constants.DefaultAvatar);
|
builder.Entity<ApplicationUser>().Property(u => u.Avatar).HasDefaultValue(YavscConstants.DefaultAvatar);
|
||||||
builder.Entity<ApplicationUser>().Property(u => u.DiskQuota).HasDefaultValue(Constants.DefaultFSQ);
|
builder.Entity<ApplicationUser>().Property(u => u.DiskQuota).HasDefaultValue(YavscConstants.DefaultFSQ);
|
||||||
builder.Entity<ApplicationUser>().HasAlternateKey(u => u.Email);
|
builder.Entity<ApplicationUser>().HasAlternateKey(u => u.Email);
|
||||||
builder.Entity<BlackListed>().HasOne<ApplicationUser>(bl => bl.User);
|
builder.Entity<BlackListed>().HasOne<ApplicationUser>(bl => bl.User);
|
||||||
builder.Entity<BlackListed>().HasOne<ApplicationUser>(bl => bl.Owner);
|
builder.Entity<BlackListed>().HasOne<ApplicationUser>(bl => bl.Owner);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Yavsc.Services
|
||||||
// TODO: Handle the socket here.
|
// TODO: Handle the socket here.
|
||||||
// Find receivers: others in the chat room
|
// Find receivers: others in the chat room
|
||||||
// send them the flow
|
// send them the flow
|
||||||
var buffer = new byte[Constants.WebSocketsMaxBufLen];
|
var buffer = new byte[YavscConstants.WebSocketsMaxBufLen];
|
||||||
var sBuffer = new ArraySegment<byte>(buffer);
|
var sBuffer = new ArraySegment<byte>(buffer);
|
||||||
_logger.LogInformation("Receiving bytes...");
|
_logger.LogInformation("Receiving bytes...");
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ namespace Yavsc.Services
|
||||||
{
|
{
|
||||||
_logger.LogInformation("try and receive new bytes");
|
_logger.LogInformation("try and receive new bytes");
|
||||||
|
|
||||||
buffer = new byte[Constants.WebSocketsMaxBufLen];
|
buffer = new byte[YavscConstants.WebSocketsMaxBufLen];
|
||||||
received = await liveHandler.Socket.ReceiveAsync(sBuffer, liveHandler.TokenSource.Token);
|
received = await liveHandler.Socket.ReceiveAsync(sBuffer, liveHandler.TokenSource.Token);
|
||||||
|
|
||||||
_logger.LogInformation($"Received bytes : {received.Count}");
|
_logger.LogInformation($"Received bytes : {received.Count}");
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Yavsc.Services
|
||||||
claimAdds.Remove("profile");
|
claimAdds.Remove("profile");
|
||||||
claimAdds.Add(JwtClaimTypes.Name);
|
claimAdds.Add(JwtClaimTypes.Name);
|
||||||
claimAdds.Add(JwtClaimTypes.Email);
|
claimAdds.Add(JwtClaimTypes.Email);
|
||||||
claimAdds.Add(Constants.RoleClaimType);
|
claimAdds.Add(YavscConstants.RoleClaimType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (claimAdds.Contains(JwtClaimTypes.Name))
|
if (claimAdds.Contains(JwtClaimTypes.Name))
|
||||||
|
|
@ -52,12 +52,12 @@ namespace Yavsc.Services
|
||||||
if (claimAdds.Contains(JwtClaimTypes.Email))
|
if (claimAdds.Contains(JwtClaimTypes.Email))
|
||||||
claims.Add(new Claim(JwtClaimTypes.Email, user.Email));
|
claims.Add(new Claim(JwtClaimTypes.Email, user.Email));
|
||||||
|
|
||||||
if (claimAdds.Contains(Constants.RoleClaimType))
|
if (claimAdds.Contains(YavscConstants.RoleClaimType))
|
||||||
{
|
{
|
||||||
var roles = await this._userManager.GetRolesAsync(user);
|
var roles = await this._userManager.GetRolesAsync(user);
|
||||||
if (roles.Count()>0)
|
if (roles.Count()>0)
|
||||||
{
|
{
|
||||||
claims.AddRange(roles.Select(r => new Claim(Constants.RoleClaimType, r)));
|
claims.AddRange(roles.Select(r => new Claim(YavscConstants.RoleClaimType, r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return claims;
|
return claims;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ namespace Yavsc.ViewModels.Account
|
||||||
public class ExternalLoginConfirmationViewModel
|
public class ExternalLoginConfirmationViewModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[YaStringLength(2,Constants.MaxUserNameLength)]
|
[YaStringLength(2,YavscConstants.MaxUserNameLength)]
|
||||||
[YaRegularExpression(Constants.UserNameRegExp)]
|
[YaRegularExpression(YavscConstants.UserNameRegExp)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ namespace cli {
|
||||||
_logger.LogInformation("Connecting to " + url);
|
_logger.LogInformation("Connecting to " + url);
|
||||||
await _client.ConnectAsync(new Uri(url), _tokenSource.Token);
|
await _client.ConnectAsync(new Uri(url), _tokenSource.Token);
|
||||||
_logger.LogInformation("Connected");
|
_logger.LogInformation("Connected");
|
||||||
const int bufLen = Yavsc.Constants.WebSocketsMaxBufLen;
|
const int bufLen = Yavsc.YavscConstants.WebSocketsMaxBufLen;
|
||||||
byte [] buffer = new byte[bufLen];
|
byte [] buffer = new byte[bufLen];
|
||||||
const int offset=0;
|
const int offset=0;
|
||||||
int read;
|
int read;
|
||||||
|
|
@ -90,7 +90,7 @@ namespace cli {
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
read = await stream.ReadAsync(buffer, offset, bufLen);
|
read = await stream.ReadAsync(buffer, offset, bufLen);
|
||||||
lastFrame = read < Yavsc.Constants.WebSocketsMaxBufLen;
|
lastFrame = read < Yavsc.YavscConstants.WebSocketsMaxBufLen;
|
||||||
ArraySegment<byte> segment = new ArraySegment<byte>(buffer, offset, read);
|
ArraySegment<byte> segment = new ArraySegment<byte>(buffer, offset, read);
|
||||||
await _client.SendAsync(segment, pckType, lastFrame, _tokenSource.Token);
|
await _client.SendAsync(segment, pckType, lastFrame, _tokenSource.Token);
|
||||||
_logger.LogInformation($"sent {segment.Count} ");
|
_logger.LogInformation($"sent {segment.Count} ");
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ namespace cli
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string StreamingUrl { get {
|
public string StreamingUrl { get {
|
||||||
return Port==0 ? $"ws://{Authority}"+Constants.StreamingPath:
|
return Port==0 ? $"ws://{Authority}"+YavscConstants.StreamingPath:
|
||||||
$"ws://{Authority}:{Port}"+Constants.StreamingPath;
|
$"ws://{Authority}:{Port}"+YavscConstants.StreamingPath;
|
||||||
} }
|
} }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ namespace isnd.tests
|
||||||
.AddEnvironmentVariables()
|
.AddEnvironmentVariables()
|
||||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||||
{
|
{
|
||||||
[$"ConnectionStrings:{Constants.YavscConnectionStringName}"] = "InMemory"
|
[$"ConnectionStrings:{YavscConstants.YavscConnectionStringName}"] = "InMemory"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configure Kestrel for HTTPS with self-signed certificate on a dynamic port
|
// Configure Kestrel for HTTPS with self-signed certificate on a dynamic port
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue