|
|
@ -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;
|
|
|
@ -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,10 +259,11 @@ 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)
|
|
|
|
ViewBag.Calendars = new GoogleApis.CalendarApi(_googleSettings.ApiKey)
|
|
|
|
.GetCalendars(credential);
|
|
|
|
.GetCalendars(credential);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -270,19 +271,19 @@ namespace Yavsc.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// a bug
|
|
|
|
// a bug
|
|
|
|
_logger.LogError("Google token, an Forbidden calendar");
|
|
|
|
_logger.LogError("Google token, an Forbidden calendar");
|
|
|
|
if (ex.HResult == (int) HttpStatusCode.Forbidden)
|
|
|
|
if (ex.HResult == (int)HttpStatusCode.Forbidden)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return RedirectToAction("LinkLogin",new { provider = "Google" });
|
|
|
|
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 exSiren = await _dbContext.ExceptionsSIREN.FirstOrDefaultAsync(
|
|
|
|
|
|
|
|
ex => ex.SIREN == model.SIREN
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (exSiren != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("Exception SIREN:"+exSiren);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var taskCheck = await _cchecker.CheckAsync(model.SIREN);
|
|
|
|
var taskCheck = await _cchecker.CheckAsync(model.SIREN);
|
|
|
|
if (!taskCheck.success) {
|
|
|
|
if (!taskCheck.success)
|
|
|
|
|
|
|
|
{
|
|
|
|
ModelState.AddModelError(
|
|
|
|
ModelState.AddModelError(
|
|
|
|
"SIREN",
|
|
|
|
"SIREN",
|
|
|
|
_SR["Invalid company number"]+" ("+taskCheck.errorCode+")"
|
|
|
|
_SR["Invalid company number"] + " (" + taskCheck.errorCode + ")"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
_logger.LogWarning("Invalid company number, using key:"+_cinfoSettings.ApiKey);
|
|
|
|
_logger.LogInformation("Invalid company number, using key:" + _cinfoSettings.ApiKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|