1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

improving database settings

This commit is contained in:
Braun Patrik 2017-07-12 18:31:19 +02:00
parent aaad3cd5c2
commit 23cc90a42d
11 changed files with 38 additions and 15 deletions

View File

@ -20,7 +20,7 @@ export class AdminMWs {
const databaseSettings = <DataBaseConfig>req.body.databaseSettings; const databaseSettings = <DataBaseConfig>req.body.databaseSettings;
try { try {
if (Config.Server.database.type == DatabaseType.mysql) { if (databaseSettings.type == DatabaseType.mysql) {
await MySQLConnection.tryConnection(databaseSettings); await MySQLConnection.tryConnection(databaseSettings);
} }
Config.Server.database = databaseSettings; Config.Server.database = databaseSettings;
@ -50,12 +50,12 @@ export class AdminMWs {
const databaseSettings = <DataBaseConfig>req.body.databaseSettings; const databaseSettings = <DataBaseConfig>req.body.databaseSettings;
try { try {
if (Config.Server.database.type == DatabaseType.mysql) { if (databaseSettings.type == DatabaseType.mysql) {
await MySQLConnection.tryConnection(databaseSettings); await MySQLConnection.tryConnection(databaseSettings);
} }
return next(); return next();
} catch (err) { } catch (err) {
return next(new Error(ErrorCodes.SETTINGS_ERROR, "Error saving database settings", err)); return next(new Error(ErrorCodes.SETTINGS_ERROR, "Settings error: " + JSON.stringify(err, null, ' '), err));
} }
} }
} }

View File

