示例#1
0
def profile_update():
    usr = current_user._get_current_object()
    fields = dict()
    name = request.json.get('name')
    email = request.json.get('email')
    username = request.json.get('username')

    try:
        if 'name' in request.json:
            fields['name'] = name or ''
        if 'username' in request.json:
            fields['username'] = validate_username(username)
        if 'email' in request.json:
            fields['email'] = validate_email(email)
    except ValidationError, e:
        return e.message, 403
示例#2
0
def profile_update():
    usr = current_user._get_current_object()
    fields = dict()
    name = request.json.get('name')
    email = request.json.get('email')
    username = request.json.get('username')

    try:
        if 'name' in request.json:
            fields['name'] = name or ''
        if 'username' in request.json:
            fields['username'] = validate_username(username)
        if 'email' in request.json:
            fields['email'] = validate_email(email)
    except ValidationError, e:
        return e.message, 403
示例#3
0
def signup(data, login=True, remember=False):
    data = data or dict()
    email = data.get('email')
    username = data.get('username')
    password = data.get('password')
    confirm = data.get('password_confirm')

    email = validate_email(email)
    username = validate_username(username)
    password = validate_password(password, confirm)

    try:
        usr = user.create(username, password, email=email)
    except exc.InvalidPasswordError:
        raise ValidationError('Invalid Password')
    except exc.UsernameUnavailableError:
        raise ValidationError('Username has already been taken')
    except exc.EmailUnavailableError:
        raise ValidationError('Email has already been taken')

    if login:
        login_user(usr, remember=remember)

    return usr
示例#4
0
def signup(data, login=True, remember=False):
    data = data or dict()
    email = data.get('email')
    username = data.get('username')
    password = data.get('password')
    confirm = data.get('password_confirm')

    email = validate_email(email)
    username = validate_username(username)
    password = validate_password(password, confirm)

    try:
        usr = user.create(username, password, email=email)
    except exc.InvalidPasswordError:
        raise ValidationError('Invalid Password')
    except exc.UsernameUnavailableError:
        raise ValidationError('Username has already been taken')
    except exc.EmailUnavailableError:
        raise ValidationError('Email has already been taken')

    if login:
        login_user(usr, remember=remember)

    return usr