ngx-admin/src/app/@core/core.module.ts

99 lines
2.1 KiB
TypeScript
Raw Normal View History

import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
2017-04-13 14:24:23 +03:00
import { CommonModule } from '@angular/common';
2018-06-20 18:46:49 +03:00
import { NbAuthModule, NbDummyAuthStrategy } from '@nebular/auth';
import { NbSecurityModule, NbRoleProvider } from '@nebular/security';
2018-05-10 23:48:39 +03:00
import { of as observableOf } from 'rxjs';
2017-04-13 14:24:23 +03:00
import { throwIfAlreadyLoaded } from './module-import-guard';
import { DataModule } from './data/data.module';
2017-09-20 13:55:34 +03:00
import { AnalyticsService } from './utils/analytics.service';
const socialLinks = [
{
url: 'https://github.com/akveo/nebular',
target: '_blank',
icon: 'socicon-github',
},
{
url: 'https://www.facebook.com/akveo/',
target: '_blank',
icon: 'socicon-facebook',
},
{
url: 'https://twitter.com/akveo_inc',
target: '_blank',
icon: 'socicon-twitter',
},
];
2018-05-10 23:48:39 +03:00
export class NbSimpleRoleProvider extends NbRoleProvider {
getRole() {
// here you could provide any role based on any auth flow
return observableOf('guest');
}
}
export const NB_CORE_PROVIDERS = [
...DataModule.forRoot().providers,
...NbAuthModule.forRoot({
2018-06-20 18:46:49 +03:00
strategies: [
NbDummyAuthStrategy.setup({
name: 'email',
delay: 3000,
}),
],
forms: {
login: {
socialLinks: socialLinks,
},
register: {
socialLinks: socialLinks,
},
},
}).providers,
2018-06-20 18:46:49 +03:00
NbSecurityModule.forRoot({
accessControl: {
guest: {
view: '*',
},
user: {
parent: 'guest',
create: '*',
edit: '*',
remove: '*',
},
},
}).providers,
2018-06-20 18:46:49 +03:00
{
2018-05-10 23:48:39 +03:00
provide: NbRoleProvider, useClass: NbSimpleRoleProvider,
},
2017-09-20 13:55:34 +03:00
AnalyticsService,
];
2017-04-13 14:24:23 +03:00
@NgModule({
imports: [
2017-05-06 15:35:15 +03:00
CommonModule,
2017-04-13 14:24:23 +03:00
],
exports: [
NbAuthModule,
],
2017-05-06 15:35:15 +03:00
declarations: [],
2017-04-13 14:24:23 +03:00
})
export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
static forRoot(): ModuleWithProviders {
return <ModuleWithProviders>{
ngModule: CoreModule,
providers: [
...NB_CORE_PROVIDERS,
],
};
}
2017-04-13 14:24:23 +03:00
}