Exemple #1
0
def name():
    while True:
        name = input(theme.input("Name (e.g. Robert Schulz): "))
        if validate.name(name) == Answer.IN_WRONG_FORMAT:
            console_log.warning("Name should only contain charachters.")
        else:
            return name
Exemple #2
0
def email():
    while True:
        email = input(theme.input("Email: "))
        if validate.email(email) == Answer.IN_WRONG_FORMAT:
            console_log.warning("Invalid email format, please try again.")
        else:
            return email
Exemple #3
0
def phone_number():
    while True:
        phone_number = input(
            theme.input("Phone Number: (e.g. +4915574461441): "))
        if validate.phone_number(phone_number) == Answer.IN_WRONG_FORMAT:
            console_log.warning("Phone number should only contain 12 digits")
        else:
            return phone_number
Exemple #4
0
def option():
    while True:
        try:
            option = int(input(theme.input("Option: ")))
            if validate.option(option) == Answer.IN_RIGHT_FORMAT:
                return option
            console_log.warning("Wrong option, try again")
        except:
            console_log.warning("Please input only numbers")
Exemple #5
0
def password(input_text: str):
    while True:
        pwd = input(theme.input(input_text))
        if validate.password(pwd) == Answer.IN_WRONG_FORMAT:
            console_log.warning(
                "Passwords length should be min. 4 and max. 8 and characters only"
            )
        else:
            return pwd
Exemple #6
0
def try_again():
    while True:
        answer = input(theme.yellow_bold("Do you want to try again? (y/n): "))
        if answer.lower() == "n" or answer.lower() == "no":
            console_log.statement("See you.")
            return Answer.NO
        elif answer.lower() == "y" or answer.lower() == "yes":
            return Answer.YES
        console_log.warning(
            f"{answer} is not a proper answer. Please try again.")
def forgot_password():
    while True:
        phone_number = terminal_read.phone_number()
        user = user_services.get_user_by_phone_number(phone_number)
        if user == Instance.DOES_NOT_EXIST:
            console_log.warning(
                f"{phone_number} does not exists. Please try again.")
            continue

        process = sms.send_password(phone_number, user.get_password())

        if process == Process.FAILED:
            return console_log.warning("Your phone number doesn't exist.")
        console_log.success(user.messages.SUCCESSFULLY_SENT_SMS)
        break
def register():
    name = terminal_read.name()

    while True:
        email = terminal_read.email()
        user = user_services.get_user_by_email(email)
        if user != Instance.DOES_NOT_EXIST:
            console_log.warning(
                f'{email} does already exist. Please try again.')
            continue
        break

    pwd = terminal_read.password("Password (min. 4 and max. 8 characters): ")
    phone_number = terminal_read.phone_number()

    user = User(generate.random_id(), name, email, pwd, phone_number)
    user_services.add_user_to_json(user)
    console_log.success(user.messages.SUCCESSFULLY_REGISTERED)
from services import auth_services
from utils import console_log
from utils import terminal_read
from enums.option import Option

console_log.headline("welcome")
console_log.options()

option = terminal_read.option()

if option == Option.LOGIN.value:
    console_log.headline("login")
    auth_services.login()

elif option == Option.REGISTER.value:
    console_log.headline("register")
    auth_services.register()

elif option == Option.FORGOT_PASSWORD.value:
    console_log.headline("forgot password")
    auth_services.forgot_password()

elif option == Option.RESET_PASSWORD.value:
    console_log.headline("reset password")
    auth_services.reset_password()

else:
    console_log.warning(f'Option doesn\'t exist')