Adds support for SIREN exceptions to validation from the external provider
This commit is contained in:
@ -52,7 +52,7 @@ namespace Yavsc.Controllers
|
|||||||
IOptions<GoogleAuthSettings> googleSettings,
|
IOptions<GoogleAuthSettings> googleSettings,
|
||||||
IOptions<PayPalSettings> paypalSettings,
|
IOptions<PayPalSettings> paypalSettings,
|
||||||
IOptions<CompanyInfoSettings> cinfoSettings,
|
IOptions<CompanyInfoSettings> cinfoSettings,
|
||||||
IStringLocalizer <Yavsc.Resources.YavscLocalisation>SR,
|
IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR,
|
||||||
ILoggerFactory loggerFactory)
|
ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_dbContext = context;
|
_dbContext = context;
|
||||||
@ -87,7 +87,7 @@ namespace Yavsc.Controllers
|
|||||||
|
|
||||||
var user = await GetCurrentUserAsync();
|
var user = await GetCurrentUserAsync();
|
||||||
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
|
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
|
||||||
|
|
||||||
var model = new IndexViewModel
|
var model = new IndexViewModel
|
||||||
{
|
{
|
||||||
HasPassword = await _userManager.HasPasswordAsync(user),
|
HasPassword = await _userManager.HasPasswordAsync(user),
|
||||||
@ -100,7 +100,7 @@ namespace Yavsc.Controllers
|
|||||||
Balance = user.AccountBalance,
|
Balance = user.AccountBalance,
|
||||||
ActiveCommandCount = _dbContext.BookQueries.Count(x => (x.ClientId == user.Id) && (x.EventDate > DateTime.Now)),
|
ActiveCommandCount = _dbContext.BookQueries.Count(x => (x.ClientId == user.Id) && (x.EventDate > DateTime.Now)),
|
||||||
HasDedicatedCalendar = !string.IsNullOrEmpty(user.DedicatedGoogleCalendar),
|
HasDedicatedCalendar = !string.IsNullOrEmpty(user.DedicatedGoogleCalendar),
|
||||||
Roles = await _userManager.GetRolesAsync (user)
|
Roles = await _userManager.GetRolesAsync(user)
|
||||||
};
|
};
|
||||||
if (_dbContext.Performers.Any(x => x.PerformerId == user.Id))
|
if (_dbContext.Performers.Any(x => x.PerformerId == user.Id))
|
||||||
{
|
{
|
||||||
@ -259,30 +259,31 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
var credential = await _userManager.GetCredentialForGoogleApiAsync(
|
var credential = await _userManager.GetCredentialForGoogleApiAsync(
|
||||||
_dbContext, User.GetUserId());
|
_dbContext, User.GetUserId());
|
||||||
if (credential==null)
|
if (credential == null)
|
||||||
return RedirectToAction("LinkLogin",new { provider = "Google" });
|
return RedirectToAction("LinkLogin", new { provider = "Google" });
|
||||||
|
|
||||||
try {
|
try
|
||||||
ViewBag.Calendars = new GoogleApis.CalendarApi(_googleSettings.ApiKey)
|
{
|
||||||
.GetCalendars(credential);
|
ViewBag.Calendars = new GoogleApis.CalendarApi(_googleSettings.ApiKey)
|
||||||
}
|
.GetCalendars(credential);
|
||||||
catch (WebException ex)
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
// a bug
|
||||||
|
_logger.LogError("Google token, an Forbidden calendar");
|
||||||
|
if (ex.HResult == (int)HttpStatusCode.Forbidden)
|
||||||
{
|
{
|
||||||
// a bug
|
return RedirectToAction("LinkLogin", new { provider = "Google" });
|
||||||
_logger.LogError("Google token, an Forbidden calendar");
|
|
||||||
if (ex.HResult == (int) HttpStatusCode.Forbidden)
|
|
||||||
{
|
|
||||||
return RedirectToAction("LinkLogin",new { provider = "Google" });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return View(new SetGoogleCalendarViewModel { ReturnUrl=returnUrl });
|
}
|
||||||
|
return View(new SetGoogleCalendarViewModel { ReturnUrl = returnUrl });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost,ValidateAntiForgeryToken,
|
[HttpPost, ValidateAntiForgeryToken,
|
||||||
Authorize]
|
Authorize]
|
||||||
public async Task<IActionResult> SetGoogleCalendar(SetGoogleCalendarViewModel model)
|
public async Task<IActionResult> SetGoogleCalendar(SetGoogleCalendarViewModel model)
|
||||||
{
|
{
|
||||||
var user = _dbContext.Users.FirstOrDefault(u=>u.Id == User.GetUserId());
|
var user = _dbContext.Users.FirstOrDefault(u => u.Id == User.GetUserId());
|
||||||
user.DedicatedGoogleCalendar = model.GoogleCalendarId;
|
user.DedicatedGoogleCalendar = model.GoogleCalendarId;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
if (string.IsNullOrEmpty(model.ReturnUrl))
|
if (string.IsNullOrEmpty(model.ReturnUrl))
|
||||||
@ -485,16 +486,28 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
var user = GetCurrentUserAsync().Result;
|
var user = GetCurrentUserAsync().Result;
|
||||||
var uid = user.Id;
|
var uid = user.Id;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var taskCheck = await _cchecker.CheckAsync(model.SIREN);
|
var exSiren = await _dbContext.ExceptionsSIREN.FirstOrDefaultAsync(
|
||||||
if (!taskCheck.success) {
|
ex => ex.SIREN == model.SIREN
|
||||||
ModelState.AddModelError(
|
);
|
||||||
"SIREN",
|
if (exSiren != null)
|
||||||
_SR["Invalid company number"]+" ("+taskCheck.errorCode+")"
|
{
|
||||||
);
|
_logger.LogInformation("Exception SIREN:"+exSiren);
|
||||||
_logger.LogWarning("Invalid company number, using key:"+_cinfoSettings.ApiKey);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var taskCheck = await _cchecker.CheckAsync(model.SIREN);
|
||||||
|
if (!taskCheck.success)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(
|
||||||
|
"SIREN",
|
||||||
|
_SR["Invalid company number"] + " (" + taskCheck.errorCode + ")"
|
||||||
|
);
|
||||||
|
_logger.LogInformation("Invalid company number, using key:" + _cinfoSettings.ApiKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user