Commit d687c6db authored by Janik Münzenberger's avatar Janik Münzenberger
Browse files
parents ccd71763 4581e7cb
......@@ -10,8 +10,7 @@
"/index.html",
"/assets/i18n/*.json",
"/*.css",
"/*.js",
"/*.js",
"/*.js"
],
"urls":[
"https://use.fontawesome.com/releases/v5.0.13/css/*"
......
......@@ -31,7 +31,9 @@ export class DiseaseComponent implements OnInit, OnDestroy {
getPlant(id) {
this.dService.getSingleDisease(id)
.then(disease => this.disease = disease)
.catch(err => console.log(err))
.catch(() => this.error = true);
.catch(err => {
console.log(err);
this.error = true;
})
}
}
......@@ -43,7 +43,7 @@
</div>
</div>
<div class="alert alert-danger" role="alert" *ngIf="error">
<strong>{{"AUTH.OH_SNAP" | translate}}</strong> {{errorResponse}}
<strong>{{"AUTH.OH_SNAP" | translate}}</strong> {{errorResponse | translate}}
</div>
</form>
</div>
......@@ -3,6 +3,7 @@ import {Router, ActivatedRoute} from '@angular/router';
import {MatSnackBar} from '@angular/material';
import {AuthService} from '../../services/auth.service';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
selector: 'app-login',
......@@ -45,9 +46,15 @@ export class LoginComponent implements OnInit {
duration: 3000,
});
this.router.navigate(['/profile']);
}).catch(err => {
}).catch((err:HttpErrorResponse) => {
this.error = true;
this.errorResponse = err.error.error.message || "Sorry could not login";
if(err.status === 504 || !err.status){
this.errorResponse = "ERRORS.NO_CONNECTION";
}else if(err.error){
this.errorResponse = err.error.error.message;
}else{
this.errorResponse = "ERRORS.LOGIN";
}
});
}
......
<div class="loader mx-auto my-5" *ngIf="!plant" appTimeout [timeout]="1000"></div>
<div class="col-md-12" *ngIf="!plant && error">
<div class="col-md-12 alert alert-warning mx-auto">
{{"ERRORS.PLANTS" | translate}}
{{"ERRORS.PLANT" | translate}}
</div>
</div>
<div class="container" *ngIf="plant">
......
......@@ -42,7 +42,7 @@
</div>
<div class="alert alert-danger" role="alert" *ngIf="error">
<strong>{{"AUTH.OH_SNAP" | translate}}</strong> {{errorResponse}}
<strong>{{"AUTH.OH_SNAP" | translate}}</strong> {{errorResponse | translate}}
</div>
</form>
</div>
......@@ -34,7 +34,13 @@ export class RegisterComponent implements OnInit {
this.route.navigate(['/login'], { queryParams: { reason: 'registered' } });
}).catch(err => {
this.error = true;
this.errorResponse = err.error.error.message || "Could not be registered";
if(err.status === 504 || !err.status){
this.errorResponse = "ERRORS.NO_CONNECTION";
}else if(err.error){
this.errorResponse = err.error.error.message;
}else{
this.errorResponse = "ERRORS.REGISTER";
}
console.error(err);
});
}
......
......@@ -82,8 +82,8 @@
"TO_EMAIL": "Sende Ergbnis an meine Email",
"ANALYSE": "Analysieren",
"PUSH": "Analyse erfolgreich gestartet. Sie werden benachrichtigt sobald das Ergebnis fertig ist.",
"PROGRESS": "Ihr Foto wird analysiert. Bitte warten.",
"NO_RESULT": "Tut uns leid, aber wir konnten kein Ergebnis für ihre Analyse erhalten. Bitte versuchen sie es später noch einmal"
"PROGRESS": "Warten auf das Ergebnis.",
"NO_RESULT": "Tut uns leid, aber wir die Analyse konnte nicht gestartet werden."
},
"PROFILE": {
"INFORMATION": "Information",
......@@ -116,7 +116,10 @@
"PLANTS": "Tut uns leid, aber wirk konnten leider keine Krankheiten laden. Bitte überprüfen Sie ihre Internetverbindung.",
"GARDENERS": "Keine Gärtnereien verfügbar",
"PLANT": "Pflanze konnte nicht geladen werden. Bitte überprüfen Sie ihre Internetverbindung. Die können die Seite auch offline benutzen sobald Sie sie einmal geladen haben",
"DISEASE": "Krankheit konnte nicht geladen werden. Bitte überprüfen Sie ihre Internetverbindung. Die können die Seite auch offline benutzen sobald Sie sie einmal geladen haben"
"DISEASE": "Krankheit konnte nicht geladen werden. Bitte überprüfen Sie ihre Internetverbindung. Die können die Seite auch offline benutzen sobald Sie sie einmal geladen haben",
"LOGIN": "Login fehlgeschlagen.",
"REGISTER": "Registrierung fehlgeschlagen",
"NO_CONNECTION": "Keine Internetverbindung. Bitte überprüfen sie ihre Einstellungen."
},
"YES": "Ja",
"NO": "Nein",
......
......@@ -81,7 +81,7 @@
"SELECT_IMAGE": "Choose / Make a photo",
"TO_EMAIL": "Send the result to my email",
"ANALYSE": "Analyse",
"NO_RESULT": "Sorry we couldnt get a result for your image in time. Please try again later.",
"NO_RESULT": "Unfortunatly the analysis could not be started.",
"PROGRESS": "Waiting for analysis result.",
"PUSH": "Successfully startet the analysis. You will be notified when the result is ready."
},
......@@ -117,7 +117,10 @@
"PLANTS": "Sorry we could not get the plants. Please check your internet connection.",
"GARDENERS": "No gardeners available!",
"PLANT": "Could not get the plant. Please check your internet connection. To access this page in offline mode, please visit it once with online access.",
"DISEASE": "Could not get the disease. Please check your internet connection. To access this page in offline mode, please visit it once with online access."
"DISEASE": "Could not get the disease. Please check your internet connection. To access this page in offline mode, please visit it once with online access.",
"LOGIN": "Login failed.",
"REGISTER": "Register failed",
"NO_CONNECTION": "No internet connection. Please check your network settings."
},
"YES": "Yes",
"NO": "No",
......
/** Required packages */
const mongoose = require('mongoose'),
express = require('express'),
bodyParser = require('body-parser'),
fileUpload = require('express-fileupload'),
os = require('os'),
path = require('path'),
express = require('express'),
bodyParser = require('body-parser'),
fileUpload = require('express-fileupload'),
os = require('os'),
path = require('path'),
webpush = require('web-push'),
compression = require('compression');
compression = require('compression');
/** Get configuration */
process.env.NODE_CONFIG_DIR = __dirname + "/config/";
......@@ -15,6 +15,13 @@ const config = require('config');
/** Express initialzer */
const app = express();
app.use(req, res, next)
{
// check if it is a secure (https) request
// if not redirect to the equivalent https url
!req.secure ? res.redirect('https://' + req.hostname + req.url) : next();
}
/** Initizialize logger */
const winston = require('winston');
winston.level = process.env.LOG_LEVEL || 'info';
......@@ -23,30 +30,33 @@ winston.level = process.env.LOG_LEVEL || 'info';
app.use(compression());
/** Bodyparser */
app.use(bodyParser.urlencoded( {extended: true }));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(bodyParser.text());
if(process.env.NODE_ENV !== 'prod'){
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
if (process.env.NODE_ENV !== 'prod') {
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
// Pass to next layer of middleware
next();
});
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
}
/** file-Upload */
......@@ -68,10 +78,11 @@ app.use('/uploads', express.static(path.join(__dirname, './assets')));
/** Initialize routes */
app.use('/api', require('./controller/routes'));
app.use('*', function(req, res){
res.sendFile(path.join(__dirname, "../../dist/index.html"));
app.use('*', function (req, res) {
res.sendFile(path.join(__dirname, "../../dist/index.html"));
});
/** configure web-push with vapid key **/
const publicVapidKey = config.publicVapidKey;
const privateVapidKey = config.privateVapidKey;
......@@ -81,12 +92,12 @@ const privateVapidKey = config.privateVapidKey;
webpush.setVapidDetails('mailto:a_loic16@yahoo.fr', publicVapidKey, privateVapidKey);
/** Start server */
let port = process.env.PORT || config.port;
app.listen(port, () => {
app.listen(port, () = > {
console.log(`Listening on Port: ${port}`);
});
})
;
/** Exports */
module.exports = app;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment