simpler, better

This commit is contained in:
2018-06-10 20:40:11 +02:00
parent b14ad5242b
commit 78c89b32b4
27 changed files with 3323 additions and 50 deletions

View File

@ -14,12 +14,13 @@ namespace Yavsc
public partial class Startup
{
public static FileServerOptions UserFilesOptions { get; private set; }
public static FileServerOptions GitOptions { get; private set; }
public static FileServerOptions AvatarsOptions { get; set; }
public void ConfigureFileServerApp(IApplicationBuilder app,
SiteSettings siteSettings, IHostingEnvironment env, IAuthorizationService authorizationService)
{
var userFilesDirInfo = new DirectoryInfo( siteSettings.UserFiles.Blog );
var userFilesDirInfo = new DirectoryInfo( siteSettings.Blog );
AbstractFileSystemHelpers.UserFilesDirName = userFilesDirInfo.FullName;
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
@ -42,7 +43,7 @@ namespace Yavsc
var result = await authorizationService.AuthorizeAsync(context.Context.User, new ViewFileContext
{ UserName = uname, File = context.File, Path = path } , new ViewRequirement());
};
var avatarsDirInfo = new DirectoryInfo(Startup.SiteSetup.UserFiles.Avatars);
var avatarsDirInfo = new DirectoryInfo(Startup.SiteSetup.Avatars);
if (!avatarsDirInfo.Exists) avatarsDirInfo.Create();
AvatarsDirName = avatarsDirInfo.FullName;
@ -52,6 +53,14 @@ namespace Yavsc
RequestPath = new PathString(Constants.AvatarsPath),
EnableDirectoryBrowsing = env.IsDevelopment()
};
var gitdirinfo = new DirectoryInfo(Startup.SiteSetup.GitRepository);
GitOptions = new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(GitDirName),
RequestPath = new PathString(Constants.GitPath),
EnableDirectoryBrowsing = env.IsDevelopment()
};
app.UseFileServer(UserFilesOptions);

View File

@ -150,16 +150,21 @@ namespace Yavsc
var gcontext = context as GoogleOAuthCreatingTicketContext;
context.Identity.AddClaim(new Claim(YavscClaimTypes.GoogleUserId, gcontext.GoogleUserId));
var dbContext = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
await dbContext.StoreTokenAsync(gcontext.GoogleUserId, context.TokenResponse);
var store = serviceScope.ServiceProvider.GetService<IDataStore>();
await store.StoreAsync(gcontext.GoogleUserId, new TokenResponse {
await store.StoreAsync(gcontext.GoogleUserId, new TokenResponse {
AccessToken = gcontext.TokenResponse.AccessToken,
RefreshToken = gcontext.TokenResponse.RefreshToken,
TokenType = gcontext.TokenResponse.TokenType,
ExpiresInSeconds = int.Parse(gcontext.TokenResponse.ExpiresIn),
IssuedUtc = DateTime.Now
});
await dbContext.StoreTokenAsync (gcontext.GoogleUserId,
gcontext.TokenResponse.Response,
gcontext.TokenResponse.AccessToken,
gcontext.TokenResponse.TokenType,
gcontext.TokenResponse.RefreshToken,
gcontext.TokenResponse.ExpiresIn);
}
}

View File

@ -41,6 +41,7 @@ namespace Yavsc
public partial class Startup
{
public static string AvatarsDirName { private set; get; }
public static string GitDirName { private set; get; }
public static string Authority { get; private set; }
public static string Temp { get; set; }
public static SiteSettings SiteSetup { get; private set; }
@ -155,10 +156,11 @@ namespace Yavsc
// Add framework services.
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationDbContext>()
;
.AddNpgsql()
.AddDbContext<ApplicationDbContext>(
db => db.UseNpgsql(DbHelpers.ConnectionString)
);
ConfigureOAuthServices(services);
services.AddCors(
@ -270,9 +272,9 @@ namespace Yavsc
ResourcesHelpers.GlobalLocalizer = localizer;
SiteSetup = siteSettings.Value;
Authority = siteSettings.Value.Authority;
var blogsDir = siteSettings.Value.UserFiles.Blog;
var blogsDir = siteSettings.Value.Blog;
if (blogsDir==null) throw new Exception ("blogsDir==null");
var billsDir = siteSettings.Value.UserFiles.Bills;
var billsDir = siteSettings.Value.Bills;
if (billsDir==null) throw new Exception ("billsDir==null");
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName;
@ -354,7 +356,6 @@ namespace Yavsc
else throw ex;
}
}
// before fixing the security protocol, let beleive our lib it's done with it.
var cxmgr = ConnectionManager.Instance;
// then, fix it.