예제 #1
0
def create_user(request):
    data = json.loads(request.body)

    errors = {}
    for field in REQ_FIELDS:
        if field not in data:
            errors[field] = [_('This field is required')]

    for inputfield in data:
        if inputfield not in ALL_FIELDS:
            errors[inputfield] = [_('Unrecognized field')]

    if errors:
        raise ValidationError(errors)

    dup_username = User.objects.filter(username=data['username'])
    dup_email = User.objects.filter(email=data['email'])

    if dup_username.exists():
        return _conflict_response(_('Username is already in use'))
    if dup_email.exists():
        # BE WARNED - The iOS application relies on this error message string.
        # If you change this you WILL NEED TO ALTER CODE THERE AS WELL.
        return _conflict_response(_('Email is already in use'))

    user = User(**data)

    # Needed to properly hash the password
    user.set_password(data['password'])
    user.active = True
    user.save()

    RegistrationProfile.objects.create_profile(user)

    return {'status': 'success', 'id': user.pk}
예제 #2
0
파일: user.py 프로젝트: PyBulls/OTM2
def create_user(request):
    data = json.loads(request.body)

    errors = {}
    for field in REQ_FIELDS:
        if field not in data:
            errors[field] = [trans('This field is required')]

    for inputfield in data:
        if inputfield not in ALL_FIELDS:
            errors[inputfield] = [trans('Unrecognized field')]

    if errors:
        raise ValidationError(errors)

    dup_username = User.objects.filter(username=data['username'])
    dup_email = User.objects.filter(email=data['email'])

    if dup_username.exists():
        return _conflict_response(trans('Username is already in use'))
    if dup_email.exists():
        # BE WARNED - The iOS application relies on this error message string.
        # If you change this you WILL NEED TO ALTER CODE THERE AS WELL.
        return _conflict_response(trans('Email is already in use'))

    user = User(**data)

    # Needed to properly hash the password
    user.set_password(data['password'])
    user.active = True
    user.save()

    RegistrationProfile.objects.create_profile(user)

    return {'status': 'success', 'id': user.pk}
예제 #3
0
파일: views.py 프로젝트: jvgriffis/OTM2
def create_user(*args, **kwargs):
    # Clearly this is just getting the api working
    # it shouldn't stay here when real user stuff happens
    user = User(username=kwargs["username"], email=kwargs["email"])
    user.set_password(kwargs["password"])
    user.save()

    return user
예제 #4
0
파일: basic.py 프로젝트: jvgriffis/OTM2
    def _create_test_user(self):
        global userUUID

        username = '******' % userUUID
        email = '*****@*****.**' % username
        userUUID += 1

        User.objects.filter(email=email).delete()

        u = User(username=username, email=email)
        u.set_password(username)
        u.save()
        setattr(u, 'plain_password', username)

        return u
예제 #5
0
def create_user(request):
    data = json.loads(request.body)

    if 'allow_email_contact' not in data:
        data['allow_email_contact'] = False

    errors = {}
    for field in REQ_FIELDS:
        if field not in data:
            errors[field] = [trans('This field is required')]

    for inputfield in data:
        if inputfield not in ALL_FIELDS:
            errors[inputfield] = [trans('Unrecognized field')]

    if errors:
        raise ValidationError(errors)

    dup_username = User.objects.filter(username=data['username'])
    dup_email = User.objects.filter(email=data['email'])

    if dup_username.exists():
        return _conflict_response(trans('Username is already in use'))
    if dup_email.exists():
        return _conflict_response(trans('Email is already in use'))

    user = User(**data)

    # Needed to properly hash the password
    user.set_password(data['password'])
    user.active = True
    user.save()

    RegistrationProfile.objects.create_profile(user)

    return {'status': 'success', 'id': user.pk}
예제 #6
0
def create_user(request):
    data = json.loads(request.body)

    if 'allow_email_contact' not in data:
        data['allow_email_contact'] = False

    errors = {}
    for field in REQ_FIELDS:
        if field not in data:
            errors[field] = [trans('This field is required')]

    for inputfield in data:
        if inputfield not in ALL_FIELDS:
            errors[inputfield] = [trans('Unrecognized field')]

    if errors:
        raise ValidationError(errors)

    dup_username = User.objects.filter(username=data['username'])
    dup_email = User.objects.filter(email=data['email'])

    if dup_username.exists():
        return _conflict_response(trans('Username is already in use'))
    if dup_email.exists():
        return _conflict_response(trans('Email is already in use'))

    user = User(**data)

    # Needed to properly hash the password
    user.set_password(data['password'])
    user.active = True
    user.save()

    RegistrationProfile.objects.create_profile(user)

    return {'status': 'success', 'id': user.pk}
예제 #7
0
파일: __init__.py 프로젝트: dank1/otm-core
def make_plain_user(username, password='******'):
    user = User(username=username, email='*****@*****.**' % username)
    user.set_password(password)  # hashes password, allowing authentication
    user.save()

    return user
예제 #8
0
def make_plain_user(username, password='******'):
    user = User(username=username, email='*****@*****.**' % username)
    user.set_password(password)  # hashes password, allowing authentication
    user.save()

    return user