示例#1
0
def register():
    form = RegistrationForm(csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        user = User()
        user.id = form.id.data
        user.first_name = form.first_name.data
        user.last_name = form.last_name.data
        user.password = form.password.data
        user.email = form.email.data
        user.contact_no = form.contact_no.data
        user.branch = form.branch.data
        user.profile_type = request.form['profile_type']
        profile_pic = request.files['profile_pic']

        if profile_pic:
            profile_pic_extension = ctrl.get_extension_of_file(profile_pic.filename)
            user.profile_pic_extension = profile_pic_extension
            file_op.save_profile_pic(profile_pic, user.id)

        if user.profile_type != 'P':
            ctrl.mkdir_p(os.path.join(app.config['SOLUTION_FILES_DEST'], user.id))
        user.is_active = 'Y'

        db_session = get_db_session()
        insert_to_db(db_session, user)
        return render_template('forms/registration_success.html')
    return render_template('forms/register.html', form=form)
示例#2
0
def profile():
    user_id = session['username']
    user = get_db_session().query(User).filter_by(id=user_id).one()
    user_form = ProfileForm(csrf_enabled=False, obj=user)
    if request.method == 'POST':
        user.first_name = user_form.first_name.data
        user.last_name = user_form.last_name.data
        if user_form.password.data != '':
            user.password = user_form.password.data
        user.contact_no = user_form.contact_no.data
        profile_pic = request.files['profile_pic']
        file_op.save_profile_pic(profile_pic, user_id)
        get_db_session().commit()
    return render_template('forms/profile.html', user=user, form=user_form, randint=random.randint(1000, 9999))