Re-fabrication
This commit is contained in:
@ -7,12 +7,11 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace OAuth.AspNet.Tokens
|
||||
{
|
||||
[Obsolete]
|
||||
public class TicketDataFormatTokenValidator : ISecurityTokenValidator
|
||||
{
|
||||
#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)
|
||||
{
|
||||
|
@ -1,10 +1,17 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Yavsc.ViewModels.UserFiles;
|
||||
|
||||
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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return true;
|
||||
@ -36,6 +43,16 @@ namespace Yavsc.Abstract.FileSystem
|
||||
}
|
||||
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
|
||||
|
@ -1,3 +1,6 @@
|
||||
using System.Resources;
|
||||
using Yavsc.Resources;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
@ -8,7 +11,7 @@ namespace Yavsc.Attributes.Validation
|
||||
|
||||
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 ()
|
||||
{
|
||||
this.ErrorMessage = Startup.GlobalLocalizer["RequiredField"];
|
||||
this.ErrorMessage = ResourcesHelpers.DefaultResourceManager.GetString("RequiredField");
|
||||
|
||||
}
|
||||
public override bool IsValid(object value) {
|
@ -6,7 +6,7 @@ namespace Yavsc.Attributes.Validation
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>string.Format(
|
||||
Startup.GlobalLocalizer["BadStringLength"],
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("BadStringLength"),
|
||||
maxLen))
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
@ -43,12 +43,12 @@ namespace Yavsc.Attributes.Validation
|
||||
if (MinLen<0) {
|
||||
// DetailledMaxStringLength
|
||||
return string.Format(
|
||||
Startup.GlobalLocalizer["DetailledMaxStringLength"],
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("DetailledMaxStringLength"),
|
||||
maxLen,
|
||||
excedent);
|
||||
} else
|
||||
return string.Format(
|
||||
Startup.GlobalLocalizer["DetailledMinMaxStringLength"],
|
||||
ResourcesHelpers.DefaultResourceManager.GetString("DetailledMinMaxStringLength"),
|
||||
MinLen,
|
||||
maxLen,
|
||||
manquant,
|
@ -4,7 +4,7 @@ namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Startup.GlobalLocalizer[name];
|
||||
return ResourcesHelpers.DefaultResourceManager.GetString(name);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Yavsc.Abstract.FileSystem;
|
||||
using Yavsc.Billing;
|
||||
using Yavsc.Models.Billing;
|
||||
|
||||
@ -24,7 +25,7 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
var suffix = bill.GetIsAcquitted() ? "-ack":null;
|
||||
var filename = bill.GetFileBaseName()+".pdf";
|
||||
return new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||
return new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
|
||||
}
|
||||
}
|
||||
}
|
11
Yavsc.Server/Helpers/DbHelpers.cs
Normal file
11
Yavsc.Server/Helpers/DbHelpers.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
7
Yavsc.Server/Helpers/FileSystemHelpers.cs
Normal file
7
Yavsc.Server/Helpers/FileSystemHelpers.cs
Normal file
@ -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 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)
|
||||
{
|
||||
@ -85,7 +78,7 @@ namespace Yavsc.Helpers
|
||||
);
|
||||
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))
|
||||
throw new InvalidOperationException("No Google login");
|
||||
@ -94,7 +87,7 @@ namespace Yavsc.Helpers
|
||||
// token != null
|
||||
var c = SystemClock.Default;
|
||||
if (token.IsExpired(c)) {
|
||||
token = await RefreshToken(token);
|
||||
token = await RefreshToken(googleAuthSettings, token);
|
||||
}
|
||||
return new UserCredential(flow, googleUserLoginKey, token);
|
||||
}
|
||||
@ -114,15 +107,15 @@ namespace Yavsc.Helpers
|
||||
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";
|
||||
// refresh_token client_id client_secret grant_type=refresh_token
|
||||
try {
|
||||
using (var m = new SimpleJsonPostMethod(ep)) {
|
||||
return await m.Invoke<TokenResponse>(
|
||||
new { refresh_token= oldResponse.RefreshToken, client_id=Startup.GoogleSettings.ClientId,
|
||||
client_secret=Startup.GoogleSettings.ClientSecret,
|
||||
new { refresh_token= oldResponse.RefreshToken, client_id=settings.ClientId,
|
||||
client_secret=settings.ClientSecret,
|
||||
grant_type="refresh_token" }
|
||||
);
|
||||
}
|
@ -131,6 +131,8 @@ namespace Yavsc.Server.Helpers
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
14
Yavsc.Server/Helpers/ResourcesHelpers.cs
Normal file
14
Yavsc.Server/Helpers/ResourcesHelpers.cs
Normal file
@ -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
Reference in New Issue
Block a user