Browse Source

Small improvements.

pull/1/head
Sebastian 10 years ago
parent
commit
8481bc9854
  1. 4
      src/Squidex/Startup.cs
  2. 2
      src/Squidex/app-config/webpack.run.prod.js
  3. 12
      src/Squidex/app/shared/guards/app-must-exist.guard.ts
  4. 4
      src/Squidex/app/shared/services/apps-store.service.ts
  5. 25
      src/Squidex/app/shared/services/auth.service.ts
  6. 1
      src/Squidex/project.json

4
src/Squidex/Startup.cs

@ -68,7 +68,6 @@ namespace Squidex
services.AddMemoryCache();
services.AddOptions();
services.AddRouting();
services.AddResponseCompression();
services.AddWebpackBuilder();
services.Configure<MyMongoDbOptions>(
@ -95,8 +94,6 @@ namespace Squidex
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseResponseCompression();
if (!Environment.IsDevelopment())
{
app.UseMiddleware<SingleUrlsMiddleware>();
@ -185,7 +182,6 @@ namespace Squidex
headers.CacheControl = new CacheControlHeaderValue
{
MaxAge = TimeSpan.FromDays(60),
};
}
});

2
src/Squidex/app-config/webpack.run.prod.js

@ -57,7 +57,7 @@ module.exports = webpackMerge.smart(runConfig, {
loader: ExtractTextPlugin.extract({ fallbackLoader: 'style', loader: 'css!sass?sourceMap' })
}, {
test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/,
loaders: ['file?hash=sha512&digest=hex&name=[hash].[ext]', 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false']
loaders: ['file?hash=sha512&digest=hex&name=assets/[name].[hash].[ext]', 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false']
}
]
},

12
src/Squidex/app/shared/guards/app-must-exist.guard.ts

@ -8,8 +8,6 @@
import * as Ng2 from '@angular/core';
import * as Ng2Router from '@angular/router';
import { Observable } from 'rxjs';
import { AppsStoreService } from './../services/apps-store.service';
@Ng2.Injectable()
@ -20,17 +18,19 @@ export class AppMustExistGuard implements Ng2Router.CanActivate {
) {
}
public canActivate(route: Ng2Router.ActivatedRouteSnapshot, state: Ng2Router.RouterStateSnapshot): Observable<boolean> {
public canActivate(route: Ng2Router.ActivatedRouteSnapshot, state: Ng2Router.RouterStateSnapshot): Promise<boolean> {
const appName = route.params['appName'];
const result =
this.appsStore.selectApp(appName)
.take(1)
.map(app => app !== null)
.do(hasApp => {
.then(hasApp => {
if (!hasApp) {
this.router.navigate(['/404']);
}
return hasApp;
}).catch(() => {
this.router.navigate(['/404']);
});
return result;

4
src/Squidex/app/shared/services/apps-store.service.ts

@ -82,10 +82,10 @@ export class AppsStoreService {
});
}
public selectApp(name: string | null): Observable<AppDto | null> {
public selectApp(name: string | null): Promise<boolean> {
this.appName$.next(name);
return this.selectedApp;
return this.selectedApp.take(1).map(app => app !== null).toPromise();
}
public createApp(appToCreate: AppCreateDto): Observable<AppDto> {

25
src/Squidex/app/shared/services/auth.service.ts

@ -38,6 +38,8 @@ export class Profile {
export class AuthService {
private readonly userManager: UserManager;
private readonly isAuthenticatedChanged$ = new Subject<boolean>();
private loginCompleted = false;
private loginCache: Promise<boolean> | null = null;
private currentUser: Profile | null = null;
private readonly isAuthenticatedChangedPublished$ =
@ -87,16 +89,18 @@ export class AuthService {
}
public checkLogin(): Promise<boolean> {
if (this.currentUser) {
return Promise.resolve(true);
if (this.loginCompleted) {
return Promise.resolve(this.currentUser !== null);
} else if (this.loginCache) {
return this.loginCache;
} else {
const promise =
this.loginCache =
this.checkState(this.userManager.signinSilent())
.then(result => {
return result || this.checkState(this.userManager.signinSilent());
});
return promise;
return this.loginCache;
}
}
@ -143,11 +147,18 @@ export class AuthService {
const resultPromise =
promise
.then(user => {
if (user) {
this.onAuthenticated(user);
}
this.loginCache = null;
this.loginCompleted = null;
this.onAuthenticated(user);
return !!this.currentUser;
}).catch((err) => {
this.loginCache = null;
this.loginCompleted = null;
this.onAuthenticated(null);
return false;
});

1
src/Squidex/project.json

@ -15,7 +15,6 @@
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.ResponseCompression": "1.0.0-preview1-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",

Loading…
Cancel
Save