Exemple #1
0
def createsuperuser(login=None, email=None, password=None):
    """ Create user with admin rights"""
    login = login or ask_input('Введите логин')
    email = email or ask_input('Введите адрес электронной почты')
    passwd = password or ask_input('Введите пароль', hidden=True)
    confirmation = password or ask_input('Подтвердите пароль', hidden=True)

    while passwd != confirmation:
        print('Пароли не совпадают! Похоже, вы опечатались.')
        while True:
            choice = input('Повторить ввод? (y/n) ').lower()
            if choice in 'yes':
                passwd = ask_input('Введите пароль', hidden=True)
                confirmation = ask_input('Подтвердите пароль', hidden=True)
                break
            elif choice in 'no':
                return
            else:
                print('Пожалуйста, ответьте y (yes) или n (no)')

    with disable_csrf(app):
        form = HelperForm(
            name='dummy',
            surname='dummy',
            password=passwd,
            confirmation=passwd,
        )
        # dodge filling obj_data , just like browser form filling
        # (Existence validation comes false positive)
        form.login.data = login
        form.email.data = email
        if not form.validate():
            errors = [err for field in form.errors.values() for err in field]
            for error in errors:
                print(error)
            return
        else:
            with app.app_context(), perform(
                name='createsuperuser',
                before='Creating user',
                fail='Error occured while creating user',
                after='Superuser has been succesfully created!',
            ):
                User.bl.create_superuser(login, passwd, email)
Exemple #2
0
def createsuperuser(login=None, email=None, password=None):
    """ Create user with admin rights"""
    login = login or ask_input('Введите логин')
    email = email or ask_input('Введите адрес электронной почты')
    passwd = password or ask_input('Введите пароль', hidden=True)
    confirmation = password or ask_input('Подтвердите пароль', hidden=True)

    while passwd != confirmation:
        print('Пароли не совпадают! Похоже, вы опечатались.')
        while True:
            choice = input('Повторить ввод? (y/n) ').lower()
            if choice in 'yes':
                passwd = ask_input('Введите пароль', hidden=True)
                confirmation = ask_input('Подтвердите пароль', hidden=True)
                break
            elif choice in 'no':
                return
            else:
                print('Пожалуйста, ответьте y (yes) или n (no)')

    with disable_csrf(app):
        form = HelperForm(
            name='dummy',
            surname='dummy',
            password=passwd,
            confirmation=passwd,
        )
        # dodge filling obj_data , just like browser form filling
        # (Existence validation comes false positive)
        form.login.data = login
        form.email.data = email
        if not form.validate():
            errors = [err for field in form.errors.values() for err in field]
            for error in errors:
                print(error)
            return
        else:
            with app.app_context(), perform(
                    name='createsuperuser',
                    before='Creating user',
                    fail='Error occured while creating user',
                    after='Superuser has been succesfully created!',
            ):
                User.bl.create_superuser(login, passwd, email)
Exemple #3
0
 def log_in(self, login="******"):
     # assume that login is equal to password
     credentials = {"login": login, "password": login}
     with disable_csrf(self.app):
         self.client.post(url_for("auth.login"), data=credentials)
Exemple #4
0
 def log_in(self, login='******'):
     # assume that login is equal to password
     credentials = {"login": login, "password": login}
     with disable_csrf(self.app):
         self.client.post(url_for("auth.login"), data=credentials)