-
Notifications
You must be signed in to change notification settings - Fork 134
refactor server.py for using Blueprint #3033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JanEisermann
wants to merge
51
commits into
Open-MSS:develop
Choose a base branch
from
JanEisermann:inkludingBP
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
1fafef2
implementation of BluePrint, fixed local dependencies of pytest "test…
JanEisermann f19cf8d
implementation of BluePrint, fixed local dependencies of pytest "test…
JanEisermann 7ed2570
moved file_exists to mslib.utils, moved the constants to the beginnin…
JanEisermann c62ad8b
added Blueprints for mscolab
JanEisermann b11e00b
fixxed flake8 errors
JanEisermann ce2ef58
fixed incompleted address errors
JanEisermann 18ff5ed
added Jan Eisermann to the authors list
JanEisermann 2f8f139
moved methods to the rigth blueprint path and added description to th…
JanEisermann 570f809
moved Jan Eisermann to the right place in the author list
JanEisermann 80c25b7
moved each blueprint in mscolab and mswms into its own directory (inc…
JanEisermann aea0401
corrected the directory path in the doc string
JanEisermann efb2dc6
renamed from status.html to status_password.html
JanEisermann 47e7c3e
added doc string
JanEisermann b9393d8
corrected doc string
JanEisermann db4a8bc
moved into blueprins.docs.templates (mscolab and mswms)
JanEisermann f4ef61f
moved the routes into the respective blueprints.
JanEisermann 0a6b15e
added content.html to mslib.mswms.blueprints.gallery.templates.gallery
JanEisermann d6f1716
moved APP.routes('/') from mslib/mscolab/server.py to docs Blueprint
JanEisermann ed5d2de
moved APP.routes('/') from mslib/mswms/wms to docs Blueprint
JanEisermann 4fa09d5
moved static directory to blueprints
JanEisermann d7227ea
moved static directory to blueprints
JanEisermann cb54df2
fixed the Mission Support System
JanEisermann c843548
fixed the Mission Support System Gallary
JanEisermann a1de8d0
fixed URL for reset_request
JanEisermann 067fb8d
changed imprint = None and gdpr = None
JanEisermann ae5f232
fixed URLs
JanEisermann 5ae62ea
fixed URL
JanEisermann 82e4476
added blank line
JanEisermann 2955043
changed that current_app is used instead of APP
JanEisermann 09abb66
fixed flake8 errors
JanEisermann fde16dc
changed that current_app is used instead of APP
JanEisermann ee1d8b4
Merge branch 'develop' into inkludingBP
JanEisermann a84d194
origin default settings
JanEisermann 3093e2a
fixed SAML2 login
JanEisermann 80a67fc
catch EmailUndeliverableError
JanEisermann 3ea56e1
moved the mscolab-coupled helpers to mscolab.auth
JanEisermann 7b6a5d7
added description header
JanEisermann 8c60015
tried to remove workarounds for circular Imports (does not work at th…
JanEisermann 8547d43
removed workarounds for circular Imports
JanEisermann 476d815
renamed getMail to get_mail
JanEisermann d94a344
moved Blueprint registrations into create_app
JanEisermann 895c3d2
corrected status code
JanEisermann a396cbc
fixed reset_request URL in status_password template context
JanEisermann cda0bae
added default values for imprint and gdpr
JanEisermann 14f074e
Typo and removed dead parameter
JanEisermann b29626d
fixed attribute error by ensuring jump has .size before access
JanEisermann 36b1cdc
fixed gallery default tab logic to prioritize "Top" plot type when av…
JanEisermann 76b1e42
register_user is now imported from one location
JanEisermann f6775ea
flake8
JanEisermann 174ea41
removed validate_email since the import is no longer used
JanEisermann f9f4a52
explicit url path for each blueprint
JanEisermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
|
|
||
| mslib.utils.auth | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| handles passwords from the keyring for login and http_auuth | ||
|
|
||
|
|
||
| To better understand of the code, look at the 'ships' example from | ||
| chapter 14/16 of 'Rapid GUI Programming with Python and Qt: The | ||
| Definitive Guide to PyQt Programming' (Mark Summerfield). | ||
|
|
||
| This file is part of MSS. | ||
|
|
||
| :copyright: Copyright 2023 Reimar Bauer | ||
| :copyright: Copyright 2023-2026 by the MSS team, see AUTHORS. | ||
| :license: APACHE-2.0, see LICENSE for details. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
|
|
||
| import datetime | ||
| import functools | ||
| import logging | ||
|
|
||
| import email_validator | ||
| import sqlalchemy | ||
| from flask import current_app, request, abort, g | ||
| from itsdangerous import URLSafeTimedSerializer, BadSignature | ||
|
|
||
| from mslib.mscolab.conf import setup_saml2_backend | ||
| from mslib.mscolab.models import User | ||
|
|
||
|
|
||
| def check_login(emailid, password): | ||
| try: | ||
| user = User.query.filter_by(emailid=str(emailid)).first() | ||
| except sqlalchemy.exc.OperationalError as ex: | ||
| logging.debug("Problem in the database (%ex), likely version client different", ex) | ||
| return False | ||
| if user is not None: | ||
| if current_app.config['MAIL_ENABLED']: | ||
| if user.confirmed: | ||
| if user.verify_password(password): | ||
| return user | ||
| else: | ||
| if user.verify_password(password): | ||
| return user | ||
| return False | ||
|
|
||
|
|
||
| def register_user(email, password, username, fullname): | ||
| if len(str(email.strip())) == 0 or len(str(username.strip())) == 0: | ||
| return {"success": False, "message": "Your username or email cannot be empty"} | ||
| is_valid_username = True if username.find("@") == -1 else False | ||
| try: | ||
| # ToDo verify what changed for check_deliverability | ||
| email_validator.validate_email(email, check_deliverability=current_app.config['MAIL_ENABLED']) | ||
| except (email_validator.exceptions.EmailSyntaxError or email_validator.exceptions.EmailUndeliverableError): | ||
| return {"success": False, "message": "Your email ID is not valid!"} | ||
| if not is_valid_username: | ||
| return {"success": False, "message": "Your username cannot contain @ symbol!"} | ||
| user_exists = User.query.filter_by(emailid=str(email)).first() | ||
| if user_exists: | ||
| return {"success": False, "message": "This email ID is already taken!"} | ||
| user_exists = User.query.filter_by(username=str(username)).first() | ||
| if user_exists: | ||
| return {"success": False, "message": "This username is already registered"} | ||
| fm = current_app.extensions['fm'] | ||
| user = User(email, username, password, fullname) | ||
| result = fm.modify_user(user, action="create") | ||
| return {"success": result} | ||
|
|
||
|
|
||
| def verify_user(func): | ||
| @functools.wraps(func) | ||
| def wrapper(*args, **kwargs): | ||
| try: | ||
| user = User.verify_auth_token(request.args.get('token', request.form.get('token', False))) | ||
| except TypeError: | ||
| logging.debug("no token in request form") | ||
| abort(404) | ||
| if not user: | ||
| return "False" | ||
| else: | ||
| # saving user details in flask.g | ||
| if current_app.config['MAIL_ENABLED']: | ||
| if user.confirmed: | ||
| g.user = user | ||
| return func(*args, **kwargs) | ||
| else: | ||
| return "False" | ||
| else: | ||
| g.user = user | ||
| return func(*args, **kwargs) | ||
| return wrapper | ||
|
|
||
|
|
||
| def confirm_token(token, expiration=3600): | ||
| serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY']) | ||
| try: | ||
| email = serializer.loads( | ||
| token, | ||
| salt=current_app.config['SECURITY_PASSWORD_SALT'], | ||
| max_age=expiration | ||
| ) | ||
| except (IOError, BadSignature): | ||
| return False | ||
| return email | ||
|
|
||
|
|
||
| def generate_confirmation_token(email): | ||
| serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY']) | ||
| return serializer.dumps(email, salt=current_app.config['SECURITY_PASSWORD_SALT']) | ||
|
|
||
|
|
||
| def get_idp_entity_id(selected_idp): | ||
| """ | ||
| Finds the entity_id from the configured IDPs | ||
| :return: the entity_id of the idp or None | ||
| """ | ||
| for config in setup_saml2_backend.CONFIGURED_IDPS: | ||
| if selected_idp == config['idp_identity_name']: | ||
| idps = config['idp_data']['saml2client'].metadata.identity_providers() | ||
| only_idp = idps[0] | ||
| entity_id = only_idp | ||
| return entity_id | ||
| return None | ||
|
|
||
|
|
||
| def create_or_update_idp_user(email, username, token, authentication_backend): | ||
| """ | ||
| Creates or updates an idp user in the system based on the provided email, | ||
| username, token, and authentication backend. | ||
| :param email: idp users email | ||
| :param username: idp users username | ||
| :param token: authentication token | ||
| :param authentication_backend: authenticated identity providers name | ||
| :return: bool : query success or not | ||
| """ | ||
| fm = current_app.extensions['fm'] | ||
| user = User.query.filter_by(emailid=email).first() | ||
| if not user: | ||
| # using an IDP for a new account/profile, e-mail is already verified by the IDP | ||
| confirm_time = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(seconds=1) | ||
| user = User(email, username, password=token, confirmed=True, confirmed_on=confirm_time, | ||
| authentication_backend=authentication_backend) | ||
| result = fm.modify_user(user, action="create") | ||
| else: | ||
| user.authentication_backend = authentication_backend | ||
| user.hash_password(token) | ||
| result = fm.modify_user(user, action="update_idp_user") | ||
| return result | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.