Exemplo n.º 1
0
def signin_fb(request):
    if not is_client_known(request):
        return Response('Forbidden', status=401)

    id = request.data.get('id')

    try:
        user = User.objects.get(profile__facebook__id=id)
    except User.DoesNotExist:
        email = request.data.get('email')

        user = User.objects.create_user(
            username='******' + email.split('@')[0],
            password='******',
        )

        user.email = 'REG_FACEBOOK_' + email
        user.save()

        user.profile = UserProfile()
        user.profile.state = 'fb'
        user.profile.save()

        FacebookProfile.objects.create(
            profile=user.profile, id=id,
            email=email, name=request.data.get('name'))

    return get_access_token(user)
Exemplo n.º 2
0
def signin(request):
    if not is_client_known(request):
        return Response('Forbidden', status=401)

    identifier = request.data.get('identifier')
    password = request.data.get('password')

    try:
        user = User.objects.get(username=identifier)

        if user.check_password(password):
            return get_access_token(user)
        else:
            return Response('Incorrect password', status=400)
    except User.DoesNotExist:
        try:
            user = User.objects.get(email=identifier)

            if user.check_password(password):
                return get_access_token(user)
            else:
                return Response('Unauthorized', status=400)
        except User.DoesNotExist:
            return Response('Account does not exist', status=404)
Exemplo n.º 3
0
def register(request):
    if not is_client_known(request):
        return Response('Forbidden', status=401)

    serialized = UserSerializer(data=request.data)

    if serialized.is_valid():
        user = User.objects.create_user(
            username=serialized.validated_data['username'],
            password=serialized.validated_data['password'],
        )

        user.email = serialized.validated_data['email']
        user.save()

        user.profile = UserProfile()
        user.profile.save()
        createMail(user)
        return get_access_token(user)

    return Response(serialized._errors, status=400)