preparing to feed abstract

[FIXME] test won't end
This commit is contained in:
2018-07-15 06:47:41 +02:00
parent 3505d5aa6c
commit 6c50650b8a
33 changed files with 721 additions and 242 deletions

View File

@ -141,7 +141,9 @@ namespace Yavsc.WebApi.Controllers
.Include(u=>u.Roles)
.FirstAsync(u=>u.Id == uid);
var user = new Me(userData);
var user = new Me(userData.Id, userData.UserName, userData.Email,
userData.Avatar ,
userData.PostalAddress, userData.DedicatedGoogleCalendar );
var userRoles = _dbContext.UserRoles.Where(u=>u.UserId == uid).ToArray();

View File

@ -20,6 +20,7 @@ using Newtonsoft.Json;
namespace Yavsc.Controllers
{
using Microsoft.AspNet.Http.Authentication;
using Yavsc.Abstract.Manage;
using Yavsc.Helpers;
@ -84,6 +85,7 @@ namespace Yavsc.Controllers
var properties = _signInManager.ConfigureExternalAuthenticationProperties(OpenIdConnectDefaults.AuthenticationScheme, returnUrl);
return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, properties);
*/
}
[AllowAnonymous]

View File

@ -3,17 +3,24 @@ using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Authentication;
using Yavsc.ViewModels.Account;
namespace Yavsc.Helpers {
public static class HttpContextExtensions {
public static IEnumerable<AuthenticationDescription> GetExternalProviders(this HttpContext context) {
public static IEnumerable<YaAuthenticationDescription> GetExternalProviders(this HttpContext context) {
if (context == null) {
throw new ArgumentNullException(nameof(context));
}
return from description in context.Authentication.GetAuthenticationSchemes()
where !string.IsNullOrEmpty(description.DisplayName)
select description;
select
( new YaAuthenticationDescription
{
DisplayName = description.DisplayName,
AuthenticationScheme = description.AuthenticationScheme,
Items = description.Items
});;
}
public static bool IsProviderSupported(this HttpContext context, string provider) {

View File

@ -336,6 +336,7 @@
<data name="PreferedDate"><value>Date souhaitée</value></data>
<data name="PresationLocation"><value>Lieu de la présation: {0}.\n</value></data>
<data name="Preview"><value>Prévisualiser</value><comment>Prévisualiser le document</comment></data>
<data name="Previsional"><value>Montant prévisionel de la préstation</value></data>
<data name="Profile edition"><value>Édition du profil</value></data>
<data name="Product reference"><value>Référence produit</value></data>
<data name="prestation"><value>prestation</value></data>

100
Yavsc/Services/GCMSender.cs Normal file
View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using Newtonsoft.Json;
using Yavsc.Interfaces.Workflow;
using Yavsc.Models.Google.Messaging;
using Yavsc.Models.Haircut;
using Yavsc.Models.Messaging;
using Yavsc.Server.Helpers;
namespace Yavsc.Services
{
public class GCMSender : IGoogleCloudMessageSender
{
private ILogger _logger;
SiteSettings siteSettings;
GoogleAuthSettings googleSettings;
public GCMSender(
ILoggerFactory loggerFactory,
IOptions<SiteSettings> sitesOptions,
IOptions<SmtpSettings> smtpOptions,
IOptions<GoogleAuthSettings> googleOptions
)
{ _logger = loggerFactory.CreateLogger<MailSender>();
siteSettings = sitesOptions?.Value;
googleSettings = googleOptions?.Value;
}
public async Task <MessageWithPayloadResponse> NotifyEvent<Event>
( IEnumerable<string> regids, Event ev)
where Event : IEvent
{
if (ev == null)
throw new Exception("Spécifier un évènement");
if (ev.Sender == null)
throw new Exception("Spécifier un expéditeur");
if (regids == null )
throw new NotImplementedException("Notify & No GCM reg ids");
var raa = regids.ToArray();
if (raa.Length<1)
throw new NotImplementedException("No GCM reg ids");
var msg = new MessageWithPayload<Event>()
{
data = ev,
registration_ids = regids.ToArray()
};
_logger.LogInformation("Sendding to Google : "+JsonConvert.SerializeObject(msg));
try {
using (var m = new SimpleJsonPostMethod("https://gcm-http.googleapis.com/gcm/send",$"key={googleSettings.ApiKey}")) {
return await m.Invoke<MessageWithPayloadResponse>(msg);
}
}
catch (Exception ex) {
throw new Exception ("Quelque chose s'est mal passé à l'envoi",ex);
}
}
public async Task<MessageWithPayloadResponse> NotifyBookQueryAsync( IEnumerable<string> registrationIds, RdvQueryEvent ev)
{
return await NotifyEvent<RdvQueryEvent>(registrationIds, ev);
}
public async Task<MessageWithPayloadResponse> NotifyEstimateAsync(IEnumerable<string> registrationIds, EstimationEvent ev)
{
return await NotifyEvent<EstimationEvent>(registrationIds, ev);
}
public async Task<MessageWithPayloadResponse> NotifyHairCutQueryAsync(
IEnumerable<string> registrationIds, HairCutQueryEvent ev)
{
return await NotifyEvent<HairCutQueryEvent>(registrationIds, ev);
}
public async Task<MessageWithPayloadResponse> NotifyAsync(IEnumerable<string> regids, IEvent yaev)
{
return await NotifyEvent<IEvent>(regids, yaev);
}
/* SMS with Twilio:
public Task SendSmsAsync(TwilioSettings twilioSettigns, string number, string message)
{
var Twilio = new TwilioRestClient(twilioSettigns.AccountSID, twilioSettigns.Token);
var result = Twilio.SendMessage( twilioSettigns.SMSAccountFrom, number, message);
// Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
// Twilio doesn't currently have an async API, so return success.
return Task.FromResult(result.Status != "Failed");
} */
}
}

View File

@ -0,0 +1,79 @@
using System;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using MimeKit;
using Yavsc.Abstract.Manage;
namespace Yavsc.Services
{
public class MailSender : IEmailSender
{
private ILogger _logger;
SiteSettings siteSettings;
SmtpSettings smtpSettings;
public MailSender(
ILoggerFactory loggerFactory,
IOptions<SiteSettings> sitesOptions,
IOptions<SmtpSettings> smtpOptions,
IOptions<GoogleAuthSettings> googleOptions
)
{
_logger = loggerFactory.CreateLogger<MailSender>();
siteSettings = sitesOptions?.Value;
smtpSettings = smtpOptions?.Value;
}
/// <summary>
///
/// </summary>
/// <param name="googleSettings"></param>
/// <param name="registrationId"></param>
/// <param name="ev"></param>
/// <returns>a MessageWithPayloadResponse,
/// <c>bool somethingsent = (response.failure == 0 &amp;&amp; response.success > 0)</c>
/// </returns>
public async Task<EmailSentViewModel> SendEmailAsync(string username, string email, string subject, string message)
{
EmailSentViewModel model = new EmailSentViewModel{ EMail = email };
try
{
MimeMessage msg = new MimeMessage();
msg.From.Add(new MailboxAddress(
siteSettings.Owner.Name,
siteSettings.Owner.EMail));
msg.To.Add(new MailboxAddress(username, email));
msg.Body = new TextPart("plain")
{
Text = message
};
msg.Subject = subject;
msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId(
siteSettings.Authority
);
using (SmtpClient sc = new SmtpClient())
{
sc.Connect(
smtpSettings.Host,
smtpSettings.Port,
SecureSocketOptions.None);
sc.Send(msg);
model.MessageId = msg.MessageId;
}
}
catch (Exception ex)
{
model.Sent = false;
model.ErrorMessage = ex.Message;
return model;
}
return model;
}
}
}

View File

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MimeKit;
using MailKit.Security;
using System;
using Yavsc.Models.Messaging;
using Yavsc.Models;
using Yavsc.Models.Google.Messaging;
using System.Collections.Generic;
using Yavsc.Models.Haircut;
using Yavsc.Interfaces.Workflow;
using System.Linq;
using Newtonsoft.Json;
using Yavsc.Server.Helpers;
using Yavsc.Abstract.Manage;
using Microsoft.AspNet.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
namespace Yavsc.Services
{
// This class is used by the application to send Email and SMS
// when you turn on two-factor authentication in ASP.NET Identity.
// For more details see this link http://go.microsoft.com/fwlink/?LinkID=532713
}

View File

@ -172,14 +172,14 @@ namespace Yavsc
};
branch.UseMiddleware<Yavsc.Auth.GoogleMiddleware>(YavscGoogleAppOptions);
/* FIXME 403
branch.UseTwitterAuthentication(options=>
{
TwitterAppOptions = options;
options.ConsumerKey = Configuration["Authentication:Twitter:ClientId"];
options.ConsumerSecret = Configuration["Authentication:Twitter:ClientSecret"];
});
}); */
branch.UseOAuthAuthorizationServer(

View File

@ -242,8 +242,8 @@ namespace Yavsc
services.AddTransient<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>();
// Add application services.
services.AddTransient<IEmailSender, MessageSender>();
services.AddTransient<IGoogleCloudMessageSender, MessageSender>();
services.AddTransient<IEmailSender, MailSender>();
services.AddTransient<IGoogleCloudMessageSender, GCMSender>();
services.AddTransient<IBillingService, BillingService>();
services.AddTransient<IDataStore, FileDataStore>( (sp) => new FileDataStore("googledatastore",false) );
services.AddTransient<ICalendarManager, CalendarManager>();

View File

@ -0,0 +1,11 @@
using Microsoft.AspNet.FileProviders;
namespace Yavsc.ViewModels.Auth
{
public class ViewFileContext
{
public string UserName { get; set; }
public IFileInfo File { get; set; }
public string Path { get; set; }
}
}

View File

@ -0,0 +1,55 @@
using System.Collections.Generic;
using Microsoft.AspNet.Identity;
namespace Yavsc.ViewModels.Manage
{
using Models.Bank;
using Models;
using Models.Workflow;
public class IndexViewModel
{
public string UserName {get; set; }
public string Avatar { get; set; }
public bool HasPassword { get; set; }
public IList<UserLoginInfo> Logins { get; set; }
public string PhoneNumber { get; set; }
public bool TwoFactor { get; set; }
public bool BrowserRemembered { get; set; }
public List<UserActivity> Activity { get; set; }
public bool HaveProfessionalSettings { get; set; }
public bool HaveActivityToConfigure { get; set; }
public long PostsCounter { get; set; }
public AccountBalance Balance { get; set; }
public long ActiveCommandCount { get; set; }
public bool HasDedicatedCalendar { get; set; }
public IEnumerable<string> Roles { get; set; }
public string FullName { get; set; }
public string PostalAddress { get; set; }
public BankIdentity BankInfo { get; set; }
public long DiskQuota { get; set; }
public long DiskUsage { get; set; }
public string DedicatedCalendarId { get; set; }
public string EMail { get; set; }
public bool EmailConfirmed { get; set; }
public bool AllowMonthlyEmail { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
using Microsoft.AspNet.Http.Authentication;
using Microsoft.AspNet.Identity;
namespace Yavsc.ViewModels.Manage
{
public class ManageLoginsViewModel
{
public IList<UserLoginInfo> CurrentLogins { get; set; }
public IList<AuthenticationDescription> OtherLogins { get; set; }
}
}

View File

@ -36,10 +36,10 @@
@Html.DisplayFor(model => model.Description)
</dd>
<dt>
@Html.DisplayNameFor(model => model.LocalRepo)
@Html.DisplayNameFor(model => model.Repository)
</dt>
<dd>
@Html.DisplayFor(model => model.LocalRepo)
@Html.DisplayFor(model => model.Repository)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OwnerId)

View File

@ -10,6 +10,12 @@
<h4>Project</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Consent)
</dt>
@ -35,10 +41,10 @@
@Html.DisplayFor(model => model.Description)
</dd>
<dt>
@Html.DisplayNameFor(model => model.LocalRepo)
@Html.DisplayNameFor(model => model.Repository)
</dt>
<dd>
@Html.DisplayFor(model => model.LocalRepo)
@Html.DisplayFor(model => model.Repository)
</dd>
<dt>
@Html.DisplayNameFor(model => model.OwnerId)

View File

@ -13,88 +13,31 @@
<div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="ActivityCode" class="control-label col-md-2">ActivityCode</label>
<label asp-for="Name" class="control-label col-md-2">Nom</label>
<div class="col-md-10">
<select asp-for="ActivityCode" class="form-control" />
<span asp-validation-for="ActivityCode" class="text-danger" />
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="ClientId" class="control-label col-md-2">ClientId</label>
<div class="col-md-10">
<select asp-for="ClientId" class="form-control" />
<span asp-validation-for="ClientId" class="text-danger" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
<input asp-for="Consent" />
<label asp-for="Consent"></label>
</div>
</div>
</div>
<div class="form-group">
<label asp-for="DateCreated" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="DateCreated" class="form-control" />
<span asp-validation-for="DateCreated" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="DateModified" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="DateModified" class="form-control" />
<span asp-validation-for="DateModified" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Description" class="col-md-2 control-label"></label>
<label asp-for="Description" class="col-md-2 control-label">Description</label>
<div class="col-md-10">
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger" />
<span asp-validation-for="Description" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="LocalRepo" class="col-md-2 control-label"></label>
<label asp-for="Repository" class="col-md-2 control-label">Repository</label>
<div class="col-md-10">
<input asp-for="LocalRepo" class="form-control" />
<span asp-validation-for="LocalRepo" class="text-danger" />
<input asp-for="Repository" class="form-control" />
<span asp-validation-for="Repository" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="Name" class="control-label col-md-2">Name</label>
<div class="col-md-10">
<select asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="OwnerId" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="OwnerId" class="form-control" />
<span asp-validation-for="OwnerId" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="PaymentId" class="control-label col-md-2">PaymentId</label>
<div class="col-md-10">
<select asp-for="PaymentId" class="form-control" />
<span asp-validation-for="PaymentId" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="PerformerId" class="control-label col-md-2">PerformerId</label>
<div class="col-md-10">
<select asp-for="PerformerId" class="form-control" />
<span asp-validation-for="PerformerId" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Previsional" class="col-md-2 control-label"></label>
<label asp-for="Previsional" class="col-md-2 control-label">Prévisionel</label>
<div class="col-md-10">
<input asp-for="Previsional" class="form-control" />
<span asp-validation-for="Previsional" class="text-danger" />
<span asp-validation-for="Previsional" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
@ -105,13 +48,6 @@
</div>
</div>
</div>
<div class="form-group">
<label asp-for="RejectedAt" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="RejectedAt" class="form-control" />
<span asp-validation-for="RejectedAt" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Status" class="col-md-2 control-label"></label>
<div class="col-md-10">
@ -119,27 +55,6 @@
<span asp-validation-for="Status" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="UserCreated" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserCreated" class="form-control" />
<span asp-validation-for="UserCreated" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="UserModified" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserModified" class="form-control" />
<span asp-validation-for="UserModified" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="ValidationDate" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="ValidationDate" class="form-control" />
<span asp-validation-for="ValidationDate" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Version" class="col-md-2 control-label"></label>
<div class="col-md-10">

View File

@ -11,6 +11,9 @@
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Consent)
</th>
@ -55,6 +58,9 @@
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Consent)
</td>