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;
try {
if (Config.Server.database.type == DatabaseType.mysql) {
if (databaseSettings.type == DatabaseType.mysql) {
await MySQLConnection.tryConnection(databaseSettings);
}
Config.Server.database = databaseSettings;
@ -50,12 +50,12 @@ export class AdminMWs {
const databaseSettings = <DataBaseConfig>req.body.databaseSettings;
try {
if (Config.Server.database.type == DatabaseType.mysql) {
if (databaseSettings.type == DatabaseType.mysql) {
await MySQLConnection.tryConnection(databaseSettings);
}
return next();
} 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) {
let message = new Message<PrivateConfigClass>(null, Config);
let message = new Message<PrivateConfigClass>(null, Config.original());
res.json(message);
}

View File

@ -1,12 +1,12 @@
import * as bcrypt from "bcryptjs";
import * as bcryptjs from "bcryptjs";
export class PasswordHelper {
public static cryptPassword(password) {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(password, salt);
const salt = bcryptjs.genSaltSync(10);
return bcryptjs.hashSync(password, salt);
}
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 {Connection, createConnection} from "typeorm";
import {Connection, createConnection, getConnection} from "typeorm";
import {UserEntity} from "./enitites/UserEntity";
import {UserRoles} from "../../../common/entities/UserDTO";
import {PhotoEntity, PhotoMetadataEntity} from "./enitites/PhotoEntity";
@ -53,6 +53,10 @@ export class MySQLConnection {
}
public static async tryConnection(config: DataBaseConfig) {
try {
await getConnection("test").close();
} catch (err) {
}
const conn = await createConnection({
name: "test",
driver: {

View File

@ -52,5 +52,11 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
public save() {
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() {
this.controllersVisible = false;
this.fullScreenService.exitFullScreen();
this.pause();
const lightboxDimension = this.activePhoto.getDimension();
lightboxDimension.top -= this.getBodyScrollTop();

View File

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

View File

@ -7,7 +7,7 @@
<form #settingsForm="ngForm">
<p class="title">Type:</p>
<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>
</select>
<ng-container *ngIf="settings.type == DatabaseType.mysql">
@ -25,12 +25,12 @@
</form>
<button class="btn btn-primary pull-right"
*ngIf="tested==false"
[disabled]="!settingsForm.form.valid || !changed"
[disabled]="!settingsForm.form.valid || !changed || inProgress"
(click)="test()">Test
</button>
<button class="btn btn-success pull-right"
*ngIf="tested==true"
[disabled]="!settingsForm.form.valid || !changed"
[disabled]="!settingsForm.form.valid || !changed || inProgress"
(click)="save()">Save
</button>
<button class="btn btn-default pull-right"

View File

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

View File

@ -27,6 +27,6 @@ export class DatabaseSettingsService {
}
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-dynamic": "~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-session": "1.15.0",
"@types/gm": "^1.17.31",