Paul Schneider 8 years ago
commit 8c2feece06
12 changed files with 4460 additions and 2373 deletions

@ -47,7 +47,7 @@ namespace Yavsc.Helpers
request.SendChunked = true; request.SendChunked = true;
request.TransferEncoding = "UTF-8"; request.TransferEncoding = "UTF-8";
if (authorizationHeader!=null) if (authorizationHeader!=null)
request.Headers.Add(authorizationHeader); request.Headers["Authorization"]=authorizationHeader;
} }
public void Dispose() public void Dispose()

@ -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)) if (_context.GCMDevices.Any(d => d.DeviceId == declaration.DeviceId))
{ {
var alreadyRegisteredDevice = _context.GCMDevices.FirstOrDefault(d => d.DeviceId == declaration.DeviceId); var alreadyRegisteredDevice = _context.GCMDevices.FirstOrDefault(d => d.DeviceId == declaration.DeviceId);
if (alreadyRegisteredDevice.DeviceOwnerId != uid) // Override an exiting owner
{ alreadyRegisteredDevice.DeviceOwnerId = uid;
return new BadRequestObjectResult(new { error = $"Device owned by someone else {declaration.DeviceId}" });
}
alreadyRegisteredDevice.GCMRegistrationId = declaration.GCMRegistrationId; alreadyRegisteredDevice.GCMRegistrationId = declaration.GCMRegistrationId;
alreadyRegisteredDevice.Model = declaration.Model; alreadyRegisteredDevice.Model = declaration.Model;
alreadyRegisteredDevice.Platform = declaration.Platform; 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 // 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 // Send an email with this link
//var code = await _userManager.GeneratePasswordResetTokenAsync(user); var code = await _userManager.GeneratePasswordResetTokenAsync(user);
//var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
//await _emailSender.SendEmailAsync(model.Email, "Reset Password", await _emailSender.SendEmailAsync(_siteSettings,_smtpSettings,model.Email, "Reset Password",
// "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>"); "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
//return View("ForgotPasswordConfirmation"); return View("ForgotPasswordConfirmation");
} }
// If we got this far, something failed, redisplay form // If we got this far, something failed, redisplay form

