Exemple #1
0
    def process_registration():

        form = RegistrationForm()

        if form.validate_on_submit():

            username = form.username_reg.data
            password = form.password_reg.data

            if Users.query.filter(Users.email == username).count():
                flash('Такой пользователь уже есть')
                logging.error('Такой пользователь уже есть')
                return redirect(url_for('registration'))

            new_user = Users(email=username)
            new_user.set_password(password)
            db.session.add(new_user)
            db.session.commit()

            flash('Вы успешно зарегистрировались')
            return redirect(url_for('index'))

        flash('Пароль не удовлетворяет требованиям. Повторите ввод')
        logging.error('Форма не провалидировалась, Ошибка в пароле.')
        return redirect(url_for('registration'))
Exemple #2
0
    def process_reg():
        form = RegistrationForm()
        if form.validate_on_submit():
            new_user = User(username=form.username.data,
                            email=form.email.data,
                            role='user')
            if form.first_name.data:
                new_user.first_name = form.first_name.data
            if form.last_name.data:
                new_user.last_name = form.last_name.data
            if form.city.data:
                new_user.city = form.city.data
            new_user.set_password(form.password.data)
            db.session.add(new_user)
            db.session.commit()
            flash('Вы успешно зарегистрировались')
            return redirect(url_for('login'))

        else:
            for field, errors in form.errors.items():
                for error in errors:
                    flash('Ошибка в поле {}: {}'.format(
                        getattr(form, field).label.text, error))

        return redirect(url_for('register'))
Exemple #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    db.create_all()

    def Key_api_generator():
        key_api = secrets.token_hex(16).encode('utf-8')
        return key_api

    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password,
                    key_api=Key_api_generator())
        db.session.add(user)
        db.session.commit()
        flash(
            'Your account has been created! You are now able to log in! An Account KEY  is sent to your email',
            'success')
        path = 'webapp/trained_img/' + user.username
        os.mkdir(path)
        user1 = user.username

        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #4
0
    def process_registration():
        form = RegistrationForm()
        if form.validate_on_submit():

            email = form.email.data
            username = form.username.data
            password = form.password_reg.data
            password_confirm = form.password_reg_confirm.data

            if Users.query.filter(Users.email == email).count():
                logging.error('Такой пользователь уже есть')
                flash('Такой пользователь уже есть')
                return redirect(url_for('login'))

            if not password == password_confirm:
                logging.error('Пароли не совпадают')
                flash('Пароли не совпадают. Повторите ввод')
                return redirect(url_for('registration'))

            new_user = Users(email=email, username=username)
            new_user.set_password(password)
            db.session.add(new_user)
            db.session.commit()

            flash('Вы успешно зарегистрировались')
            return redirect(url_for('login'))
        logging.error('Пароль не соответствует требованиям')
        flash('Пароль должен содержать хотя бы одну заглавную букву,'
              'хотя бы одну цифру и быть не менее 8 символов')
        return redirect(url_for('registration'))
Exemple #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        user.save()
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #6
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        wappdb.session.add(user)
        wappdb.session.commit()
        flash('Se ha registrado el usuario nuevo.')
        return redirect(url_for('index'))
    return render_template('register.html', title='Register', form=form)
Exemple #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        user.save()
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #8
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(username=form.username.data, password=form.password.data)

        db.session.add(user)
        db.session.commit()
        flash('Thanks for registering! Now you can login!')
        return redirect(url_for('auth.login'))
    return render_template('register.html', form=form)
Exemple #9
0
def registration():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('You are now registered user!')
        return redirect(url_for('login'))
    return render_template('registration.html', title='Register', form=form)
Exemple #10
0
def register():
    if current_user.is_authenticated: ## DEBUG: doens't work # TODO: if logged in redirect to home
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') # hashes entered password
        user = User(username=form.username.data, email=form.email.data, password=hashed_password) # create user instance with input from form
        db.session.add(user)
        db.session.commit() # adds user to database
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #11
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        new_user = User(form.username.data)
        new_user.set_password(form.password.data)
        db.session.add(new_user)
        db.session.commit()

        flash("Your user has been created, please login.", category='success')
        return redirect(url_for('.login'))

    return render_template('register.html', form=form)
