Skip to content

Commit 78a13de

Browse files
committed
Added webapp/flaskwebapps/genericflaskwebapp
* Create new section 'webapp' * Added 'src/webapp/flaskwebapps/genericflaskwebapp/' module / app - custom SQLite3 ORM equipped basic (generic) flask web app for quick development. * Added 'examples/webapp/flaskwebapps/genericflaskwebapp/' module / app.
1 parent ed3ab73 commit 78a13de

File tree

98 files changed

+5912
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+5912
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name = 'CXINFINITE'
2+
github = 'https://github.com/CXINFINITE/'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
sys.path.append(os.path.abspath(
6+
Path(__file__).parent.resolve()
7+
))
8+
sys.path.append(os.path.abspath(
9+
Path(__file__).parent.parent.resolve()
10+
))
11+
12+
from . import (
13+
__author__,
14+
__version__,
15+
ui,
16+
ui_bridge,
17+
operations,
18+
backend,
19+
database,
20+
)
21+
22+
__all__ = [
23+
'__author__',
24+
'__version__',
25+
26+
'ui',
27+
'ui_bridge',
28+
'operations',
29+
'backend',
30+
'database',
31+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
sys.path.append(os.path.abspath(
6+
Path(__file__).parent.resolve(),
7+
))
8+
sys.path.append(os.path.abspath(
9+
Path(__file__).parent.parent.resolve(),
10+
))
11+
12+
from ui_bridge import execute_cli
13+
14+
if __name__ == '__main__':
15+
execute_cli()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
fullappname = 'Generic Flask Web App Demo'
2+
appname = 'GenericFlaskWebAppDemo'
3+
4+
major = 0
5+
minor = 0
6+
patch = 0
7+
8+
release = 'dev'
9+
10+
description = '{0}: v{1}.{2}.{3}-{4}'.format(
11+
appname, major, minor, patch, release,
12+
)
13+
14+
full = '{0}.{1}.{2}-{3}'.format(
15+
major, minor, patch, release,
16+
)
17+
18+
long = '{0}.{1}.{2}'.format(
19+
major, minor, patch,
20+
)
21+
22+
short = '{0}.{1}'.format(
23+
major, minor,
24+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from . import (
2+
core,
3+
security,
4+
decorators,
5+
functionality,
6+
7+
routers,
8+
)
9+
10+
from .api import API as api
11+
12+
router = None
13+
14+
__all__ = [
15+
'api',
16+
17+
'core',
18+
'security',
19+
'decorators',
20+
'functionality',
21+
22+
'routers',
23+
24+
'router',
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import genericflaskwebapp as app
2+
3+
class API:
4+
class Router:
5+
RouterV1 = 1
6+
7+
def router_start (router):
8+
if (router == API.Router.RouterV1):
9+
from .routers import routerv1
10+
11+
app.backend.router = routerv1
12+
13+
return True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .redirect_internal import Redirect_Internal as redirect_internal
2+
3+
__all__ = [
4+
'redirect_internal',
5+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import datetime
2+
3+
from flask import (
4+
redirect,
5+
session,
6+
)
7+
8+
class Redirect_Internal:
9+
def redirect (route, expire=None, **kwargs):
10+
redirectiondata = {
11+
'route': route,
12+
'data': kwargs,
13+
'expire': (None
14+
if (not expire)
15+
else
16+
expire
17+
),
18+
}
19+
session['redirect_internal'] = redirectiondata
20+
21+
return redirect(route)
22+
23+
def check (route):
24+
if ('redirect_internal' not in session):
25+
return None
26+
27+
redirectiondata = session.pop('redirect_internal')
28+
29+
if (redirectiondata.get('route') != route):
30+
return None
31+
32+
if (redirectiondata.get('expire')):
33+
if (
34+
datetime.datetime.now() > redirectiondata.get('expire')
35+
):
36+
return None
37+
38+
return (redirectiondata.get('data'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .csrf import CSRF as csrf
2+
from .redirect_internal import Redirect_Internal as redirect_internal
3+
4+
from .authentication import Authentication as authentication
5+
6+
__all__ = [
7+
'csrf',
8+
'redirect_internal',
9+
10+
'authentication',
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from functools import wraps
2+
3+
from flask import (
4+
redirect,
5+
)
6+
7+
import genericflaskwebapp as app
8+
9+
class Authentication:
10+
def login_required (
11+
redirectionroute,
12+
internalredirect=False,
13+
invert=False,
14+
**internalredirectiondata,
15+
):
16+
def Inner (api_function):
17+
@wraps(api_function)
18+
def wrapper (*args, **kwargs):
19+
logged_in = (
20+
app.backend.functionality.Authentication.state_logged_in_check()
21+
)
22+
23+
logged_in = (
24+
bool(logged_in[0])
25+
if (not invert)
26+
else
27+
bool(not logged_in[0])
28+
)
29+
30+
if (not logged_in):
31+
if (internalredirect):
32+
return app.backend.core.redirect_internal.redirect(
33+
redirectionroute,
34+
**internalredirectiondata,
35+
)
36+
37+
return redirect(redirectionroute)
38+
39+
return api_function(*args, **kwargs)
40+
41+
return wrapper
42+
return Inner
43+
44+
def get_logged_in_user ():
45+
def Inner (api_function):
46+
@wraps(api_function)
47+
def wrapper (*args, **kwargs):
48+
return api_function(
49+
*args,
50+
user=(
51+
app.backend.functionality.Authentication.get_logged_in_user()
52+
),
53+
**kwargs,
54+
)
55+
56+
return wrapper
57+
return Inner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from functools import wraps
2+
3+
import genericflaskwebapp as app
4+
5+
class CSRF:
6+
def csrf_protect (
7+
embedd=True,
8+
check=True, form=None,
9+
ontrap=None, ontrapcallable=False, ontrapembedd=False,
10+
):
11+
if (not (embedd or check)):
12+
raise Exception(
13+
'backend.decorators.csrf:csrf_protect:: csrf protection used but '
14+
+ 'not enabled !'
15+
)
16+
17+
def Inner (api_function):
18+
@wraps(api_function)
19+
def wrapper (*args, **kwargs):
20+
if (check
21+
and (not app.backend.security.csrf.check_csrf_token(form=form))
22+
):
23+
if (ontrap):
24+
if (ontrapembedd):
25+
return app.backend.security.csrf.embedd_token((
26+
ontrap()
27+
if (callable(ontrap) and ontrapcallable)
28+
else
29+
ontrap
30+
))
31+
32+
return (
33+
ontrap()
34+
if (callable(ontrap) and ontrapcallable)
35+
else
36+
ontrap
37+
)
38+
39+
return 'Request blocked !'
40+
41+
if (embedd):
42+
return app.backend.security.csrf.embedd_token(
43+
api_function(*args, **kwargs),
44+
)
45+
46+
return api_function(*args, **kwargs)
47+
48+
return wrapper
49+
return Inner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from functools import wraps
2+
3+
import genericflaskwebapp as app
4+
5+
class Redirect_Internal:
6+
def check (
7+
redirectionroute,
8+
):
9+
def Inner (api_function):
10+
@wraps(api_function)
11+
def wrapper (*args, **kwargs):
12+
return api_function(
13+
*args,
14+
redirectiondata=(app.backend.core.redirect_internal.check(
15+
redirectionroute,
16+
) or dict()),
17+
**kwargs,
18+
)
19+
20+
return wrapper
21+
return Inner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .authentication import Authentication
2+
from .user import User
3+
from .todo import ToDo
4+
5+
__all__ = [
6+
'Authentication',
7+
'User',
8+
'ToDo',
9+
]

0 commit comments

Comments
 (0)