mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
adding option to configure unAuthenticated user role
This commit is contained in:
parent
037c366e80
commit
77a815fe53
@ -1,7 +1,9 @@
|
||||
# User rights
|
||||
|
||||
* Limited Guest - list dir
|
||||
* Guest - +search
|
||||
* User - +share
|
||||
* Admin - +settings
|
||||
* Developer - +see errors
|
||||
| id | Role | rights |
|
||||
|----|---------------|-------------|
|
||||
| 1 | Limited Guest | list dir |
|
||||
| 2 | Guest | +search |
|
||||
| 3 | User | +share |
|
||||
| 4 | Admin | +settings |
|
||||
| 5 | Developer | +see errors |
|
||||
|
@ -12,7 +12,7 @@ export class AuthenticationMWs {
|
||||
|
||||
public static async tryAuthenticate(req: Request, res: Response, next: NextFunction) {
|
||||
if (Config.Client.authenticationRequired === false) {
|
||||
req.session.user = <UserDTO>{name: 'Admin', role: UserRoles.Admin};
|
||||
req.session.user = <UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole};
|
||||
return next();
|
||||
}
|
||||
try {
|
||||
@ -31,7 +31,7 @@ export class AuthenticationMWs {
|
||||
public static async authenticate(req: Request, res: Response, next: NextFunction) {
|
||||
|
||||
if (Config.Client.authenticationRequired === false) {
|
||||
req.session.user = <UserDTO>{name: 'Admin', role: UserRoles.Admin};
|
||||
req.session.user = <UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole};
|
||||
return next();
|
||||
}
|
||||
try {
|
||||
|
@ -2,6 +2,9 @@ import {PublicConfigClass} from '../public/ConfigClass';
|
||||
import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ServerConfig, ThumbnailProcessingLib} from './IPrivateConfig';
|
||||
import * as path from 'path';
|
||||
import {ConfigLoader} from 'typeconfig';
|
||||
import {UserService} from '../../../frontend/app/model/network/user.service';
|
||||
import {Utils} from '../../Utils';
|
||||
import {UserRoles} from '../../entities/UserDTO';
|
||||
|
||||
/**
|
||||
* This configuration will be only at backend
|
||||
@ -59,6 +62,10 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
|
||||
path.join(__dirname, './../../../config.json'),
|
||||
[['PORT', 'Server-port']]);
|
||||
|
||||
if (Utils.enumToArray(UserRoles).map(r => r.key).indexOf(this.Client.unAuthenticatedUserRole) === -1) {
|
||||
throw new Error('Unknown user role for Client.unAuthenticatedUserRole, found: ' + this.Client.unAuthenticatedUserRole);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public save() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {SortingMethods} from '../../entities/SortingMethods';
|
||||
import {UserRoles} from '../../entities/UserDTO';
|
||||
|
||||
export module ClientConfig {
|
||||
export interface SearchConfig {
|
||||
@ -63,6 +64,7 @@ export module ClientConfig {
|
||||
RandomPhoto: RandomPhotoConfig;
|
||||
Other: OtherConfig;
|
||||
authenticationRequired: boolean;
|
||||
unAuthenticatedUserRole: UserRoles;
|
||||
languages: string[];
|
||||
Video: VideoConfig;
|
||||
MetaFile: MetaFileConfig;
|
||||
@ -118,6 +120,7 @@ export class PublicConfigClass {
|
||||
}
|
||||
},
|
||||
authenticationRequired: true,
|
||||
unAuthenticatedUserRole: UserRoles.Admin,
|
||||
publicUrl: '',
|
||||
urlBase: '',
|
||||
languages: []
|
||||
|
@ -30,7 +30,7 @@ export class AuthenticationService {
|
||||
this.getSessionUser();
|
||||
} else {
|
||||
if (Config.Client.authenticationRequired === false) {
|
||||
this.user.next(<UserDTO>{name: '', role: UserRoles.Admin});
|
||||
this.user.next(<UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ import {BehaviorSubject} from 'rxjs';
|
||||
import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ThumbnailProcessingLib} from '../../../common/config/private/IPrivateConfig';
|
||||
import {NetworkService} from '../model/network/network.service';
|
||||
import {SortingMethods} from '../../../common/entities/SortingMethods';
|
||||
import {UserRoles} from '../../../common/entities/UserDTO';
|
||||
|
||||
@Injectable()
|
||||
export class SettingsService {
|
||||
@ -55,6 +56,7 @@ export class SettingsService {
|
||||
publicUrl: '',
|
||||
applicationTitle: '',
|
||||
authenticationRequired: true,
|
||||
unAuthenticatedUserRole: UserRoles.Admin,
|
||||
languages: []
|
||||
},
|
||||
Server: {
|
||||
|
Loading…
Reference in New Issue
Block a user