Example #1
0
def add_user():

    form = RegisterForm()

    blog = Blog.query.all()

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

            salt = bcrypt.gensalt()
            hashed_password = bcrypt.hashpw(form.password.data.encode('utf8'),
                                            salt)

            fullname = form.fullname.data
            email = form.email.data
            username = form.username.data
            password = hashed_password
            is_author = True
            is_admin = form.is_admin.data
            is_active = True

            author = Author(fullname, email, username, password, is_author,
                            is_admin, is_active)

            db.session.add(author)
            db.session.commit()

            flash('User added successfully')

            return redirect(url_for('admin_app.admin'))

    return render_template('/author/register.html', form=form, blog=blog)
Example #2
0
def register():
    form = RegisterForm()
    data = request.form

    if form.validate_on_submit():
        return redirect(url_for('success'))

    return render_template('author/register.html', form=form)
Example #3
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        author = Author(form.fullname.data, form.email.data,
                        form.username.data, hashed_password, False)
        db.session.add(author)
        db.session.commit()
        return redirect('/success')
    return render_template('author/register.html', form=form)
Example #4
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).limit(1)
        # checking if username already exists
        if author.count():
            error = "Username already exists. Please choose another username"
            return render_template('author/register.html', form = form)
        else:
        
            return redirect(url_for('success'))
    return render_template('author/register.html', form = form)    
Example #5
0
def resetpassword():
    form = RegisterForm()
    error = ""
    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            salt = bcrypt.gensalt()
            hashed_password = bcrypt.hashpw(form.password.data, salt)
            author.password = hashed_password
            setattr(author, 'password', hashed_password)
            db.session.commit()
            return redirect(url_for('success', msg="Password Reset"))
    return render_template('author/register.html', form=form, action="reset")
Example #6
0
def editbio():
    form = RegisterForm()
    error = ""
    if form.validate_on_submit():
        print("validated")
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            newbio = form.bio.data
            if newbio > ' ':
                setattr(author, 'bio', newbio)
                db.session.commit()
                return redirect(url_for('success', msg="Bio updated"))
    print("invalid")
    return render_template('author/register.html', form=form, action="edit")
Example #7
0
def register():
    form = RegisterForm()
    error = None
    #get_flashed_messages()
    if form.validate_on_submit():
        author = Author(form.fullname.data, form.email.data,
                        form.username.data, form.password.data, True)
        error = flush_commit(author)
        if error:
            return render_template('author/register.html',
                                   form=form,
                                   error=error)
        else:
            return redirect(url_for('success'))
    else:
        return render_template('author/register.html', form=form, error=error)
def register():
    form=RegisterForm()
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        author=Author(
            form.fullname.data,
            form.email.data,
            form.username.data,
            hashed_password,
            False
            )
        db.session.add(author)
        db.session.commit()
        return redirect(url_for('success'))
    return render_template('author/register.html', form=form)
def editbio():
    form = RegisterForm()
    error = ""
    message = ""
    datachanged = 0
    #pdb.set_trace()
    if form.validate_on_submit():
        if session['username'] == form.username:
            author = Author.query.filter_by(
                username=form.username.data
                ).first()
            if author:
                newbio = form.bio.data
                image = request.files.get('image')
                filename = None
                try:
                    filename = uploaded_images.save(image)
                    setattr(author, 'image', filename)
                    datachanged = 1
                except:
                    flash("The image was not uploaded.")
                    print("The image was not uploaded.")
                if newbio > ' ':
                    setattr(author, 'bio', newbio)
                    datachanged = 1
                if datachanged == 1:
                    db.session.commit()
                    return redirect(url_for('success', msg="Author updated"))
            else:
                #This will never execute, because you must be logged in to use this function,
                # and if you have a login, you are in the author table, even if is_author is false.
                return "You must be an author to edit your bio."
        else:  
            return "You may only edit your own information."
           # return url_for('index')
    else:            
        #username=session['username']
        #author = Author.query.filter_by(username=session['username']).first()
        #form.fullname = author.fullname
        #form.email = author.email
        #form.username = author.username
        #form.password = author.password
        #form.confirm = author.password
        #form.bio = author.bio
        #form.image = author.image
        return render_template('author/register.html', form=form,  action="edit")    
Example #10
0
def register():
    form = RegisterForm()
    error = None
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        author = Author(form.fullname.data, form.email.data,
                        form.username.data, hashed_password,
                        form.is_author.data)
        db.session.add(author)
        db.session.flush()

        if author.id:
            db.session.commit()
            flash("User created successfully!")
            return redirect(url_for('success'))
        else:
            db.session.rollback()
            error = "Error creating user"
    return render_template('author/register.html', form=form)
Example #11
0
def register():
    blog = Blog.query.first()
    form = RegisterForm()
    error = ""
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        author = Author(form.fullname.data, form.email.data,
                        form.username.data, hashed_password, False)
        db.session.add(author)
        db.session.flush()
        if author.id:
            db.session.commit()
            flash("User account created")
            return redirect(url_for('index'))
        else:
            db.session.rollback()
            error = "Error creating user"
    return render_template('author/register.html',
                           form=form,
                           error=error,
                           blog=blog)
Example #12
0
def register():
    form = RegisterForm()
    error = None
    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        author = Author(form.fullname.data, form.email.data,
                        form.username.data, hashed_password, False)
        db.session.add(author)
        db.session.flush()

        if author.id:
            db.session.commit()
            flash('User registered')

        else:
            db.session.rollback()
            error = 'Error registering user'
            return render_template('author/register.html',
                                   form=form,
                                   error=error)

        return redirect(url_for('index'))
    return render_template('author/register.html', form=form)
Example #13
0
def auth_register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect('/auth_success')
    return render_template('author/auth_register.html', form=form)
Example #14
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect(url_for('success'))
    return render_template('author/register.html', form = form)
Example #15
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect(url_for('login', next=url_for('admin')))
    return render_template('author/register.html', form=form)
Example #16
0
def auth_register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect('/auth_success')
    return render_template('author/auth_register.html', form=form)
Example #17
0
def register():
	form = RegisterForm()
	return render_template('author/register.html', form=form)
Example #18
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect(url_for("success"))

    return render_template('author/register.html', form=form)