refacts
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Models.OAuth
|
||||
namespace Yavsc.Models.Auth
|
||||
{
|
||||
/// <summary>
|
||||
/// OffLine OAuth2 Token
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
using Yavsc.Models.OAuth;
|
||||
|
||||
namespace Yavsc.Models.Auth {
|
||||
|
||||
public class UserCredential {
|
||||
@ -19,4 +17,4 @@ namespace Yavsc.Models.Auth {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -89,10 +89,12 @@ namespace Yavsc.Controllers
|
||||
paymentOk = true;
|
||||
command.ValidationDate = DateTime.Now;
|
||||
}
|
||||
else _logger.LogError
|
||||
("This Command were yet validated, and is now paied one more ...");
|
||||
}
|
||||
await _context.SaveChangesAsync(User.GetUserId());
|
||||
SetViewBagPaymentUrls(id);
|
||||
if (command.PerformerProfile.AcceptPublicContact && paymentOk)
|
||||
if (paymentOk)
|
||||
{
|
||||
MessageWithPayloadResponse grep = null;
|
||||
var yaev = command.CreatePaymentEvent(paymentInfo, _localizer);
|
||||
@ -118,10 +120,6 @@ namespace Yavsc.Controllers
|
||||
yaev.CreateBody()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO if (AcceptProContact) try & find a bookmaker to send him this query
|
||||
}
|
||||
|
||||
ViewData["Notify"] = new List<Notification> {
|
||||
new Notification {
|
||||
|
@ -47,9 +47,6 @@ namespace Yavsc.Helpers
|
||||
/// </summary>
|
||||
public static class GoogleHelpers
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static async Task<GoogleCredential> GetCredentialForApi(IEnumerable<string> scopes)
|
||||
{
|
||||
GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();
|
60
Yavsc/Helpers/GoogleStoreHelpers.cs
Normal file
60
Yavsc/Helpers/GoogleStoreHelpers.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
using Microsoft.Data.Entity;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Yavsc.Helpers.Google {
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Auth;
|
||||
public static class GoogleStoreHelper {
|
||||
|
||||
public static Task<OAuth2Tokens> GetTokensAsync(this ApplicationDbContext context, string googleUserId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(googleUserId))
|
||||
{
|
||||
throw new ArgumentException("email MUST have a value");
|
||||
}
|
||||
|
||||
var item = context.Tokens.FirstOrDefault(x => x.UserId == googleUserId);
|
||||
// TODO Refresh token
|
||||
|
||||
return Task.FromResult(item);
|
||||
}
|
||||
|
||||
public static Task StoreTokenAsync(this ApplicationDbContext context, string googleUserId, JObject response, string accessToken,
|
||||
string tokenType, string refreshToken, string expiresIn
|
||||
)
|
||||
{
|
||||
if (string.IsNullOrEmpty(googleUserId))
|
||||
{
|
||||
throw new ArgumentException("googleUserId MUST have a value");
|
||||
}
|
||||
|
||||
var item = context.Tokens.SingleOrDefaultAsync(x => x.UserId == googleUserId).Result;
|
||||
if (item == null)
|
||||
{
|
||||
context.Tokens.Add(new OAuth2Tokens
|
||||
{
|
||||
TokenType = "Bearer",
|
||||
AccessToken = accessToken,
|
||||
RefreshToken = refreshToken,
|
||||
Expiration = DateTime.Now.AddSeconds(int.Parse(expiresIn)),
|
||||
UserId = googleUserId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
item.AccessToken = accessToken;
|
||||
item.Expiration = DateTime.Now.AddMinutes(int.Parse(expiresIn));
|
||||
if (refreshToken != null)
|
||||
item.RefreshToken = refreshToken;
|
||||
context.Tokens.Update(item);
|
||||
}
|
||||
context.SaveChanges(googleUserId);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -64,7 +64,7 @@ namespace Yavsc.Models
|
||||
builder.Entity<Models.Cratie.Option>().HasKey(o => new { o.Code, o.CodeScrutin });
|
||||
builder.Entity<Notification>().Property(n => n.icon).HasDefaultValue("exclam");
|
||||
builder.Entity<ChatRoomPresence>().HasKey(p => new { room = p.ChannelName, user = p.ChatUserConnectionId });
|
||||
|
||||
|
||||
foreach (var et in builder.Model.GetEntityTypes())
|
||||
{
|
||||
if (et.ClrType.GetInterface("IBaseTrackedEntity") != null)
|
||||
@ -137,56 +137,6 @@ namespace Yavsc.Models
|
||||
public DbSet<Service> Services { get; set; }
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
|
||||
public Task<OAuth2Tokens> GetTokensAsync(string googleUserId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(googleUserId))
|
||||
{
|
||||
throw new ArgumentException("email MUST have a value");
|
||||
}
|
||||
|
||||
using (var context = new ApplicationDbContext())
|
||||
{
|
||||
var item = this.Tokens.FirstOrDefault(x => x.UserId == googleUserId);
|
||||
// TODO Refresh token
|
||||
|
||||
return Task.FromResult(item);
|
||||
}
|
||||
}
|
||||
|
||||
public Task StoreTokenAsync(string googleUserId, JObject response, string accessToken,
|
||||
string tokenType, string refreshToken, string expiresIn
|
||||
)
|
||||
{
|
||||
if (string.IsNullOrEmpty(googleUserId))
|
||||
{
|
||||
throw new ArgumentException("googleUserId MUST have a value");
|
||||
}
|
||||
|
||||
var item = this.Tokens.SingleOrDefaultAsync(x => x.UserId == googleUserId).Result;
|
||||
if (item == null)
|
||||
{
|
||||
Tokens.Add(new OAuth2Tokens
|
||||
{
|
||||
TokenType = "Bearer", // FIXME why value.TokenType would be null?
|
||||
AccessToken = accessToken,
|
||||
RefreshToken = refreshToken,
|
||||
Expiration = DateTime.Now.AddSeconds(int.Parse(expiresIn)),
|
||||
UserId = googleUserId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
item.AccessToken = accessToken;
|
||||
item.Expiration = DateTime.Now.AddMinutes(int.Parse(expiresIn));
|
||||
if (refreshToken != null)
|
||||
item.RefreshToken = refreshToken;
|
||||
Tokens.Update(item);
|
||||
}
|
||||
SaveChanges(googleUserId);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
Client FindApplication(string clientId)
|
||||
{
|
||||
return Applications.FirstOrDefault(
|
||||
|
@ -24,6 +24,8 @@ namespace Yavsc
|
||||
using Auth;
|
||||
using Extensions;
|
||||
using Models;
|
||||
using Helpers.Google;
|
||||
|
||||
public partial class Startup
|
||||
{
|
||||
public static CookieAuthenticationOptions ExternalCookieAppOptions { get; private set; }
|
||||
|
@ -280,9 +280,6 @@
|
||||
<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png" alt="PayPal Acceptance">
|
||||
|
||||
<input type="submit" class="btn btn-success btn-submit" value="@SR["Validez ce choix, et prendre rendez-vous"] avec @Model.PerformerProfile.Performer.UserName"/>
|
||||
<environment names="Development">
|
||||
<input type="submit" class="btn btn-success btn-submit" value="@SR["Validez ce choix, et prendre rendez-vous"] avec @Model.PerformerProfile.Performer.UserName [DEV+Location+Date]"/>
|
||||
</environment>
|
||||
</div>
|
||||
@Html.HiddenFor(model=>model.Location.Latitude)
|
||||
@Html.HiddenFor(model=>model.Location.Longitude)
|
||||
|
Reference in New Issue
Block a user