Merge branch 'vnext' of https://github.com/pazof/yavsc into vnext

* 'vnext' of https://github.com/pazof/yavsc: (38 commits)
fixe le premier démarrage
Corrige le mot de passe perdu d'un utilisateur au nom contenant des
espaces
traductions
fixe la reccupération du mot de passe
refabrique:
MEP index blogs
Specialized the book query notification
Updated the Licence validity
cleaned up log warnings
label event date
cleans the code
Adds support for SIREN exceptions to validation from the external
provider
layout
trads
refactoring
refactoring
Google maps: a map
image
implements an AccessDenied page
A better layout
...

# Conflicts:
#	Yavsc.Api/project.lock.json
#	Yavsc.Client/Yavsc.Client.csproj
#	Yavsc.Client/packages.config
#	sendmsg/Program.cs
This commit is contained in:
Paul Schneider 2016-07-30 22:51:19 +02:00
commit e3a73e8146
190 changed files with 6664 additions and 763 deletions

View file

@ -15,6 +15,7 @@ using Yavsc.Models;
using Yavsc.Services;
using Yavsc.ViewModels.Account;
using Yavsc.Helpers;
using Microsoft.Extensions.Localization;
namespace Yavsc.Controllers
{
@ -30,6 +31,8 @@ namespace Yavsc.Controllers
SmtpSettings _smtpSettings;
TwilioSettings _twilioSettings;
IStringLocalizer _localizer;
// TwilioSettings _twilioSettings;
public AccountController(
@ -38,7 +41,8 @@ namespace Yavsc.Controllers
IEmailSender emailSender,
IOptions<SiteSettings> siteSettings,
IOptions<SmtpSettings> smtpSettings,
ILoggerFactory loggerFactory, IOptions<TwilioSettings> twilioSettings)
ILoggerFactory loggerFactory, IOptions<TwilioSettings> twilioSettings,
IStringLocalizer<Yavsc.Resources.YavscLocalisation> localizer)
{
_userManager = userManager;
_signInManager = signInManager;
@ -49,6 +53,7 @@ namespace Yavsc.Controllers
_smtpSettings = smtpSettings.Value;
_twilioSettings = twilioSettings.Value;
_logger = loggerFactory.CreateLogger<AccountController>();
_localizer = localizer;
}
@ -70,6 +75,16 @@ namespace Yavsc.Controllers
*/
}
public ActionResult AccessDenied(string requestUrl = null)
{
ViewBag.UserIsSignedIn = User.IsSignedIn();
if (string.IsNullOrWhiteSpace(requestUrl))
if (string.IsNullOrWhiteSpace(Request.Headers["Referer"]))
requestUrl = "/";
else requestUrl = Request.Headers["Referer"];
return View("AccessDenied",requestUrl);
}
[HttpPost(Constants.LoginPath)]
public async Task<IActionResult> SignIn(SignInViewModel model)
{
@ -325,10 +340,14 @@ namespace Yavsc.Controllers
{
if (ModelState.IsValid)
{
var user = await _userManager.FindByNameAsync(model.Email);
var user = await _userManager.FindByEmailAsync(model.Email);
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
{
// Don't reveal that the user does not exist or is not confirmed
if (user == null)
_logger.LogWarning($"ForgotPassword: Email {model.Email} not found");
else
_logger.LogWarning($"ForgotPassword: Email {model.Email} not confirmed");
return View("ForgotPasswordConfirmation");
}
@ -336,8 +355,8 @@ namespace Yavsc.Controllers
// Send an email with this link
var code = await _userManager.GeneratePasswordResetTokenAsync(user);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
await _emailSender.SendEmailAsync(_siteSettings,_smtpSettings,model.Email, "Reset Password",
"Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
await _emailSender.SendEmailAsync(_siteSettings,_smtpSettings,model.Email, _localizer["Reset Password"],
_localizer["Please reset your password by following this link:"] + callbackUrl );
return View("ForgotPasswordConfirmation");
}
@ -356,7 +375,7 @@ namespace Yavsc.Controllers
//
// GET: /Account/ResetPassword
[HttpGet]
public IActionResult ResetPassword(string code = null)
public IActionResult ResetPassword(string UserId, string code = null)
{
return code == null ? View("Error") : View();
}
@ -371,7 +390,7 @@ namespace Yavsc.Controllers
{
return View(model);
}
var user = await _userManager.FindByNameAsync(model.Email);
var user = await _userManager.FindByEmailAsync(model.Email);
if (user == null)
{
// Don't reveal that the user does not exist

View file

@ -1,14 +1,15 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging;
using Yavsc.Models;
using System;
using Microsoft.AspNet.Authorization;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
using Microsoft.Extensions.OptionsModel;
using Yavsc.Models;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

View file

@ -96,7 +96,7 @@ namespace Yavsc.Controllers
);
var pro = _context.Performers.Include(
x => x.Performer).FirstOrDefault(
x => x.PerfomerId == id
x => x.PerformerId == id
);
if (pro == null)
return HttpNotFound();
@ -107,7 +107,7 @@ namespace Yavsc.Controllers
return View(new BookQuery(new Location(),DateTime.Now.AddHours(4))
{
PerformerProfile = pro,
PerformerId = pro.PerfomerId,
PerformerId = pro.PerformerId,
ClientId = userid,
Client = user
});
@ -129,7 +129,7 @@ namespace Yavsc.Controllers
u => u.Performer
).Include( u => u.Performer.Devices)
.FirstOrDefault(
x => x.PerfomerId == command.PerformerId
x => x.PerformerId == command.PerformerId
);
command.PerformerProfile = pro;
var user = await _userManager.FindByIdAsync(
@ -152,12 +152,14 @@ namespace Yavsc.Controllers
var regids = command.PerformerProfile.Performer
.Devices.Select(d => d.GCMRegistrationId);
var sregids = string.Join(",",regids);
_logger.LogWarning($"ApiKey: {_googleSettings.ApiKey} {sregids}");
grep = await _GCMSender.NotifyAsync(_googleSettings,regids,yaev);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
// if (grep==null || grep.success<=0 || grep.failure>0)
ViewBag.GooglePayload=grep;
if (grep!=null)
_logger.LogWarning($"Performer: {command.PerformerProfile.Performer.UserName} success: {grep.success} failure: {grep.failure}");
await _emailSender.SendEmailAsync(
_siteSettings, _smtpSettings,
@ -166,7 +168,8 @@ namespace Yavsc.Controllers
$"{yaev.Description}\r\n-- \r\n{yaev.Comment}\r\n"
);
}
return RedirectToAction("Index");
ViewBag.GoogleSettings = _googleSettings;
return View("CommandConfirmation",command);
}
ViewBag.GoogleSettings = _googleSettings;
return View(command);

View file

@ -37,7 +37,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
RDVEstimate estimate = _context.Estimates
Estimate estimate = _context.Estimates
.Include(e => e.Query)
.Include(e => e.Query.PerformerProfile)
.Include(e => e.Query.PerformerProfile.Performer)
@ -61,7 +61,7 @@ namespace Yavsc.Controllers
// POST: Estimate/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(RDVEstimate estimate,
public IActionResult Create(Estimate estimate,
ICollection<IFormFile> newGraphics,
ICollection<IFormFile> newFiles
)
@ -75,7 +75,7 @@ namespace Yavsc.Controllers
var perfomerProfile = _context.Performers
.Include(
perpr => perpr.Performer).FirstOrDefault(
x=>x.PerfomerId == estimate.Query.PerformerId
x=>x.PerformerId == estimate.Query.PerformerId
);
var command = _context.BookQueries.FirstOrDefault(
cmd => cmd.Id == estimate.CommandId
@ -115,7 +115,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
if (estimate == null)
{
return HttpNotFound();
@ -127,7 +127,7 @@ namespace Yavsc.Controllers
// POST: Estimate/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(RDVEstimate estimate)
public IActionResult Edit(Estimate estimate)
{
if (ModelState.IsValid)
{
@ -147,7 +147,7 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
if (estimate == null)
{
return HttpNotFound();
@ -161,7 +161,7 @@ namespace Yavsc.Controllers
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(long id)
{
RDVEstimate estimate = _context.Estimates.Single(m => m.Id == id);
Estimate estimate = _context.Estimates.Single(m => m.Id == id);
_context.Estimates.Remove(estimate);
_context.SaveChanges();
return RedirectToAction("Index");

View file

@ -69,7 +69,7 @@ namespace Yavsc.Controllers
var pro = _context.Performers.Include(
pr => pr.Performer
).FirstOrDefault(
x=>x.PerfomerId == bookQuery.PerformerId
x=>x.PerformerId == bookQuery.PerformerId
);
if (pro==null)
return HttpNotFound();
@ -95,7 +95,7 @@ namespace Yavsc.Controllers
[Produces("text/x-tex"), Authorize,
Route("Release/Estimate-{id}.tex")]
public RDVEstimate Estimate(long id)
public Estimate Estimate(long id)
{
var estimate = _context.Estimates.Include(x=>x.Query).
Include(x=>x.Query.Client).FirstOrDefault(x=>x.Id==id);

View file

@ -52,7 +52,7 @@ namespace Yavsc.Controllers
IOptions<GoogleAuthSettings> googleSettings,
IOptions<PayPalSettings> paypalSettings,
IOptions<CompanyInfoSettings> cinfoSettings,
IStringLocalizer <Yavsc.Resources.YavscLocalisation>SR,
IStringLocalizer<Yavsc.Resources.YavscLocalisation> SR,
ILoggerFactory loggerFactory)
{
_dbContext = context;
@ -87,7 +87,7 @@ namespace Yavsc.Controllers
var user = await GetCurrentUserAsync();
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
var model = new IndexViewModel
{
HasPassword = await _userManager.HasPasswordAsync(user),
@ -100,11 +100,11 @@ namespace Yavsc.Controllers
Balance = user.AccountBalance,
ActiveCommandCount = _dbContext.BookQueries.Count(x => (x.ClientId == user.Id) && (x.EventDate > DateTime.Now)),
HasDedicatedCalendar = !string.IsNullOrEmpty(user.DedicatedGoogleCalendar),
Roles = await _userManager.GetRolesAsync (user)
Roles = await _userManager.GetRolesAsync(user)
};
if (_dbContext.Performers.Any(x => x.PerfomerId == user.Id))
if (_dbContext.Performers.Any(x => x.PerformerId == user.Id))
{
var code = _dbContext.Performers.First(x => x.PerfomerId == user.Id).ActivityCode;
var code = _dbContext.Performers.First(x => x.PerformerId == user.Id).ActivityCode;
model.Activity = _dbContext.Activities.First(x => x.Code == code);
}
return View(model);
@ -259,30 +259,31 @@ namespace Yavsc.Controllers
{
var credential = await _userManager.GetCredentialForGoogleApiAsync(
_dbContext, User.GetUserId());
if (credential==null)
return RedirectToAction("LinkLogin",new { provider = "Google" });
if (credential == null)
return RedirectToAction("LinkLogin", new { provider = "Google" });
try {
ViewBag.Calendars = new GoogleApis.CalendarApi(_googleSettings.ApiKey)
.GetCalendars(credential);
}
catch (WebException ex)
try
{
ViewBag.Calendars = new GoogleApis.CalendarApi(_googleSettings.ApiKey)
.GetCalendars(credential);
}
catch (WebException ex)
{
// a bug
_logger.LogError("Google token, an Forbidden calendar");
if (ex.HResult == (int)HttpStatusCode.Forbidden)
{
// a bug
_logger.LogError("Google token, an Forbidden calendar");
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]
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;
await _dbContext.SaveChangesAsync();
if (string.IsNullOrEmpty(model.ReturnUrl))
@ -461,52 +462,69 @@ namespace Yavsc.Controllers
{
var user = GetCurrentUserAsync().Result;
var uid = user.Id;
bool existing = _dbContext.Performers.Any(x => x.PerfomerId == uid);
bool existing = _dbContext.Performers.Any(x => x.PerformerId == uid);
ViewBag.Activities = _dbContext.ActivityItems(null);
ViewBag.GoogleSettings = _googleSettings;
if (existing)
{
var currentProfile = _dbContext.Performers.Include(x => x.OrganisationAddress)
.First(x => x.PerfomerId == uid);
var currentProfile = _dbContext.Performers.Include(x => x.OrganizationAddress)
.First(x => x.PerformerId == uid);
string currentCode = currentProfile.ActivityCode;
return View(currentProfile);
}
return View(new PerformerProfile
{
PerfomerId = user.Id,
OrganisationAddress = new Location()
PerformerId = user.Id,
OrganizationAddress = new Location()
});
}
[HttpPost]
[ValidateAntiForgeryToken, Authorize]
[Authorize]
public async Task<IActionResult> SetActivity(PerformerProfile model)
{
var user = GetCurrentUserAsync().Result;
var uid = user.Id;
if (ModelState.IsValid)
try
{
var taskCheck = await _cchecker.CheckAsync(model.SIREN);
if (!taskCheck.success) {
ModelState.AddModelError(
"SIREN",
_SR["Invalid company number"]+" ("+taskCheck.errorCode+")"
if (ModelState.IsValid)
{
var exSiren = await _dbContext.ExceptionsSIREN.FirstOrDefaultAsync(
ex => ex.SIREN == model.SIREN
);
_logger.LogWarning("Invalid company number, using key:"+_cinfoSettings.ApiKey);
if (exSiren != null)
{
_logger.LogInformation("Exception SIREN:"+exSiren);
}
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);
}
}
}
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
}
if (ModelState.IsValid)
{
if (uid == model.PerfomerId)
if (uid == model.PerformerId)
{
bool addrexists = _dbContext.Map.Any(x => model.OrganisationAddress.Id == x.Id);
bool addrexists = _dbContext.Map.Any(x => model.OrganizationAddress.Id == x.Id);
if (!addrexists)
{
_dbContext.Map.Add(model.OrganisationAddress);
_dbContext.Map.Add(model.OrganizationAddress);
}
bool existing = _dbContext.Performers.Any(x => x.PerfomerId == uid);
bool existing = _dbContext.Performers.Any(x => x.PerformerId == uid);
if (existing)
{
_dbContext.Update(model);
@ -518,7 +536,7 @@ namespace Yavsc.Controllers
return RedirectToAction(nameof(Index), new { Message = message });
}
else ModelState.AddModelError(string.Empty, "Acces denied");
else ModelState.AddModelError(string.Empty, $"Access denied ({uid} vs {model.PerformerId})");
}
ViewBag.GoogleSettings = _googleSettings;
ViewBag.Activities = _dbContext.ActivityItems(model.ActivityCode);
@ -530,11 +548,11 @@ namespace Yavsc.Controllers
{
var user = GetCurrentUserAsync().Result;
var uid = user.Id;
bool existing = _dbContext.Performers.Any(x => x.PerfomerId == uid);
bool existing = _dbContext.Performers.Any(x => x.PerformerId == uid);
if (existing)
{
_dbContext.Performers.Remove(
_dbContext.Performers.First(x => x.PerfomerId == uid)
_dbContext.Performers.First(x => x.PerformerId == uid)
);
_dbContext.SaveChanges();
}

View file

@ -0,0 +1,121 @@
using System.Linq;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
using Yavsc.Models;
using Yavsc.Models.Billing;
namespace Yavsc.Controllers
{
[Authorize(Roles="Administrator")]
public class SIRENExceptionsController : Controller
{
private ApplicationDbContext _context;
public SIRENExceptionsController(ApplicationDbContext context)
{
_context = context;
}
// GET: SIRENExceptions
public IActionResult Index()
{
return View(_context.ExceptionsSIREN.ToList());
}
// GET: SIRENExceptions/Details/5
public IActionResult Details(string id)
{
if (id == null)
{
return HttpNotFound();
}
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
if (exceptionSIREN == null)
{
return HttpNotFound();
}
return View(exceptionSIREN);
}
// GET: SIRENExceptions/Create
public IActionResult Create()
{
return View();
}
// POST: SIRENExceptions/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(ExceptionSIREN exceptionSIREN)
{
if (ModelState.IsValid)
{
_context.ExceptionsSIREN.Add(exceptionSIREN);
_context.SaveChanges();
return RedirectToAction("Index");
}
return View(exceptionSIREN);
}
// GET: SIRENExceptions/Edit/5
public IActionResult Edit(string id)
{
if (id == null)
{
return HttpNotFound();
}
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
if (exceptionSIREN == null)
{
return HttpNotFound();
}
return View(exceptionSIREN);
}
// POST: SIRENExceptions/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(ExceptionSIREN exceptionSIREN)
{
if (ModelState.IsValid)
{
_context.Update(exceptionSIREN);
_context.SaveChanges();
return RedirectToAction("Index");
}
return View(exceptionSIREN);
}
// GET: SIRENExceptions/Delete/5
[ActionName("Delete")]
public IActionResult Delete(string id)
{
if (id == null)
{
return HttpNotFound();
}
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
if (exceptionSIREN == null)
{
return HttpNotFound();
}
return View(exceptionSIREN);
}
// POST: SIRENExceptions/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(string id)
{
ExceptionSIREN exceptionSIREN = _context.ExceptionsSIREN.Single(m => m.SIREN == id);
_context.ExceptionsSIREN.Remove(exceptionSIREN);
_context.SaveChanges();
return RedirectToAction("Index");
}
}
}