Skip to content

Commit

Permalink
Merge pull request #68 from filak/dev-1.6.8
Browse files Browse the repository at this point in the history
Dev 1.6.8
  • Loading branch information
filak authored Dec 17, 2024
2 parents aad9ff9 + 7ce87a7 commit 8f35471
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 226 deletions.
102 changes: 102 additions & 0 deletions flask-app/!!build__dist_pyinstaller.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@echo off
setlocal
echo.
set python=venv\Scripts\pyinstaller.exe

echo.
choice /C AN /M "Activate Python VENV ? A/N"
if errorlevel 2 goto:start

echo.
echo Activating VENV
call venv\Scripts\activate

:start
echo.
choice /C AN /M "Clean build ? A/N"
if errorlevel 1 set buildClean=--clean
if errorlevel 2 set buildClean=

choice /C AN /M "Test run ? A/N"
if errorlevel 1 set testRun=1
if errorlevel 2 set testRun=0

echo Build using pyinstaller : %python%

set srcDir=application
set targetDir=dist
set subdir=
set logFile=!build_dist_pyinstaller.rep

echo.
echo Cleaning static files %targetDir% ...
RMDIR %targetDir%\static /S /Q
RMDIR %targetDir%\templates /S /Q

echo.
echo Copying files from: static, templates ...
xcopy %srcDir%\static %targetDir%\static /I /E /Q /Y
xcopy %srcDir%\templates %targetDir%\templates /I /E /Q /Y

echo. > %logFile%

set fileHandle=mtw-server
set extras=--add-data %srcDir%/pyuca/*.txt;pyuca
set subdir=
call:buildFiles

set fileHandle=mtw-worker
set extras=--add-data %srcDir%/pyuca/*.txt;pyuca
set subdir=
call:buildFiles

set fileHandle=set-mtw-admin
set extras=
set subdir=
call:buildFiles

set fileHandle=mesh-nt2trx
set extras=
set subdir=tools\
call:buildFiles

set fileHandle=mesh-trx2nt
set extras=
set subdir=tools\
call:buildFiles

set fileHandle=mesh-xml2trx
set extras=
set subdir=tools\
call:buildFiles

echo.
echo Finished !!!
echo.

title Finished building!
goto:eof

:buildFiles
set srcFile=%subdir%%fileHandle%.py
echo.
echo Building %srcFile%
title Building %srcFile%

CALL %python% --log-level ERROR --onefile %extras% --distpath %targetDir%\%subdir% %srcFile% %buildClean% >> %logFile% 2>&1

if %testRun%==1 call:runTestHelp
goto:eof

:runTestHelp
echo.
set binFile=%subdir%%fileHandle%.exe
echo Running %targetDir%\%binFile% ...
CALL %targetDir%\%binFile% -h
echo.
echo Done.
echo.
goto:eof

endlocal

57 changes: 0 additions & 57 deletions flask-app/!!build__mtw-server.bat

This file was deleted.

58 changes: 0 additions & 58 deletions flask-app/!!build__mtw-tools.bat

This file was deleted.

42 changes: 0 additions & 42 deletions flask-app/!!build__mtw-worker.bat

This file was deleted.

34 changes: 0 additions & 34 deletions flask-app/!!build__set-mtw-admin.bat

This file was deleted.

10 changes: 7 additions & 3 deletions flask-app/application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix

from application.modules.extensions import Talisman, cache, csrf, paranoid, sess
from application.modules.extensions import Talisman, cache, csrf, paranoid, sess # limiter
from application.modules import utils as mtu


Expand Down Expand Up @@ -56,7 +56,7 @@ def create_app(debug=False, logger=None, port=5900,
app.config.update(dict(
APPLICATION_ROOT = url_prefix,
APP_NAME = 'MTW',
APP_VER = '1.6.7',
APP_VER = '1.6.8',
API_VER = '1.0.0',
DBVERSION = 1.0,
CACHE_DIR = mtu.get_instance_dir(app, 'cache'),
Expand Down Expand Up @@ -132,9 +132,13 @@ def create_app(debug=False, logger=None, port=5900,
cache.init_app(app)
sess.init_app(app)

# SeaSurf (csrf) & Talisman
# Limiter
# limiter.init_app(app)

# SeaSurf (csrf)
csrf.init_app(app)

# Talisman
if not relax and not app.debug:
# Paranoid
paranoid.init_app(app)
Expand Down
12 changes: 12 additions & 0 deletions flask-app/application/modules/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bcrypt
from functools import wraps
from itsdangerous import URLSafeTimedSerializer
from secrets import compare_digest
Expand All @@ -14,6 +15,17 @@
from flask import current_app as app


def hash_pwd(password):
return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')


def check_pwd(password, hashed_password):
try:
return bcrypt.checkpw(password.encode('utf-8'), hashed_password.encode('utf-8'))
except ValueError:
return False


def login_required(f):
@wraps(f)
def secure_function(*args, **kwargs):
Expand Down
7 changes: 7 additions & 0 deletions flask-app/application/modules/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from flask import flash, g
from flask import current_app as app

from application.modules.auth import hash_pwd


# Database

Expand Down Expand Up @@ -38,6 +40,9 @@ def get_db():
def addUser(username, firstname, lastname, passwd, ugroup, phone='', email=''):
db = get_db()
try:
if passwd:
passwd = hash_pwd(passwd)

db.execute('insert into users (username, passwd, firstname, lastname, ugroup, phone, email) values (?, ?, ?, ?, ?, ?, ?)',
[username, passwd, firstname, lastname, ugroup, phone, email])
db.commit()
Expand Down Expand Up @@ -73,6 +78,8 @@ def updateUser(username, firstname, lastname, passwd, ugroup, userid, phone='',
db = get_db()
try:
if passwd:
passwd = hash_pwd(passwd)

db.execute('update users set username = ?, firstname = ?, lastname = ?, passwd = ?, ugroup = ?, phone = ?, email = ? where id = ?',
[username, firstname, lastname, passwd, ugroup, phone, email, userid])
else:
Expand Down
Loading

0 comments on commit 8f35471

Please sign in to comment.