Exemple #12
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(email=form.email.data, password=hashed_password)
        user.add()

        flash("Your account has been created! You are now able to log in",
              "success")
        return redirect(url_for("login"))
    return render_template("register.html", title="Register", form=form)
Exemple #13
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        user.new_id()
        wappdb.session.add(user)
        wappdb.session.commit()
        flash('New user has been registered.')
        login_user(user, remember=False)
        return redirect(url_for('index'))
    return render_template('register.html',
                           title='Discord Herald Registration',
                           form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(email=form.email.data, password=hashed_password)

        user.add()

        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    password_hash=hashed_pw,
                    email=form.email.data,
                    admin=False).save()
        flash('Account for ' + form.username.data + ' created successfully!',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Your Account has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)
Exemple #17
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data.lower(), email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been successfully created')
        return redirect(url_for('login'))
    return render_template('register.html',
                           title='New Account',
                           header_title='Create New Account',
                           form=form)
Exemple #18
0
def register():
    if current_user.is_authenticated:
        return redirect("/home")

    form = RegistrationForm()

    if form.validate_on_submit():

        user = User(username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("New user created")
        return redirect("/index")

    return render_template("register.html", form=form, title="Register")
Exemple #19
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f"Account created for {form.username.data}! You were logged in!",
              "success")
        login_user(user)
        next_page = request.args.get("next")
        return redirect(next_page) if next_page else redirect(url_for("home"))
    return render_template("register.html", form=form)
Exemple #20
0
 def process_reg():
     form = RegistrationForm()
     if form.validate_on_submit():
         new_user = User(username=form.username.data,
                         email=form.email.data,
                         role='user')
         new_user.set_password(form.password.data)
         db.session.add(new_user)
         db.session.commit()
         flash('Вы успешно зарегистрировались!')
         return redirect(url_for('login'))
     else:
         for field, errors in form.errors.items():
             for error in errors:
                 flash('Ошибка в поле "{}": - {}'.format(
                     getattr(form, field).label.text, error))
         return redirect(url_for('register'))
     flash('Пожалуйста, исправьте ошибки в форме')
     return redirect(url_for('register'))
Exemple #21
0
def register():
    if current_user.is_authenticated:
        flash('You are already logged in', 'success')
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # hash the pw
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        # crewate user
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw)
        # add user to DataBase
        db.session.add(user)
        db.session.commit()

        flash('Your account has been created, you may now log in', 'success')
        return redirect(url_for('login'))  #function name
    return render_template('register.html', title='Register', form=form)
Exemple #22
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()  #instanciating form class created in forms.py
    if form.validate_on_submit():  #to know if the account is created or not
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')  #hashing the password
        user = User(
            username=form.username.data,
            email=form.email.data,
            password=hashed_password,
            points=0
        )  #Creating a User instaciation who contain information enter in the form variable
        db.session.add(
            user)  #Adding the user to be ready to be commit in the database
        db.session.commit()  #Add the data to the database
        flash(
            'Your account has been created! You are now able to log in',
            'success'
        )  #if the form is correctly validate then show this message "account created..."
        return redirect(url_for('login'))  #and redirect to home page
    return render_template('register.html', title='Register', form=form)
def gettingstarted():
    if current_user.is_authenticated:
        return redirect(url_for("groceryLists"))

    rform = RegistrationForm()
    lform = LoginForm()

    if rform.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            rform.password.data).decode("utf-8")
        print(rform.password.data, type(rform.password.data))
        user = User(username=rform.username.data,
                    email=rform.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(
            f"Account created for {rform.username.data}! You were logged in!",
            "success")
        login_user(user)
        next_page = request.args.get("next")
        return redirect(next_page) if next_page else redirect(
            url_for("groceryLists"))

    if lform.validate_on_submit():
        user = User.query.filter_by(email=lform.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               lform.password.data):
            login_user(user)
            next_page = request.args.get("next")
            return redirect(next_page) if next_page else redirect(
                url_for("groceryLists"))
        else:
            flash("Login unsuccessful. Please check username and password",
                  "danger")

    return render_template("gettingstarted.html", rform=rform, lform=lform)
Exemple #24
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)