@ -148,11 +148,13 @@ namespace Yavsc.Controllers
if (pro.AcceptNotifications if (pro.AcceptNotifications
&& pro.AcceptPublicContact) && pro.AcceptPublicContact)
{ {
if (pro.Performer.Devices.Count > 0) if (pro.Performer.Devices.Count > 0) {
grep = await _GCMSender.NotifyAsync(_googleSettings, var regids = command.PerformerProfile.Performer
command.PerformerProfile.Performer.Devices.Select(d => d.GCMRegistrationId), .Devices.Select(d => d.GCMRegistrationId);
yaev 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 // TODO setup a profile choice to allow notifications
// both on mailbox and mobile // both on mailbox and mobile
// if (grep==null || grep.success<=0 || grep.failure>0) // if (grep==null || grep.success<=0 || grep.failure>0)

@ -11,7 +11,7 @@ namespace Yavsc.Helpers
{ {
var yaev = new YaEvent 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) ? Comment = (query.Previsional != null) ?
SR["Deposit"] + string.Format(": {0:00}", SR["Deposit"] + string.Format(": {0:00}",
query.Previsional) : SR["No deposit."], query.Previsional) : SR["No deposit."],

@ -44,45 +44,55 @@ namespace Yavsc.Helpers
/// <returns>The event.</returns> /// <returns>The event.</returns>
/// <param name="evpub">Evpub.</param> /// <param name="evpub">Evpub.</param>
public static async Task<MessageWithPayloadResponse> NotifyEvent 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 // ASSERT ModelState.IsValid implies evpub.Circles != null
//send a MessageWithPayload<YaEvent> to circle members //send a MessageWithPayload<YaEvent> to circle members
// receive MessageWithPayloadResponse // receive MessageWithPayloadResponse
// "https://gcm-http.googleapis.com/gcm/send" // "https://gcm-http.googleapis.com/gcm/send"
var regids = new List<string> (); var regids = new List<string>();
foreach (var c in evpub.Circles) 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)); {
regids.AddRange(u.Member.Devices.Select(d => d.GCMRegistrationId));
} }
if (regids.Count>0) return null; if (regids.Count > 0) return null;
var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey); request.Headers.Authorization = new AuthenticationHeaderValue("key", googleSettings.ApiKey);
var msg = new MessageWithPayload<YaEvent> () { var msg = new MessageWithPayload<YaEvent>()
{
notification = new Notification() { title = evpub.Title, body = evpub.Description, icon = "event" }, 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 response = await channel.SendAsync(request);
var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
return payload.Value<MessageWithPayloadResponse>(); return payload.Value<MessageWithPayloadResponse>();
} }
public static async Task<MessageWithPayloadResponse> NotifyEvent<Event> public static MessageWithPayloadResponse NotifyEvent<Event>
(this HttpClient channel, GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev) (this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
where Event : YaEvent where Event : YaEvent
{ {
if (regids == null) var msg = new MessageWithPayload<Event>()
throw new NotImplementedException ("Notify & No GCM reg ids"); {
var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); notification = new Notification()
request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey); {
var msg = new MessageWithPayload<Event> () { title = ev.Title,
notification = new Notification() { title = ev.Title, body = ev.Description + ev.Comment == null ?
body = ev.Description + ev.Comment==null? "" : "(" + ev.Comment + ")",
"":"("+ev.Comment+")", icon = "icon" }, icon = "icon"
data = ev, registration_ids = regids.ToArray() }; },
data = ev,
registration_ids = regids.ToArray()
};
var response = await channel.SendAsync(request); if (regids == null)
var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); throw new NotImplementedException("Notify & No GCM reg ids");
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) public static async Task<UserCredential> GetCredentialForGoogleApiAsync(this UserManager<ApplicationUser> userManager, ApplicationDbContext context, string uid)
{ {

@ -2,13 +2,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using MailKit.Net.Smtp; using MailKit.Net.Smtp;
using MimeKit; using MimeKit;
using System.IO;
using MailKit.Security; using MailKit.Security;
using System; using System;
using Yavsc.Models.Messaging; using Yavsc.Models.Messaging;
using Yavsc.Helpers; using Yavsc.Helpers;
using System.Net;
using System.Net.Http;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Yavsc.Models; using Yavsc.Models;
using Yavsc.Models.Google.Messaging; using Yavsc.Models.Google.Messaging;
@ -33,37 +30,17 @@ namespace Yavsc.Services
public async Task<MessageWithPayloadResponse> public async Task<MessageWithPayloadResponse>
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev) NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
{ {
MessageWithPayloadResponse response; MessageWithPayloadResponse response = null;
try await Task.Run(()=>{
{ response = googleSettings.NotifyEvent(registrationIds, ev);
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);
}
return response; return response;
} }
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message) public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
{ {
try { try
{
MimeMessage msg = new MimeMessage(); MimeMessage msg = new MimeMessage();
msg.From.Add(new MailboxAddress( msg.From.Add(new MailboxAddress(
siteSettings.Owner.Name, siteSettings.Owner.Name,
@ -83,7 +60,8 @@ namespace Yavsc.Services
sc.Send(msg); sc.Send(msg);
} }
} }
catch (Exception) { catch (Exception)
{
return Task.FromResult(false); return Task.FromResult(false);
} }
return Task.FromResult(true); return Task.FromResult(true);

@ -233,7 +233,7 @@ namespace Yavsc
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
loggerFactory.MinimumLevel = LogLevel.Debug; loggerFactory.MinimumLevel = LogLevel.Verbose;
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseRuntimeInfoPage(); app.UseRuntimeInfoPage();
var epo = new ErrorPageOptions(); var epo = new ErrorPageOptions();

@ -4,11 +4,8 @@
} }
<h2>@ViewData["Title"].</h2> <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> <h4>Enter your email.</h4>
<hr /> <hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div> <div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
@ -24,7 +21,7 @@
<button type="submit" class="btn btn-default">Submit</button> <button type="submit" class="btn btn-default">Submit</button>
</div> </div>
</div> </div>
</form>*@ </form>
@section Scripts { @section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }

@ -96,7 +96,6 @@
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516", "Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
"Microsoft.AspNet.Web.Optimization": "1.1.3", "Microsoft.AspNet.Web.Optimization": "1.1.3",
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final", "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.Options": "0.0.1-alpha",
"Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final", "Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final",
"Microsoft.AspNet.DataProtection": "1.0.0-rc1-final", "Microsoft.AspNet.DataProtection": "1.0.0-rc1-final",

File diff suppressed because it is too large Load Diff
Loading…