Exemplo n.º 1
0
def profile(request, username):
    from django.core.exceptions import ObjectDoesNotExist
    import cloudinary.uploader as cup
    from core.models import Profile
    print request.user
    print username

    if request.method == 'POST':
        try:
            profile = Profile.objects.get(user=request.user)
        except(ObjectDoesNotExist):
            profile = Profile()
            profile.user = request.user
        profile_picture = request.FILES['profile_photo']
        print profile_picture
        uploaded_image = cup.upload(
            profile_picture,
            crop='limit',
            width=600,
            height=550,
            )
        filename=uploaded_image["secure_url"]
        print filename
        profile.picture = filename
        print profile.picture
        profile.save()
    if request.method == 'GET':
        try:
            profile = Profile.objects.get(user=request.user)
        except(ObjectDoesNotExist):
            return render(request, 'users/profile.html', {"user": request.user, "profile": ""})
    else:
        pass
    return render(request, 'users/profile.html', {"user": request.user, "profile": profile})
Exemplo n.º 2
0
 def create(self, validated_data):
     """
     Create Profile for user.
     """
     request = self.context.get('request')
     profile = Profile(**validated_data)
     profile.user = request.user
     profile.save()
     return profile
Exemplo n.º 3
0
def signup(request):
    name = request.data.get("name")
    surname = request.data.get("surname")
    email = request.data.get("email")
    if email:
        email = email.lower()
    username = request.data.get("username")
    if username:
        username = username.lower()
    error = checkUserAlreadyRegistered(email, username)
    if error:
        return Response({'success': False, 'error': error})
    user = User.objects.create_user(username,
                                    email,
                                    email,
                                    last_login=timezone.now())
    user.first_name = name
    user.last_name = surname
    user.is_active = False
    user.save()
    profile = Profile()
    profile.user = user
    profile.setActivationKey()
    profile.setKeyExpires()
    profile.save()
    createDefaultWallets(profile)

    #set default avatar
    try:
        imageData = getDefaultAvatarImageData()
        ext = settings.DEFAULT_AVATAR_IMAGE_PATH.split('/')[-1].split(".")[-1]
        avatarImageName = "%d.%s" % (profile.user.id, ext)
        data = ContentFile(imageData, name=avatarImageName)
        profile.avatarImage = data
        profile.save()
    except:
        pass

    # Admin Notification
    adminNotification = Notification()
    adminNotification.email = True
    adminNotification.user = User.objects.get(username="******")
    adminNotification.setEmailData(
        "New LWF user registered",
        "notifications/email/admin_email_user_registered.html", {
            'user': user,
        })
    Thread(target=adminNotification.process, args=(), kwargs={}).start()
    sendRegistrationEmail(profile)
    return Response({'success': True})