示例#1
0
def sign_up():
    email = request.form.get('email', '')
    password = request.form.get('password', '')
    name = request.form.get('name', '')
    if not email or not password or not name:
        return jsonify({
            'exception': 'Invalid Parameters',
        }), 400
    if g.session.query(models.user).filter(models.user.email == email).count():
        '''
        This implies a duplicate email (an email that has already been
        registered with us). However, we do not say so as a safety/security
        measure.
        '''
        return jsonify({
            'exception': 'Invalid Email',
        }), 400
    user = models.user(**{
        'email': email,
        'name': name,
        'password': password,
    })
    g.session.add(user)
    g.session.commit()
    g.session.refresh(user)
    return jsonify(user.get_dictionary()), 200
示例#2
0
def sign_up():
    email = request.form.get('email', '')
    password = request.form.get('password', '')
    name = request.form.get('name', '')
    if not email or not password or not name:
        return jsonify({
            'exception': 'Invalid Parameters',
        }), 400
    if g.session.query(models.user).filter(models.user.email==email).count():
        '''
        This implies a duplicate email (an email that has already been
        registered with us). However, we do not say so as a safety/security
        measure.
        '''
        return jsonify({
            'exception': 'Invalid Email',
        }), 400
    user = models.user(**{
        'email': email,
        'name': name,
        'password': password,
    })
    g.session.add(user)
    g.session.commit()
    g.session.refresh(user)
    return jsonify(user.get_dictionary()), 200
示例#3
0
def users_sign_up():
    if g.user:
        return redirect(request.args.get('next') or url_for('visitors.dashboard'))
    user = models.user()
    form = forms.users_sign_up(request.form)
    form.id = user.id
    if form.validate_on_submit():
        g.mysql.add(form.get_instance(user))
        g.mysql.commit()
        flash('You have been signed up successfully.', 'success')
        return redirect(url_for('visitors.users_sign_in'))
    return render_template('visitors/views/users_sign_up.html', form=form)
示例#4
0
def users_sign_up_twitter():
    if twitter.result:
        if twitter.result.error:
            flash(twitter.result.error.message, 'danger')
            return redirect(url_for('visitors.users_sign_up'))
        if twitter.result.user:
            if not (twitter.result.user.name and twitter.result.user.id):
                twitter.result.user.update()
            if not g.mysql.query(
                models.user,
            ).filter(
                models.user.twitter_screen_name == twitter.result.user.name,
            ).first():
                g.mysql.add(models.user(**{
                    'twitter_screen_name': twitter.result.user.name,
                }))
                g.mysql.commit()
            flash('You have been signed up successfully.', 'success')
            return redirect(url_for('visitors.users_sign_in'))
    return twitter.response