示例#1
0
def register():
    if request.method == 'GET':
        return redirect('/')
    logging.debug('add profile form : %s', str(request.form))
    logging.info('receive socket from /register-data -> profile: %s',
                 request.form['profile-name'])
    form = request.form
    profile = Profile()
    profile.name = form['profile-name']
    profile.firstname = form['profile-firstname']
    profile.address = form['profile-address']
    profile.comp_address = form['profile-comp_address']
    profile.city = form['profile-city']
    profile.zipcode = form['profile-zipcode']
    profile.country = form['profile-country']
    profile.phone = form['profile-phone']
    profile.email = form['profile-email']
    profile.siret = form['profile-siret']
    pdao = ProfileDAO()
    if pdao.insert(profile):
        logging.info('add profile %s OK', profile.name)
        session['logged_in'] = pdao.field(pdao.where('email', profile.email),
                                          'id')[0][0]
    else:
        logging.info('add profile %s FAILED', profile.name)
    return redirect('/')
示例#2
0
def register():
    logging.debug('add profile form : %s', str(request.form))
    logging.info('receive socket from /register-data -> profile: %s', request.form['profile-name'])
    form = request.form
    if form['profile-password'] != form['profile-repassword']:
        return render_template('v3-login.html', error=_('Your confirmation password does not match the password you entered'))
    profile = Profile()
    profile.name = form['profile-name']
    profile.firstname = form['profile-firstname']
    profile.address = form['profile-address']
    profile.comp_address = form['profile-comp_address']
    profile.city = form['profile-city']
    profile.zipcode = form['profile-zipcode']
    profile.country = form['profile-country']
    profile.phone = form['profile-phone']
    profile.email = form['profile-email']
    profile.siret = form['profile-siret']
    profile.password = form['profile-password']
    pdao = ProfileDAO()
    if pdao.insert(profile):
        logging.info('add profile %s OK', profile.name)
        session['logged_in'] = pdao.field(pdao.where('email', profile.email), 'id')[0][0]
    else:
        logging.info('add profile %s FAILED', profile.name)
        return render_template('v3-login.html', error=_('Impossible to create new user, please contact an admin !'))

    return redirect('/')
def user_profile():
    if request.method == 'GET':
        submit_url = url_for('.user_profile', _method='POST')
        return render_template('profile_form.html', submit_url=submit_url)
    else:
        session = Session()
        try:
            form = request.form
            username = form['username']

            if username_already_used(session, username):
                return "Username %s is already used. Click on <a href='%s'>Back</a> to go back" \
                       % (username, url_for(user_profile))

            prof = Profile()
            prof.userid = gen_random_uid()
            prof.username = username
            prof.created = str(int(time.time() * 1000))
            prof.firstname = form['firstname']
            prof.lastname = form['lastname']
            prof.age = form['age']
            prof.bio = form['biography']
            prof.gender = form['gender']

            file = request.files['image']
            img_filename = secure_filename(file.filename)
            prof.image = img_filename

            try:
                file.save(
                    os.path.join(app.config['UPLOAD_FOLDER'],
                                 prof.userid + '_' + img_filename))
            except Exception:
                pass

            session.add(prof)
            session.commit()
        except Exception:
            session.rollback()

        return "Profile submitted. Click on <a href='%s'>Back</a> to go back" % url_for(
            '.user_profile')