Ejemplo n.º 1
0
def register():
    form = RegistrationForm()
    if current_app.config['REQUEST_REGISTRATION']:
        if 'token' in request.json:
            form = TokenRegistrationForm()
        else:
            form = RegistrationRequestForm()
            if form.validate_on_submit():
                return registration_request(form.email.data, 
                                            request.remote_addr)
    if form.validate_on_submit():
        new_user = User(form.username.data, 
                        form.email.data, 
                        form.password.data,
                        request.remote_addr)
        new_user.save()
        if login_user(new_user):
            return jsonify(new_user)
        return jsonify(anonymous_user_data)
    form.errors['_status_code'] = 400 
    return jsonify(**form.errors)
Ejemplo n.º 2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        form_user = User.get_user(form.username.data)
        if form_user and form_user.check_password(form.password.data):
            if login_user(form_user):
                return jsonify(form_user)
            else:
                return jsonify(username=['Your account is currently disabled.'], 
                    _status_code=400)
        else:
            return jsonify(username=['Invalid username, email or password.'], 
                _status_code=400)
        return ''
    form.errors['_status_code'] = 400 
    return jsonify(**form.errors)
Ejemplo n.º 3
0
def load_user(userid):
    return User.get(userid)
Ejemplo n.º 4
0
 def validate_email(form, field):
     if User.get_by_email(field.data):
         raise ValidationError("Email already registered.")
Ejemplo n.º 5
0
 def validate_username(form, field):
     if User.get_by_username(field.data):
         raise ValidationError("Username already registered.")
Ejemplo n.º 6
0
 def validate_email(form, field):
     if User.get_by_email(field.data):
         raise ValidationError("This email is already registered")
     if UserRegistrationRequest.get_by_email(field.data):
         raise ValidationError("Registration already requested for this email.")