Skip to content
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

Minor fixes on login #4234

Merged
merged 16 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions openbb_terminal/base_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from typing import Any, Callable, List, Literal, Optional

from dotenv import load_dotenv
import dotenv
from rich.console import Console

from openbb_terminal.core.config.paths import (
Expand Down Expand Up @@ -98,22 +98,29 @@ def strtobool(val):


def load_dotenv_and_reload_configs():
"""Loads the dotenv files in the following order:
"""
Loads the dotenv files

openbb_terminal modules are reloaded to refresh config files with new env,
otherwise they will use cache with old variables.
"""
load_dotenv()
reload_openbb_config_modules()


def load_dotenv():
"""
Loads the dotenv files in the following order:
1. Repository .env file
2. Package .env file
3. User .env file

This allows the user to override the package settings with their own
settings, and the package to override the repository settings.

openbb_terminal modules are reloaded to refresh config files with new env,
otherwise they will use cache with old variables.
"""
load_dotenv(REPOSITORY_ENV_FILE, override=True)
load_dotenv(PACKAGE_ENV_FILE, override=True)
load_dotenv(USER_ENV_FILE, override=True)

reload_openbb_config_modules()
dotenv.load_dotenv(REPOSITORY_ENV_FILE, override=True)
dotenv.load_dotenv(PACKAGE_ENV_FILE, override=True)
dotenv.load_dotenv(USER_ENV_FILE, override=True)


def reload_openbb_config_modules():
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/session/hub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from openbb_terminal.rich_config import console

REGISTER_URL = "https://my.openbb.dev/register"
BASE_URL = "https://payments.openbb.dev/"
# BASE_URL = "http://127.0.0.1:8000/"
# BASE_URL = "https://payments.openbb.dev/"
BASE_URL = "http://127.0.0.1:8000/"
TIMEOUT = 15

CONNECTION_ERROR_MSG = "[red]Connection error.[/red]"
Expand Down
11 changes: 5 additions & 6 deletions openbb_terminal/session/sdk_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ def login(
session = Local.get_session()

if not session:
console.print("No local session found. Creating new session.")
session = get_session(email, password, token, keep_session)
else:
console.print("Using saved session to login.")
console.print("Using local session to login.")

if session_model.login(session) in [
session_model.LoginStatus.FAILED,
session_model.LoginStatus.NO_RESPONSE,
]:
raise Exception("Login failed.")
status = session_model.login(session)
if status != session_model.LoginStatus.SUCCESS:
raise Exception(f"Login failed with status `{status}`.")

console.print("[green]Login successful.[/green]")

Expand Down
3 changes: 3 additions & 0 deletions openbb_terminal/session/session_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LoginStatus(Enum):
SUCCESS = "success"
FAILED = "failed"
NO_RESPONSE = "no_response"
UNAUTHORIZED = "unauthorized"


def create_session(email: str, password: str, save: bool) -> dict:
Expand Down Expand Up @@ -84,6 +85,8 @@ def login(session: dict) -> LoginStatus:
else None
)
return LoginStatus.SUCCESS
if response.status_code == 401:
return LoginStatus.UNAUTHORIZED
return LoginStatus.FAILED
return LoginStatus.NO_RESPONSE

Expand Down
11 changes: 5 additions & 6 deletions openbb_terminal/terminal_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,11 @@ def parse_args_and_run():
" to see testing argument options."
),
)
if is_auth_enabled():
parser.add_argument(
"--login",
action="store_true",
help="Go to login prompt.",
)
parser.add_argument(
"--login",
action="store_true",
help="Go to login prompt.",
)
# The args -m, -f and --HistoryManager.hist_file are used only in reports menu
# by papermill and that's why they have suppress help.
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ authors = ["Didier Rodrigues Lopes"]
packages = [
{ include = "openbb_terminal" },
]
include = ["terminal.py"]
readme = "website/content/sdk/quickstart/installation.md"
homepage = "https://openbb.co"
repository = "https://github.com/OpenBB-finance/OpenBBTerminal"
documentation = "https://docs.openbb.co/sdk"

[tool.poetry.scripts]
openbb = 'openbb_terminal.terminal_controller:parse_args_and_run'
openbb = 'terminal:main'

[tool.poetry.dependencies]
python = "^3.8,<3.11, !=3.9.7"
Expand Down
9 changes: 8 additions & 1 deletion terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from openbb_terminal.base_helpers import load_dotenv_and_reload_configs
from openbb_terminal.terminal_helper import is_auth_enabled

if __name__ == "__main__":
# pylint: disable=import-outside-toplevel


def main():
multiprocessing.freeze_support()
sent_args = sys.argv[1:]

Expand All @@ -21,3 +24,7 @@
session_controller.main()
else:
session_controller.launch_terminal()


if __name__ == "__main__":
main()