Merge branch 'vnext' of https://github.com/pazof/yavsc.git
This commit is contained in:
commit
fea0240fc0
12 changed files with 4460 additions and 2373 deletions
|
|
@ -47,7 +47,7 @@ namespace Yavsc.Helpers
|
|||
request.SendChunked = true;
|
||||
request.TransferEncoding = "UTF-8";
|
||||
if (authorizationHeader!=null)
|
||||
request.Headers.Add(authorizationHeader);
|
||||
request.Headers["Authorization"]=authorizationHeader;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
8
Yavsc.Api/dist.sh
Executable file
8
Yavsc.Api/dist.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
dnu pack
|
||||
cp -a bin/Debug/*.nupkg ~/Nupkgs
|
||||
(cd ../Yavsc && dnu install Yavsc.Api)
|
||||
(cd ../testOauthClient && dnu install Yavsc.Api)
|
||||
|
||||
|
||||
|
|
@ -35,10 +35,8 @@ public class GCMController : Controller
|
|||
if (_context.GCMDevices.Any(d => d.DeviceId == declaration.DeviceId))
|
||||
{
|
||||
var alreadyRegisteredDevice = _context.GCMDevices.FirstOrDefault(d => d.DeviceId == declaration.DeviceId);
|
||||
if (alreadyRegisteredDevice.DeviceOwnerId != uid)
|
||||
{
|
||||
return new BadRequestObjectResult(new { error = $"Device owned by someone else {declaration.DeviceId}" });
|
||||
}
|
||||
// Override an exiting owner
|
||||
alreadyRegisteredDevice.DeviceOwnerId = uid;
|
||||
alreadyRegisteredDevice.GCMRegistrationId = declaration.GCMRegistrationId;
|
||||
alreadyRegisteredDevice.Model = declaration.Model;
|
||||
alreadyRegisteredDevice.Platform = declaration.Platform;
|
||||
|
|
|
|||
|
|
@ -334,11 +334,11 @@ namespace Yavsc.Controllers
|
|||
|
||||
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
|
||||
// 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(model.Email, "Reset Password",
|
||||
// "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
|
||||
//return View("ForgotPasswordConfirmation");
|
||||
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>");
|
||||
return View("ForgotPasswordConfirmation");
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
|
|
|
|||
|
|
@ -148,11 +148,13 @@ namespace Yavsc.Controllers
|
|||
if (pro.AcceptNotifications
|
||||
&& pro.AcceptPublicContact)
|
||||
{
|
||||
if (pro.Performer.Devices.Count > 0)
|
||||
grep = await _GCMSender.NotifyAsync(_googleSettings,
|
||||
command.PerformerProfile.Performer.Devices.Select(d => d.GCMRegistrationId),
|
||||
yaev
|
||||
);
|
||||
if (pro.Performer.Devices.Count > 0) {
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Yavsc.Helpers
|
|||
{
|
||||
var yaev = new YaEvent
|
||||
{
|
||||
Title = query.Client.UserName + SR["is asking you for a date"],
|
||||
Title = query.Client.UserName + " "+ SR["is asking you for a date"]+".",
|
||||
Comment = (query.Previsional != null) ?
|
||||
SR["Deposit"] + string.Format(": {0:00}",
|
||||
query.Previsional) : SR["No deposit."],
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ namespace Yavsc.Helpers
|
|||
/// <returns>The event.</returns>
|
||||
/// <param name="evpub">Evpub.</param>
|
||||
public static async Task<MessageWithPayloadResponse> NotifyEvent
|
||||
(this HttpClient channel, GoogleAuthSettings googleSettings, CircleEvent evpub) {
|
||||
(this HttpClient channel, GoogleAuthSettings googleSettings, CircleEvent evpub)
|
||||
{
|
||||
// ASSERT ModelState.IsValid implies evpub.Circles != null
|
||||
//send a MessageWithPayload<YaEvent> to circle members
|
||||
// receive MessageWithPayloadResponse
|
||||
|
|
@ -52,37 +53,46 @@ namespace Yavsc.Helpers
|
|||
|
||||
var regids = new List<string>();
|
||||
foreach (var c in evpub.Circles)
|
||||
foreach (var u in c.Members) {
|
||||
foreach (var u in c.Members)
|
||||
{
|
||||
regids.AddRange(u.Member.Devices.Select(d => d.GCMRegistrationId));
|
||||
}
|
||||
if (regids.Count > 0) return null;
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl);
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey);
|
||||
var msg = new MessageWithPayload<YaEvent> () {
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("key", googleSettings.ApiKey);
|
||||
var msg = new MessageWithPayload<YaEvent>()
|
||||
{
|
||||
notification = new Notification() { title = evpub.Title, body = evpub.Description, icon = "event" },
|
||||
data = evpub , registration_ids = regids.ToArray() };
|
||||
data = evpub,
|
||||
registration_ids = regids.ToArray()
|
||||
};
|
||||
var response = await channel.SendAsync(request);
|
||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
return payload.Value<MessageWithPayloadResponse>();
|
||||
}
|
||||
|
||||
public static async Task<MessageWithPayloadResponse> NotifyEvent<Event>
|
||||
(this HttpClient channel, GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
|
||||
public static MessageWithPayloadResponse NotifyEvent<Event>
|
||||
(this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
|
||||
where Event : YaEvent
|
||||
{
|
||||
var msg = new MessageWithPayload<Event>()
|
||||
{
|
||||
notification = new Notification()
|
||||
{
|
||||
title = ev.Title,
|
||||
body = ev.Description + ev.Comment == null ?
|
||||
"" : "(" + ev.Comment + ")",
|
||||
icon = "icon"
|
||||
},
|
||||
data = ev,
|
||||
registration_ids = regids.ToArray()
|
||||
};
|
||||
|
||||
if (regids == null)
|
||||
throw new NotImplementedException("Notify & No GCM reg ids");
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl);
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey);
|
||||
var msg = new MessageWithPayload<Event> () {
|
||||
notification = new Notification() { title = ev.Title,
|
||||
body = ev.Description + ev.Comment==null?
|
||||
"":"("+ev.Comment+")", icon = "icon" },
|
||||
data = ev, registration_ids = regids.ToArray() };
|
||||
|
||||
var response = await channel.SendAsync(request);
|
||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
return payload.Value<MessageWithPayloadResponse>();
|
||||
using (var m = new SimpleJsonPostMethod("https://gcm-http.googleapis.com/gcm/send",$"key={googleSettings.ApiKey}")) {
|
||||
return m.Invoke<MessageWithPayloadResponse>(msg);
|
||||
}
|
||||
}
|
||||
public static async Task<UserCredential> GetCredentialForGoogleApiAsync(this UserManager<ApplicationUser> userManager, ApplicationDbContext context, string uid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@
|
|||
using System.Threading.Tasks;
|
||||
using MailKit.Net.Smtp;
|
||||
using MimeKit;
|
||||
using System.IO;
|
||||
using MailKit.Security;
|
||||
using System;
|
||||
using Yavsc.Models.Messaging;
|
||||
using Yavsc.Helpers;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Google.Messaging;
|
||||
|
|
@ -33,37 +30,17 @@ namespace Yavsc.Services
|
|||
public async Task<MessageWithPayloadResponse>
|
||||
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
|
||||
{
|
||||
MessageWithPayloadResponse response;
|
||||
try
|
||||
{
|
||||
using (var web = new HttpClient())
|
||||
{
|
||||
response = await web.NotifyEvent(googleSettings, registrationIds, ev);
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
string errorMsgGCM;
|
||||
using (var respstream = ex.Response.GetResponseStream())
|
||||
{
|
||||
using (StreamReader rdr = new StreamReader(respstream))
|
||||
{
|
||||
errorMsgGCM = rdr.ReadToEnd();
|
||||
rdr.Close();
|
||||
}
|
||||
respstream.Close();
|
||||
}
|
||||
if (errorMsgGCM == null)
|
||||
throw;
|
||||
|
||||
throw new Exception(errorMsgGCM, ex);
|
||||
}
|
||||
MessageWithPayloadResponse response = null;
|
||||
await Task.Run(()=>{
|
||||
response = googleSettings.NotifyEvent(registrationIds, ev);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
MimeMessage msg = new MimeMessage();
|
||||
msg.From.Add(new MailboxAddress(
|
||||
siteSettings.Owner.Name,
|
||||
|
|
@ -83,7 +60,8 @@ namespace Yavsc.Services
|
|||
sc.Send(msg);
|
||||
}
|
||||
}
|
||||
catch (Exception) {
|
||||
catch (Exception)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
return Task.FromResult(true);
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ namespace Yavsc
|
|||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
loggerFactory.MinimumLevel = LogLevel.Debug;
|
||||
loggerFactory.MinimumLevel = LogLevel.Verbose;
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseRuntimeInfoPage();
|
||||
var epo = new ErrorPageOptions();
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
}
|
||||
|
||||
<h2>@ViewData["Title"].</h2>
|
||||
<p>
|
||||
For more information on how to enable reset password please see this <a href="http://go.microsoft.com/fwlink/?LinkID=532713">article</a>.
|
||||
</p>
|
||||
|
||||
@*<form asp-controller="Account" asp-action="ForgotPassword" method="post" class="form-horizontal" role="form">
|
||||
<form asp-controller="Account" asp-action="ForgotPassword" method="post" class="form-horizontal" role="form">
|
||||
<h4>Enter your email.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
|
||||
|
|
@ -24,7 +21,7 @@
|
|||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>*@
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@
|
|||
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
|
||||
"Microsoft.AspNet.Web.Optimization": "1.1.3",
|
||||
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNetCore.Authentication.OAuth": "0.0.1-alpha",
|
||||
"Microsoft.Extensions.Options": "0.0.1-alpha",
|
||||
"Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.DataProtection": "1.0.0-rc1-final",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue