Example #1
0
def show_register():

    form = RegisterUser()

    if form.validate_on_submit():

        username = form.username.data
        password = form.password.data
        first_name = form.first_name.data
        last_name = form.last_name.data
        email = form.email.data

        new_user = User(username=username,
                        password=password,
                        first_name=first_name,
                        last_name=last_name,
                        email=email)

        db.session.add(new_user)
        db.session.commit()

        session[USER_KEY] = new_user.toJSON()
        session['username'] = new_user.username

        #        return redirect("/secret")
        return redirect(f"/users/{new_user.username}")

    else:
        return render_template("register.html", form=form)
Example #2
0
def register():

    form = RegisterUser()

    if form.validate_on_submit():

        email = form.email.data
        password = form.password.data
        username = form.username.data

        try:
            form.check_mail(email)
        except ValidationError as error:
            return render_template('already_exist.html', error=repr(error))

        try:
            form.check_username(username)
        except ValidationError as error:
            return render_template('already_exist.html', error=repr(error))

        user = User(email, username, password, 'default.png')
        db.session.add(user)
        db.session.commit()

        user = User.query.filter_by(email=form.email.data).first()
        mail = user.email
        send_mail(mail)

        return redirect(url_for('login'))

    return render_template('register.html', form=form)
Example #3
0
def signup():
    form = RegisterUser()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        new_user = User.register(username, password, email)
        db.session.add(new_user)
        db.session.commit()
        session["user_id"] = new_user.id
        return redirect(url_for('user_profile', id=new_user.id))
    return render_template('signup.html', form=form)
Example #4
0
def register():
    form = RegisterUser()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        password = generate_password_hash(password=form.password.data,
                                          method='pbkdf2:sha256',
                                          salt_length=8)
        user = User(name=name, email=email, password=password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('get_all_posts'))
    return render_template("register.html", form=form)
Example #5
0
def register_user():
    """ form to register user """

    form = RegisterUser()

    if form.validate_on_submit():
        user = User.register_user(form)

        add_user_to_db(user)

        return redirect(f"/users/{user.username}")

    else:
        return render_template("register.html", form=form)
Example #6
0
def register():
    if not user_in_session():
        form = RegisterUser()
        error = None

        if form.validate_on_submit() and request.method == 'POST':
            email = form.email.data

            if not validate_email(email):
                username = form.username.data
                
                if not validate_username(username):       
                    password = sha256((form.password.data).encode())
                    password_confirm = sha256((form.password_confirm.data).encode())

                    if password.hexdigest() == password_confirm.hexdigest():
                        name = form.name.data
                        age = form.age.data


                        user = User(
                            name=name, 
                            age=age, 
                            email=email, 
                            username=username, 
                            password=password.hexdigest(),
                            created_at=datetime.now().date()
                        )
                        db.session.add(user)
                        db.session.commit()
                        
                        flash('Your account has been created successfully!')

                        return redirect(url_for('login'))
                    
                    else:
                        error = 'Passwords no match!'

                else:
                    error = 'Username already exist!'

            else:
                error = 'Email already exist!'

        return render_template('auth/register.html', form=form, error=error)
    
    else:
        abort(404)
Example #7
0
def process_user_registration():
    """ process the form and redirect to /secret"""
    form = RegisterUser()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        user = User.register(username, password, email, first_name, last_name)
        db.session.add(user)
        db.session.commit()

        session["username"] = user.username
        return redirect("/login")
    else:
        return render_template('register.html')
Example #8
0
def register():
    form = RegisterUser()
    if form.validate_on_submit():
        email = form.email.data
        if db.session.query(User).filter(User.email == email).first() == None:
            is_admin = False
            if db.session.query(User).count() == 0:
                is_admin = True
            user = User(name=form.name.data,
                        email=form.email.data,
                        is_admin=is_admin,
                        password=generate_password_hash(form.password.data,
                                                        salt_length=8))
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('get_all_posts'))
        else:
            flash("You've already signed with that email, log in instead!")
            return redirect(url_for("login"))
    else:
        return render_template("register.html", form=form)
Example #9
0
def register():
    form = RegisterUser()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        user = User.register(username=username,
                             password=password,
                             email=email,
                             first_name=first_name,
                             last_name=last_name)
        db.session.add(user)
        db.session.commit()

        session['username'] = user.username
        return redirect('/secret')
    else:
        return render_template('register.html', form=form)
Example #10
0
def register():
    form = RegisterUser()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        password = generate_password_hash(form.password.data,
                                          method='pbkdf2:sha256',
                                          salt_length=8)
        if not user:
            user = User(name=form.name.data,
                        email=form.email.data,
                        password=password)
            db.session.add(user)
            db.session.commit()
            login_user(user)
            return redirect(url_for("get_all_posts"))
        else:
            flash("You've already signed up with that email, log in instead!")
            return redirect((url_for("login")))
    return render_template("register.html",
                           form=form,
                           current_user=current_user)
Example #11
0
def register_user():
    """show and process registration form and add new user"""

    form = RegisterUser()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        new_user = User.register(username, password, email, first_name,
                                 last_name)

        if new_user:
            db.session.add(new_user)
            db.session.commit()
            session["username"] = new_user.username  # keep logged in
            return redirect(f'/users/{username}')

    return render_template("register.html", form=form)
Example #12
0
def display_register_form_and_handle_register_form():
    """Displays the register form and handles submitted forms"""

    form = RegisterUser()

    if form.validate_on_submit():
        user = User.register(
            **{
                key: value
                for (key, value) in form.data.items() if key != 'csrf_token'
            })
        db.session.add(user)
        try:
            db.session.commit()
            session['user_id'] = user.id
            return redirect(f'/users/{form.username.data}')
        except IntegrityError as error:
            flash(error.args[0][error.args[0].find("DETAIL"):])
            return render_template("register.html", form=form)

    else:
        return render_template("register.html", form=form)
Example #13
0
def register():
    form = RegisterUser()
    if form.validate_on_submit():
        flash('username="******",email requested ="%s",password="******"' %(form.username.data,form.email.data,form.password.data))
        return redirect('/index')
    return render_template('register.html', title='RegisterUser',form=form)