diff --git a/indicators.py b/indicators.py index c6dd8a3..cc2a1b8 100644 --- a/indicators.py +++ b/indicators.py @@ -27,7 +27,7 @@ from dash import Dash, html, dcc, callback, Output, Input, State, no_update, ctx from waitress import serve from flask_caching import Cache from dash.exceptions import PreventUpdate -from dash_auth import OIDCAuth +from dash_auth import BasicAuth import yahoo_fin.stock_info as si from dotenv import load_dotenv import os @@ -57,7 +57,7 @@ def intelligent_loop_plots(sym : str, stk_data): """ price = stk_data["adjclose"] vol = stk_data["volume"] - stk = security(sym, price, vol) + stk = Security(sym, price, vol) rsi = stk.rsi() vorsi = stk.volume_rsi() @@ -166,55 +166,33 @@ def intelligent_loop_plots(sym : str, stk_data): return data, vol.to_frame('_VOL'), macd, rsi, plot_indicator -# VALID_USERNAME_PASSWORD_PAIRS = { -# 'ce16559af2caf7bb54bebd57a1602e29ada331b3356004265abeab0e568278cc': -# 'b4db36eb3f887ca0bc15de7feb0b41a9589b65dbd5325aedf1c76b3ee63b8871' -# } +VALID_USERNAME_PASSWORD_PAIRS = { + os.environ['USER1']:os.environ['PASS1'], + os.environ['USER2']:os.environ['PASS2'], +} -# def user_login(username, password): -# if VALID_USERNAME_PASSWORD_PAIRS.get(hash_password(username)) == hash_password(password): -# return True -# return False - -class OIDCAuthCustom(OIDCAuth): # overide OIDCAuth to get logged in user info - - def __init__(self, *args, **kwargs): +class Auth: + def __init__(self) -> None: self.username = None - super().__init__(*args, **kwargs) - def callback(self, idp: str): - return_value = super().callback(idp) + def user_login(self, username, password): + if VALID_USERNAME_PASSWORD_PAIRS.get(username) == hash_password(password): + self.username = username + return True + return False - client = self.get_oauth_client(idp) - self.username = client.userinfo().get("username") - # ... - - return return_value +auth = Auth() # Initialize the app app = Dash(__name__) -# dash_auth.BasicAuth( -# app, -# # VALID_USERNAME_PASSWORD_PAIRS, -# auth_func=user_login, -# secret_key="MK8dyS6PyDDuEuzrmqa7dJTJZ7eH2Jkh", -# ) - -# auth = OIDCAuth(app, secret_key=os.environ['SECRET_KEY']) - -auth = OIDCAuthCustom(app, secret_key=os.environ['SECRET_KEY']) - -auth.register_provider( - "stock", - token_endpoint_auth_method="client_secret_post", - client_id=os.environ['APP_ID'], - client_secret=os.environ['APP_SECRET'], - server_metadata_url=os.environ['SERVER_URL'], +BasicAuth( + app, +# VALID_USERNAME_PASSWORD_PAIRS, + auth_func=auth.user_login, + secret_key=os.environ['SECRET_KEY'], ) -# watchlist = get_watchlist(auth.username) -# symbols = (watchlist.iloc[:, 0] + " - " + watchlist.iloc[:, 1]).tolist() CACHE_CONFIG = {'CACHE_TYPE': 'SimpleCache'} cache = Cache() diff --git a/subroutines/__init__.py b/subroutines/__init__.py index 58fa1b3..277f3d7 100644 --- a/subroutines/__init__.py +++ b/subroutines/__init__.py @@ -1,6 +1,6 @@ # Define the __all__ variable -__all__ = ["security", "remove_from_db", "insert_into_db", "get_watchlist"] +__all__ = ["Security", "remove_from_db", "insert_into_db", "get_watchlist", "hash_password"] # Import the submodules -from .security import security, get_crossing, get_sma_slope -from .dbutil import remove_from_db, insert_into_db, get_watchlist +from .security import Security, get_crossing, get_sma_slope +from .dbutil import remove_from_db, insert_into_db, get_watchlist, hash_password diff --git a/subroutines/security.py b/subroutines/security.py index ef68fdb..67da986 100644 --- a/subroutines/security.py +++ b/subroutines/security.py @@ -2,7 +2,7 @@ import numpy as np from numpy.fft import fft, ifft import scipy.signal as sig -class security: +class Security: """ This can be a list of stocks, bonds, or otherinvestment vehicles. price - Pandas DataFrame with datetime as index sorted to chronical order