Exemplo n.º 1
0
def register_page():
    # I need to have the form imported in order to be able to use it
    form = RegisterForm()
    # this function will execute 2 actions: 1) validate_ any fields that I have in forms, and
    # 2) then execute the on_submit function
    if form.validate_on_submit():
        user_to_create = User(
            username=form.username.data,
            email_address=form.email_address.data,
            # password_hash =  form.password1.data   )
            password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()

        # log the new user
        login_user(user_to_create)
        # inform the user is logged
        flash(
            f"Account created successfully! You are now logged in as {user_to_create.username}",
            category='success')

        return redirect(url_for('market_page'))

    # form.errors is a dictionary that has all the fails on the form validations declared in the form (form.py/RegisterForm)
    if form.errors != {}:
        for err_msg in form.errors.values():
            # print(f'There was an error with creating a user: {err_msg}')
            # I can add a category of the flash BC maybe I just want to inform
            # I'm sending the category "danger" BC bootstraps have one, So that I can customize the message
            flash(f'There was an error with creating a user: {err_msg}',
                  category='danger')

    return render_template('register.html', form=form)
Exemplo n.º 2
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                                email_address=form.email_address.data,
                                password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors != {}: # If there are no errors from the validations
        for err_msg in form.errors.values():
            flash(f'There was an error with creating a user: {err_msg}', category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 3
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password = form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors:  #form.errors provides a dictionary.
        for err_msg in form.errors.values():
            flash(f'Error occured in creating the user: {err_msg}' , category='danger') 

    return render_template('register.html',form = form)
Exemplo n.º 4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_adress=form.email_adress.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market'))
    if form.errors != {}:
        for err_msg in form.errors.values():
            flash(f'Hubo un error: {err_msg}', category='danger')

    return render_template('register.html', form=form)
Exemplo n.º 5
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email=form.email.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(f'Account created successly! You are now logged in as: {user_to_create.username}', category='success')
        return redirect(url_for('market_page'))
    if form.errors != {}:
        for err in form.errors.values():
            flash(f'Error from create user: {err}', category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 6
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password=form.password1.data,
                              ) #changed from password_hash to password to avoid plain text passwording
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors != {}:  #If no errors arise within the conditionals in forms.py
        for err_msg in form.errors.values():
            flash(f'There was an error with creating a user:{err_msg}', category='danger')

    return render_template('register.html', form=form)
Exemplo n.º 7
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit(
    ):  #Check if the user has clicked the submit button from RegisterForm. This if block should contain requirements
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password_hash=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors != {}:  #If there are errors from the validation
        for err_msg in form.errors.values():
            flash(f'There was an error with creating a user {err_msg}',
                  category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 8
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(
            f'Accounr created successfully! You are logged in as: {user_to_create.username}',
            category='success')
        return redirect(url_for('market_page'))
    for err_msg in form.errors.values():
        flash(err_msg[0], category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 9
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(f"Account created successfully! You are now logget in as: {user_to_create.username}", category="success")

        return redirect(url_for("market_page"))
    if form.errors != {}:
        for err_msg in form.errors.values():
            flash(f"There was an error with creating an user: {err_msg}", category="danger")

    return render_template("register.html", form=form)
Exemplo n.º 10
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username = form.username.data,
                              email_address = form.email_address.data,
                              password = form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(f"Account created. You are now logged in as {user_to_create.username.capitalize()}",category='success')

        return redirect(url_for('market_page'))
    if form.errors != {}: #If there are no errors from validations
        for err_msg in form.errors.values():
            flash(f'{err_msg}',category='danger')

    return render_template('register.html',form=form)
Exemplo n.º 11
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email=form.email.data,
                              password=form.password.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(f'User created! Welcome {user_to_create.username}!',
              category='success')
        return redirect(url_for('market'))
    if form.errors != {}:
        for err_msg in form.errors.values():
            flash(f"There was an error with creating a user: {err_msg}",
                  category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 12
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        create_user = User(username=form.username.data,
                           email_address=form.email_address.data,
                           password=form.password.data)
        db.session.add(create_user)
        db.session.commit()
        login_user(create_user)
        flash(f'Success! You are now Registered! as: {form.username.data}',
              category='success')
        return redirect(url_for('market_page'))
    if form.errors != {}:
        for err_msg in form.errors.values():
            flash(f'There was an error creating user {err_msg}',
                  category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 13
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(name=form.username.data,
                    username=form.username.data.lower(),
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created for {form.username.data}! You can now log in',
              'info')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form)
Exemplo n.º 14
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                            email_address=form.email_address.data,
                            password=form.password1.data)
        db.session.add(user_to_create)  
        db.session.commit() 

        login_user(user_to_create)
        flash(f"Account created successfully! You are now logged in as {user_to_create.username}", category='success')

        return redirect(url_for('market_page'))
    if form.errors != {}: #if there are not errors from the validation
        for err_msg in form.errors.values():
            # category danger o jinja vai entender que é pra erro 
            flash(f' There was an error with creating a user: {err_msg}', category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 15
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email=form.email_address.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(
            f"Cuenta creada exitosamente, ya esta logeado como {user_to_create.username}",
            category='success')
        return redirect(url_for('market_page'))
    if form.errors != {}:  #si no hay errores desde las validaciones
        for err_msg in form.errors.values():
            flash(f'hubo un error al crear el usuario: {err_msg}',
                  category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 16
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password_hash=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors!={}: #If there are not errors from the validations
        for err_msg in form.errors.values():
            flash(f'There was an error while creating the user: {err_msg}',category='danger')
    return render_template('register.htm', form=form)


#@app.route('/about/<username>')
#def about_page(username):
#    return f'<h1>This is the about page of {username}</h1>'
Exemplo n.º 17
0
def register_page():
    #importing all user fields from forms.py
    form = RegisterForm()
    #After user enters the details for a new user creation
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password_hash=form.password1.data)
        #Adding to database and then committing
        db.session.add(user_to_create)
        db.session.commit()
        return redirect(url_for('market_page'))
    if form.errors != {}:
        for err_message in form.errors.values():
            flash(f'There was an error with creating a User: {err_message}',
                  category='danger')
    # 'forms' used in register.html to access data from forms.py under RegisterForm class
    return render_template('register.html', forms=form)
Exemplo n.º 18
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        print("VALIDATING")
        user_to_create = User(username=form.username.data,
                              email=form.email.data,
                              name=form.name.data,
                              password=form.confirm_password.data)
        db.session.add(user_to_create)
        db.session.commit()
        flash(
            f"Successfully Registered,You are logged in as {user_to_create.username}",
            category="success")
        return redirect(url_for('market'))
    if form.errors != {}:
        for error_msg in form.errors.values():
            flash(f'There was an error creating the user {error_msg}',
                  category='danger')
    return render_template('register.html', form=form, title="Register")
Exemplo n.º 19
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()

        # Login user when created
        login_user(user_to_create)
        flash(
            f'Account created successfully. Now logged in as: {user_to_create.username}',
            category='success')
        return redirect(url_for('market'))
    if form.errors != {}:  # If there are mo errors from validations
        for err_msg in form.errors.values():
            flash(f'There was an error while creating a user: {err_msg}',
                  category='danger')
    return render_template('register.html', form=form)
Exemplo n.º 20
0
def register(request):
    form_class = AdminRegistrationForm if request.user and request.user.is_admin else RegistrationForm
    form = form_class(request.POST or None)
    if form.is_valid():
        user = User(
            login=form.cleaned_data['login'],
            email=form.cleaned_data['email'],
            salt=''.join(random.choice(string.letters) for i in range(10)),
        )
        user.password = user.get_password_hash(form.cleaned_data['password'])
        if 'is_admin' in form.cleaned_data:
            user.is_admin = form.cleaned_data.get('is_admin')
        user.save()
        return redirect('index')
    return direct_to_template(request, 'registration.html', {'form': form})
Exemplo n.º 21
0
def register_page():
    form = RegisterForm()
    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              password=form.password1.data,
                              email_address=form.email_address.data)
        db.session.add(user_to_create)
        db.session.commit()
        login_user(user_to_create)
        flash(
            f'User account created successfully ! You are now logged in with {user_to_create.username}',
            category='success')
        return redirect(url_for('market_page'))

    # if there are validation errors
    if form.errors != {}:
        for error_msg in form.errors.values():
            flash(f'There was an error while creating user : {error_msg}',
                  category='danger')

    return render_template("register.html", form=form)
Exemplo n.º 22
0
def register_page():
    form = RegisterForm()
    context = {"form": form}

    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email=form.email.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        flash(f'Success! You are logged in as {user_to_create.username}',
              'success')
        db.session.commit()
        login_user(user_to_create)
        return redirect(url_for('market_page'))

    if form.errors != {}:
        for err_msg in form.errors.values():
            flash('Error creating user : '******'danger')

    return render_template("register.html", **context)
Exemplo n.º 23
0
def register_page():
    form = RegisterForm()

    if form.validate_on_submit():
        user_to_create = User(username=form.username.data,
                              email_address=form.email_address.data,
                              password=form.password1.data)
        db.session.add(user_to_create)
        db.session.commit()

        login_user(user_to_create)
        flash(
            "Succesfully created account! You are now logged in as {}".format(
                user_to_create.username),
            category="success")
        return redirect(url_for("market_page"))

    if form.errors != {}:
        for err_msg in form.errors.values():
            flash("Failed to create user: {}".format(err_msg),
                  category="danger")

    return render_template("register.html", form=form)