@ -51,7 +51,7 @@ export class RenderingMWs {
public static renderConfig(req: Request, res: Response, next: NextFunction) { public static renderConfig(req: Request, res: Response, next: NextFunction) {
let message = new Message<PrivateConfigClass>(null, Config); let message = new Message<PrivateConfigClass>(null, Config.original());
res.json(message); res.json(message);
} }

View File

@ -1,12 +1,12 @@
import * as bcrypt from "bcryptjs"; import * as bcryptjs from "bcryptjs";
export class PasswordHelper { export class PasswordHelper {
public static cryptPassword(password) { public static cryptPassword(password) {
const salt = bcrypt.genSaltSync(10); const salt = bcryptjs.genSaltSync(10);
return bcrypt.hashSync(password, salt); return bcryptjs.hashSync(password, salt);
} }
public static comparePassword(password, encryptedPassword) { public static comparePassword(password, encryptedPassword) {
return bcrypt.compareSync(password, encryptedPassword); return bcryptjs.compareSync(password, encryptedPassword);
} }
} }

View File

@ -1,5 +1,5 @@
import "reflect-metadata"; import "reflect-metadata";
import {Connection, createConnection} from "typeorm"; import {Connection, createConnection, getConnection} from "typeorm";
import {UserEntity} from "./enitites/UserEntity"; import {UserEntity} from "./enitites/UserEntity";
import {UserRoles} from "../../../common/entities/UserDTO"; import {UserRoles} from "../../../common/entities/UserDTO";
import {PhotoEntity, PhotoMetadataEntity} from "./enitites/PhotoEntity"; import {PhotoEntity, PhotoMetadataEntity} from "./enitites/PhotoEntity";
@ -53,6 +53,10 @@ export class MySQLConnection {
} }
public static async tryConnection(config: DataBaseConfig) { public static async tryConnection(config: DataBaseConfig) {
try {
await getConnection("test").close();
} catch (err) {
}
const conn = await createConnection({ const conn = await createConnection({
name: "test", name: "test",
driver: { driver: {

View File

@ -52,5 +52,11 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
public save() { public save() {
ConfigLoader.saveConfigFile(path.join(__dirname, './../../../config.json'), this); ConfigLoader.saveConfigFile(path.join(__dirname, './../../../config.json'), this);
} }
public original(): PrivateConfigClass {
let cfg = new PrivateConfigClass();
cfg.load();
return cfg;
}
} }

View File

@ -164,6 +164,7 @@ export class GalleryLightboxComponent implements OnDestroy {
public hide() { public hide() {
this.controllersVisible = false; this.controllersVisible = false;
this.fullScreenService.exitFullScreen(); this.fullScreenService.exitFullScreen();
this.pause();
const lightboxDimension = this.activePhoto.getDimension(); const lightboxDimension = this.activePhoto.getDimension();
lightboxDimension.top -= this.getBodyScrollTop(); lightboxDimension.top -= this.getBodyScrollTop();

View File

@ -70,6 +70,9 @@ export class NetworkService {
} }
private static handleError(error: any) { private static handleError(error: any) {
if (error.code) {
return Promise.reject(error);
}
// TODO: in a real world app do something better // TODO: in a real world app do something better
// instead of just logging it to the console // instead of just logging it to the console
console.error(error); console.error(error);

View File

@ -7,7 +7,7 @@
<form #settingsForm="ngForm"> <form #settingsForm="ngForm">
<p class="title">Type:</p> <p class="title">Type:</p>
<select class="form-control" [(ngModel)]="settings.type" name="type" required> <select class="form-control" [(ngModel)]="settings.type" name="type" required>
<option *ngFor="let type of types" [value]="type.key">{{type.value}} <option *ngFor="let type of types" [ngValue]="type.key">{{type.value}}
</option> </option>
</select> </select>
<ng-container *ngIf="settings.type == DatabaseType.mysql"> <ng-container *ngIf="settings.type == DatabaseType.mysql">
@ -25,12 +25,12 @@
</form> </form>
<button class="btn btn-primary pull-right" <button class="btn btn-primary pull-right"
*ngIf="tested==false" *ngIf="tested==false"
[disabled]="!settingsForm.form.valid || !changed" [disabled]="!settingsForm.form.valid || !changed || inProgress"
(click)="test()">Test (click)="test()">Test
</button> </button>
<button class="btn btn-success pull-right" <button class="btn btn-success pull-right"
*ngIf="tested==true" *ngIf="tested==true"
[disabled]="!settingsForm.form.valid || !changed" [disabled]="!settingsForm.form.valid || !changed || inProgress"
(click)="save()">Save (click)="save()">Save
</button> </button>
<button class="btn btn-default pull-right" <button class="btn btn-default pull-right"

View File

@ -21,6 +21,7 @@ export class DatabaseSettingsComponent implements OnInit {
type: DatabaseType.memory, type: DatabaseType.memory,
mysql: {} mysql: {}
}; };
inProgress = false;
private original: DataBaseConfig; private original: DataBaseConfig;
public types: Array<any> = []; public types: Array<any> = [];
public DatabaseType: any; public DatabaseType: any;
@ -65,23 +66,31 @@ export class DatabaseSettingsComponent implements OnInit {
this.getSettings(); this.getSettings();
} }
public async test() { public async test() {
this.inProgress = true;
try { try {
this.error = "";
await this._dbSettings.testSettings(this.settings); await this._dbSettings.testSettings(this.settings);
this.tested = true; this.tested = true;
} catch (err) { } catch (err) {
if (err.message) console.log(err);
if (err.message) {
this.error = (<Error>err).message; this.error = (<Error>err).message;
} }
} }
this.inProgress = false;
}
public async save() { public async save() {
if (typeof this.settings.type == "undefined" || !this.tested) { if (typeof this.settings.type == "undefined" || !this.tested) {
return; return;
} }
this.inProgress = true;
await this._dbSettings.updateSettings(this.settings); await this._dbSettings.updateSettings(this.settings);
await this.getSettings(); await this.getSettings();
this.notification.success('Database settings saved', "Success"); this.notification.success('Database settings saved', "Success");
this.inProgress = false;
} }
} }

View File

@ -27,6 +27,6 @@ export class DatabaseSettingsService {
} }
public testSettings(settings): Promise<void> { public testSettings(settings): Promise<void> {
return this._networkService.postJson("/settings/test/database", {databaseSettings: settings}); return this._networkService.postJson<void>("/settings/test/database", {databaseSettings: settings});
} }
} }

View File

@ -56,7 +56,7 @@
"@angular/platform-browser": "~4.2.6", "@angular/platform-browser": "~4.2.6",
"@angular/platform-browser-dynamic": "~4.2.6", "@angular/platform-browser-dynamic": "~4.2.6",
"@angular/router": "~4.2.6", "@angular/router": "~4.2.6",
"@types/bcrypt": "^1.0.0", "@types/bcryptjs": "^2.4.0",
"@types/express": "^4.0.36", "@types/express": "^4.0.36",
"@types/express-session": "1.15.0", "@types/express-session": "1.15.0",
"@types/gm": "^1.17.31", "@types/gm": "^1.17.31",