Re-fabrication

vnext
Paul Schneider 7 years ago
parent e00bcbe275
commit 8fbe56c67e
499 changed files with 7574 additions and 12530 deletions

@ -7,12 +7,11 @@ using System.Text.RegularExpressions;
namespace OAuth.AspNet.Tokens namespace OAuth.AspNet.Tokens
{ {
[Obsolete]
public class TicketDataFormatTokenValidator : ISecurityTokenValidator public class TicketDataFormatTokenValidator : ISecurityTokenValidator
{ {
#region Constructors #region Constructors
public TicketDataFormatTokenValidator() : this(null, "AccessToken", new string [] { "v1" }) { } public TicketDataFormatTokenValidator(IDataProtectionProvider dataProtectionProvider, string purpose = "AccessToken") : this(dataProtectionProvider, purpose , new string [] { "v1" }) { }
public TicketDataFormatTokenValidator(IDataProtectionProvider dataProtectionProvider, string purpose, string [] subPurposes) public TicketDataFormatTokenValidator(IDataProtectionProvider dataProtectionProvider, string purpose, string [] subPurposes)
{ {

@ -1,10 +1,17 @@
using System.IO;
using System.Linq; using System.Linq;
using System.Security.Claims;
using System.Text; using System.Text;
using Yavsc.ViewModels.UserFiles;
namespace Yavsc.Abstract.FileSystem namespace Yavsc.Abstract.FileSystem
{ {
public static class FileSystemHelpers public static class AbstractFileSystemHelpers
{ {
public static string UserBillsDirName { set; get; }
public static string UserFilesDirName { set; get; }
public static bool IsValidYavscPath(this string path) public static bool IsValidYavscPath(this string path)
{ {
if (string.IsNullOrEmpty(path)) return true; if (string.IsNullOrEmpty(path)) return true;
@ -36,6 +43,16 @@ namespace Yavsc.Abstract.FileSystem
} }
return sb.ToString(); return sb.ToString();
} }
public static UserDirectoryInfo GetUserFiles(this ClaimsPrincipal user, string subdir)
{
UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, user.Identity.Name, subdir);
return di;
}
} }
public static class FileSystemConstants public static class FileSystemConstants

@ -1,3 +1,6 @@
using System.Resources;
using Yavsc.Resources;
namespace Yavsc.Attributes.Validation namespace Yavsc.Attributes.Validation
{ {
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute { public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
@ -8,7 +11,7 @@ namespace Yavsc.Attributes.Validation
public override string FormatErrorMessage(string name) public override string FormatErrorMessage(string name)
{ {
return Startup.GlobalLocalizer[this.ErrorMessageResourceName]; return ResourcesHelpers.DefaultResourceManager.GetString(this.ErrorMessageResourceName);
} }
} }
} }

@ -16,7 +16,7 @@ namespace Yavsc.Attributes.Validation
} }
public YaRequiredAttribute () public YaRequiredAttribute ()
{ {
this.ErrorMessage = Startup.GlobalLocalizer["RequiredField"]; this.ErrorMessage = ResourcesHelpers.DefaultResourceManager.GetString("RequiredField");
} }
public override bool IsValid(object value) { public override bool IsValid(object value) {

@ -6,7 +6,7 @@ namespace Yavsc.Attributes.Validation
private long maxLen; private long maxLen;
public YaStringLength(long maxLen) : base( public YaStringLength(long maxLen) : base(
()=>string.Format( ()=>string.Format(
Startup.GlobalLocalizer["BadStringLength"], ResourcesHelpers.DefaultResourceManager.GetString("BadStringLength"),
maxLen)) maxLen))
{ {
this.maxLen = maxLen; this.maxLen = maxLen;
@ -43,12 +43,12 @@ namespace Yavsc.Attributes.Validation
if (MinLen<0) { if (MinLen<0) {
// DetailledMaxStringLength // DetailledMaxStringLength
return string.Format( return string.Format(
Startup.GlobalLocalizer["DetailledMaxStringLength"], ResourcesHelpers.DefaultResourceManager.GetString("DetailledMaxStringLength"),
maxLen, maxLen,
excedent); excedent);
} else } else
return string.Format( return string.Format(
Startup.GlobalLocalizer["DetailledMinMaxStringLength"], ResourcesHelpers.DefaultResourceManager.GetString("DetailledMinMaxStringLength"),
MinLen, MinLen,
maxLen, maxLen,
manquant, manquant,

@ -4,7 +4,7 @@ namespace Yavsc.Attributes.Validation
{ {
public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{ {
public YaValidationAttribute() : base(()=> Startup.GlobalLocalizer["validationError"]) public YaValidationAttribute() : base(()=> ResourcesHelpers.DefaultResourceManager.GetString("validationError"))
{ {
} }
@ -16,7 +16,7 @@ namespace Yavsc.Attributes.Validation
public override string FormatErrorMessage(string name) public override string FormatErrorMessage(string name)
{ {
return Startup.GlobalLocalizer[name]; return ResourcesHelpers.DefaultResourceManager.GetString(name);
} }
} }
} }

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Yavsc.Abstract.FileSystem;
using Yavsc.Billing; using Yavsc.Billing;
using Yavsc.Models.Billing; using Yavsc.Models.Billing;
@ -24,7 +25,7 @@ namespace Yavsc.Helpers
{ {
var suffix = bill.GetIsAcquitted() ? "-ack":null; var suffix = bill.GetIsAcquitted() ? "-ack":null;
var filename = bill.GetFileBaseName()+".pdf"; var filename = bill.GetFileBaseName()+".pdf";
return new FileInfo(Path.Combine(Startup.UserBillsDirName, filename)); return new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
} }
} }
} }

@ -0,0 +1,11 @@
namespace Yavsc.Server.Helpers
{
public static class DbHelpers
{
static string _connectionString = null;
public static string ConnectionString {
get { return _connectionString = null; }
set { _connectionString = value; }
}
}
}

@ -0,0 +1,7 @@
namespace Yavsc.Server.Helpers
{
public static class FileSystemHelpers
{
}
}

@ -48,14 +48,7 @@ namespace Yavsc.Helpers
public static class GoogleHelpers public static class GoogleHelpers
{ {
public static ServiceAccountCredential OupsGetCredentialForApi(IEnumerable<string> scopes)
{
var initializer = new ServiceAccountCredential.Initializer(Startup.GoogleSettings.Account.client_email);
initializer = initializer.FromPrivateKey(Startup.GoogleSettings.Account.private_key);
initializer.Scopes = scopes;
var credential = new ServiceAccountCredential(initializer);
return credential;
}
public static async Task<GoogleCredential> GetCredentialForApi(IEnumerable<string> scopes) public static async Task<GoogleCredential> GetCredentialForApi(IEnumerable<string> scopes)
{ {
@ -85,7 +78,7 @@ namespace Yavsc.Helpers
); );
return googleLogin; return googleLogin;
} }
public static async Task<UserCredential> GetGoogleCredential(IDataStore store, string googleUserLoginKey) public static async Task<UserCredential> GetGoogleCredential(GoogleAuthSettings googleAuthSettings, IDataStore store, string googleUserLoginKey)
{ {
if (string.IsNullOrEmpty(googleUserLoginKey)) if (string.IsNullOrEmpty(googleUserLoginKey))
throw new InvalidOperationException("No Google login"); throw new InvalidOperationException("No Google login");
@ -94,7 +87,7 @@ namespace Yavsc.Helpers
// token != null // token != null
var c = SystemClock.Default; var c = SystemClock.Default;
if (token.IsExpired(c)) { if (token.IsExpired(c)) {
token = await RefreshToken(token); token = await RefreshToken(googleAuthSettings, token);
} }
return new UserCredential(flow, googleUserLoginKey, token); return new UserCredential(flow, googleUserLoginKey, token);
} }
@ -114,15 +107,15 @@ namespace Yavsc.Helpers
return result.ToArray(); return result.ToArray();
} }
public static async Task<TokenResponse> RefreshToken(TokenResponse oldResponse) public static async Task<TokenResponse> RefreshToken(this GoogleAuthSettings settings, TokenResponse oldResponse)
{ {
string ep = " https://www.googleapis.com/oauth2/v4/token"; string ep = " https://www.googleapis.com/oauth2/v4/token";
// refresh_token client_id client_secret grant_type=refresh_token // refresh_token client_id client_secret grant_type=refresh_token
try { try {
using (var m = new SimpleJsonPostMethod(ep)) { using (var m = new SimpleJsonPostMethod(ep)) {
return await m.Invoke<TokenResponse>( return await m.Invoke<TokenResponse>(
new { refresh_token= oldResponse.RefreshToken, client_id=Startup.GoogleSettings.ClientId, new { refresh_token= oldResponse.RefreshToken, client_id=settings.ClientId,
client_secret=Startup.GoogleSettings.ClientSecret, client_secret=settings.ClientSecret,
grant_type="refresh_token" } grant_type="refresh_token" }
); );
} }

@ -131,6 +131,8 @@ namespace Yavsc.Server.Helpers
return null; return null;
} }
} }

@ -0,0 +1,14 @@
using System.Resources;
using Yavsc.Resources;
public static class ResourcesHelpers {
static ResourceManager _defaultResourceManager
= ResourceManager.CreateFileBasedResourceManager("Yavsc.Localization",".",typeof(YavscLocalisation));
public static ResourceManager DefaultResourceManager
{
get { return _defaultResourceManager; }
set { _defaultResourceManager = value; }
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…