add asteriscs to password

This commit is contained in:
Diogo Sousa
2023-01-31 13:50:11 +00:00
parent 309e52e80e
commit 873477991b
4 changed files with 64 additions and 15 deletions

View File

@@ -1,13 +1,14 @@
import sys
from typing import Optional
import logging
import os
from matplotlib import pyplot
from prompt_toolkit import PromptSession
from prompt_toolkit.eventloop.inputhook import set_eventloop_with_inputhook
from prompt_toolkit.history import FileHistory
from openbb_terminal.core.config.paths import HIST_FILE_PATH
logger = logging.getLogger(__name__)
@@ -47,12 +48,10 @@ def inputhook(inputhook_context):
return False
history_file = os.path.join(os.path.expanduser("~"), ".openbb_terminal.his")
try:
if not is_jupyter() and not is_papermill():
session: Optional[PromptSession] = PromptSession(
history=FileHistory(history_file)
history=FileHistory(HIST_FILE_PATH)
)
set_eventloop_with_inputhook(inputhook)
else:

View File

@@ -1,7 +1,6 @@
"""Rich Module"""
__docformat__ = "numpy"
import getpass
import os
import json
from pathlib import Path
@@ -315,13 +314,9 @@ class ConsoleAndPanel:
else:
print(*args, **kwargs)
def input(self, *args, **kwargs):
self.print(*args, **kwargs, end="")
return input()
def getpass(self, *args, **kwargs):
self.print(*args, **kwargs, end="")
return getpass.getpass("")
# def input(self, *args, **kwargs):
# self.print(*args, **kwargs, end="")
# return input()
console = ConsoleAndPanel()

View File

@@ -1,14 +1,20 @@
from typing import Tuple
from prompt_toolkit import PromptSession
from prompt_toolkit.output.color_depth import ColorDepth
from openbb_terminal import terminal_controller
import openbb_terminal.session.local_model as Local
from openbb_terminal.session.session_model import (
LoginStatus,
color_message,
create_session,
get_color,
login,
)
from openbb_terminal.core.config.paths import PACKAGE_DIRECTORY
from openbb_terminal.rich_config import console
# pylint: disable=consider-using-f-string
def display_welcome_message():
"""Display welcome message"""
@@ -25,9 +31,20 @@ def get_user_input() -> Tuple[str, str, bool]:
The user email, password and save login option.
"""
console.print("\nPlease enter your credentials:", style="info")
email = console.input("> Email: ", style="menu")
password = console.getpass("> Password: ", style="menu")
save_str = console.input("> Remember me? (y/n): ", style="menu").lower()
s: PromptSession = PromptSession(color_depth=ColorDepth.TRUE_COLOR)
color = get_color()
email = s.prompt(
message=color_message("> Email: ", color),
)
password = s.prompt(
message=color_message("> Password: ", color),
is_password=True,
)
save_str = s.prompt(
message=color_message("> Remember me? (y/n): ", color), is_password=False
).lower()
save = False
if save_str == "y":
save = True

View File

@@ -5,11 +5,13 @@ import sys
import json
from enum import Enum
import matplotlib.pyplot as plt
from prompt_toolkit import HTML
import openbb_terminal.session.local_model as Local
import openbb_terminal.session.hub_model as Hub
from openbb_terminal.session.user import User
from openbb_terminal.helper_funcs import system_clear
from openbb_terminal.rich_config import console
from openbb_terminal.rich_config import CUSTOM_THEME
class LoginStatus(Enum):
@@ -89,3 +91,39 @@ def logout(cls: bool = False):
Local.remove_cli_history_file()
plt.close("all")
console.print("[green]\nLogout successful.[/green]")
def get_color() -> str:
"""Get prompt session
Returns
-------
str
The hex color.
"""
hex_color = "#ffffff"
c = CUSTOM_THEME.styles["menu"].color
if c:
rgb = c.triplet
if rgb:
hex_color = "#%02x%02x%02x" % (rgb.red, rgb.green, rgb.blue)
return hex_color
def color_message(msg: str, color: str) -> HTML:
"""Get colorized message
Parameters
----------
msg : str
The message.
color : str
The hex color.
Returns
-------
HTML
The HTML message.
"""
return HTML(f'<style fg="{color}">{msg}</style>')