summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormontezdesousa <79287829+montezdesousa@users.noreply.github.com>2023-06-01 17:07:11 +0100
committerGitHub <noreply@github.com>2023-06-01 16:07:11 +0000
commit15397938621e55ea20aeccae506815dd891e34a3 (patch)
tree3899b899b40e26700066b2d457583d5adde7b6f5
parent6381abb57506141357b5f46ac2a08bb9450e822d (diff)
No guest if installer (#5076)
* no guest if installer * prevent guest if logout from account * this not true * rename reloop var * ask for email again if no email --------- Co-authored-by: James Maslek <jmaslek11@gmail.com>
-rw-r--r--openbb_terminal/account/account_controller.py36
-rw-r--r--openbb_terminal/account/show_prompt.py24
-rw-r--r--openbb_terminal/core/session/session_controller.py19
-rw-r--r--openbb_terminal/parent_classes.py7
-rw-r--r--openbb_terminal/terminal_controller.py16
5 files changed, 57 insertions, 45 deletions
diff --git a/openbb_terminal/account/account_controller.py b/openbb_terminal/account/account_controller.py
index 72c5903bba1..826aa28d5d5 100644
--- a/openbb_terminal/account/account_controller.py
+++ b/openbb_terminal/account/account_controller.py
@@ -7,6 +7,7 @@ from openbb_terminal.account.account_view import (
display_default_routines,
display_personal_routines,
)
+from openbb_terminal.account.show_prompt import set_show_prompt
from openbb_terminal.core.session import hub_model as Hub
from openbb_terminal.core.session.current_user import (
get_current_user,
@@ -25,37 +26,11 @@ from openbb_terminal.helper_funcs import check_positive
from openbb_terminal.menu import session
from openbb_terminal.parent_classes import BaseController
from openbb_terminal.rich_config import MenuText, console
-from openbb_terminal.terminal_helper import print_guest_block_msg
+from openbb_terminal.terminal_helper import is_installer, print_guest_block_msg
logger = logging.getLogger(__name__)
-__login_called = False
-
-
-def get_login_called():
- """Get the login/logout called flag.
-
- Returns
- -------
- bool
- The login/logout called flag.
- """
- return __login_called
-
-
-def set_login_called(value: bool):
- """Set the login/logout called flag.
-
- Parameters
- ----------
- value : bool
- The login/logout called flag.
- """
- global __login_called # pylint: disable=global-statement
- __login_called = value
-
-
class AccountController(BaseController):
"""Account Controller Class"""
@@ -175,7 +150,7 @@ class AccountController(BaseController):
console.print("[info]You are already logged in.[/info]")
else:
if ns_parser:
- set_login_called(True)
+ set_show_prompt(True)
@log_start_end(log=logger)
def call_logout(self, other_args: List[str]) -> None:
@@ -197,7 +172,10 @@ class AccountController(BaseController):
token=current_user.profile.get_token(),
cls=True,
)
- self.print_help()
+ if is_installer():
+ set_show_prompt(True)
+ else:
+ self.print_help()
@log_start_end(log=logger)
def call_clear(self, other_args: List[str]):
diff --git a/openbb_terminal/account/show_prompt.py b/openbb_terminal/account/show_prompt.py
new file mode 100644
index 00000000000..d481b041fde
--- /dev/null
+++ b/openbb_terminal/account/show_prompt.py
@@ -0,0 +1,24 @@
+__show_prompt = False
+
+
+def get_show_prompt():
+ """Get the show_prompt flag.
+
+ Returns
+ -------
+ bool
+ The show_prompt flag.
+ """
+ return __show_prompt
+
+
+def set_show_prompt(value: bool):
+ """Set the show_prompt flag.
+
+ Parameters
+ ----------
+ value : bool
+ The show_prompt flag.
+ """
+ global __show_prompt # pylint: disable=global-statement
+ __show_prompt = value
diff --git a/openbb_terminal/core/session/session_controller.py b/openbb_terminal/core/session/session_controller.py
index 60d40ad0ab5..bf173e43bf9 100644
--- a/openbb_terminal/core/session/session_controller.py
+++ b/openbb_terminal/core/session/session_controller.py
@@ -11,7 +11,7 @@ from openbb_terminal.core.session.session_model import (
login,
)
from openbb_terminal.rich_config import console
-from openbb_terminal.terminal_helper import bootup
+from openbb_terminal.terminal_helper import bootup, is_installer
def display_welcome_message():
@@ -30,9 +30,15 @@ def get_user_input() -> Tuple[str, str, bool]:
Tuple[str, str, bool]
The user email, password and save login option.
"""
- console.print(
- "[info]\nPlease enter your credentials or press <ENTER> for guest mode:[/info]"
- )
+
+ msg = "\nPlease enter your credentials"
+
+ if not is_installer():
+ msg += " or press <ENTER> for guest mode:"
+ else:
+ msg += ":"
+
+ console.print("[info]" + msg + "[/info]")
s: PromptSession = PromptSession()
@@ -53,7 +59,7 @@ def get_user_input() -> Tuple[str, str, bool]:
return email, password, remember
-def prompt(welcome=True):
+def prompt(welcome: bool = True):
"""Prompt and launch terminal if login is successful.
Parameters
@@ -69,7 +75,8 @@ def prompt(welcome=True):
while True:
email, password, remember = get_user_input()
if not email:
- return launch_terminal()
+ return prompt(welcome=False) if is_installer() else launch_terminal()
+
session = create_session(email, password, remember)
if isinstance(session, dict) and session:
return login_and_launch(session, remember)
diff --git a/openbb_terminal/parent_classes.py b/openbb_terminal/parent_classes.py
index ece1a7e9f14..2021cebffb5 100644
--- a/openbb_terminal/parent_classes.py
+++ b/openbb_terminal/parent_classes.py
@@ -23,6 +23,7 @@ from rich.markdown import Markdown
# IMPORTS INTERNAL
import openbb_terminal.core.session.local_model as Local
+from openbb_terminal.account.show_prompt import get_show_prompt
from openbb_terminal.core.completer.choices import build_controller_choice_map
from openbb_terminal.core.config.paths import HIST_FILE_PATH
from openbb_terminal.core.session import hub_model as Hub
@@ -1027,10 +1028,8 @@ class BaseController(metaclass=ABCMeta):
# Process the input command
self.queue = self.switch(an_input)
- if is_local() and an_input == "login":
- return ["login"]
- if not is_local() and an_input == "logout":
- return ["logout"]
+ if get_show_prompt() and an_input in ("login", "logout"):
+ return [an_input]
except SystemExit:
if not self.contains_keys(an_input):
diff --git a/openbb_terminal/terminal_controller.py b/openbb_terminal/terminal_controller.py
index 60acc3dc8fb..cc8f3ba3c59 100644
--- a/openbb_terminal/terminal_controller.py
+++ b/openbb_terminal/terminal_controller.py
@@ -23,9 +23,9 @@ from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.styles import Style
import openbb_terminal.config_terminal as cfg
-from openbb_terminal.account.account_controller import (
- get_login_called,
- set_login_called,
+from openbb_terminal.account.show_prompt import (
+ get_show_prompt,
+ set_show_prompt,
)
from openbb_terminal.common import biztoc_model, biztoc_view, feedparser_view
from openbb_terminal.core.config.paths import (
@@ -847,7 +847,11 @@ def terminal(jobs_cmds: Optional[List[str]] = None, test_mode=False):
break
try:
- if an_input in "login" and get_login_called() and is_auth_enabled():
+ if (
+ an_input in ("login", "logout")
+ and get_show_prompt()
+ and is_auth_enabled()
+ ):
break
# Process the input command
@@ -893,8 +897,8 @@ def terminal(jobs_cmds: Optional[List[str]] = None, test_mode=False):
console.print(f"[green]Replacing by '{an_input}'.[/green]")
t_controller.queue.insert(0, an_input)
- if an_input in "login" and get_login_called() and is_auth_enabled():
- set_login_called(False)
+ if an_input in ("login", "logout") and get_show_prompt() and is_auth_enabled():
+ set_show_prompt(False)
return session_controller.main()