Ejemplo n.º 1
0
def profile():
    """Update profile for current user."""
    #Ensure that use is logged in
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    #Initialize Edit Form with user data from g
    form = EditForm(obj=g.user)

    if form.validate_on_submit():
        user = User.authenticate(g.user.username, form.password.data)
        if not user:
            flash("Password did not match", "danger")
            return redirect('/')
        else:
            #Remove the password field from the form we do not want any password modications here
            form.__delitem__("password")
            #Populate user model from form data and commit to db
            form.populate_obj(g.user)
            db.session.commit()

            return redirect(url_for('users_show', user_id=g.user.id))

    return render_template('/users/edit.html', form=form)
Ejemplo n.º 2
0
def edit(id):
    if current_user.is_authenticated:
        student = Student.query.filter_by(student_id=id).first()

        clock = EditTime.query.filter_by(id = current_user.id).first()
        clock.placeholder += 1
        db.session.add(clock)
        db.session.commit()

        if student != None:
            form = EditForm(obj=student)
            if form.validate_on_submit():
                form.populate_obj(student)
                db.session.commit()
                return redirect(url_for('index'))
        else:
            form = EditForm()
            if form.validate_on_submit():
                student = Student( firstName=form.firstName.data, lastName=form.lastName.data, bannerID=form.bannerID.data, address=form.address.data, phone=form.phone.data, gpa=form.gpa.data, creditTotal=form.creditTotal.data, student_id=id )
                db.session.add(student)
                db.session.commit()
                if(current_user.faculty == True):
                    return redirect(url_for('index'))
                else:
                    return redirect(url_for('index', id = current_user.id))
        return render_template('edit.html', title='Edit', form=form)
    else:
        return redirect(url_for('login'))