Exemple #1
0
def invite(request, code):
    profile = check_profile(code)
    if not profile:
        messages.error(request, 'Your personal URL is incorrect, please reset your account or provide proper url')
        return redirect('index') 
    
    from forms import InvitationForm
    if request.method == 'POST':
        form = InvitationForm(request.POST) 
        if form.is_valid(): 
            emails=form.cleaned_data['emails']
            emails=emails.split(',')
            for e in emails:
                e=e.strip()
                i=Invitation(email=e, key=generate_key())
                i.save()
                u, created=User.objects.get_or_create(username=e[:30], email=e)
                notification.send([u], 'invite', {'key': i.key,
                                                     'profile':profile })
            
            
            if len(emails):
                messages.info(request, '%d invitation(s) has been sent ' % len(emails)) 
                    
            return redirect('homepage', code=code)
    else:
        form=InvitationForm(initial={'key':code})
            
    return render_to_response('researchers/invite.html', {'profile':profile, 'form':form, 'key':code}, context_instance=RequestContext(request))
Exemple #2
0
def json_add_member(request, band_id):
    if isInBand(request.user, band_id):
        #current user is in this band
        if isManager(request.user, band_id):
            #current user is a manager
            if request.method == 'POST':
                #load data
                data = json.loads(request.body)
                #add an invitation to the email provided
                band = Band.objects.get(id=band_id)
                if "email" in data:
                    email = data["email"]
                else:
                    email = None
                newInv = Invitation(band=band, email=email, active=True)
                newInv.save()
                #add the member to the band regardless
                name = data["name"]
                role = data["role"]
                if "phone" in data:
                    phone = data["phone"]
                else:
                    phone = None
                status = data["status"]
                newMem = Member(band=band, name=name, role=role, phone=phone, status=status, email=email)
                newMem.save()
                return HttpResponse("success")
    return HttpResponse("failure")
Exemple #3
0
def add_friend(request,username):
    user = User.objects.get(username=username)
    invitation = Invitation(name = user.username, email= user.email, code= User.objects.make_random_password(20),sender=request.user)
    invitation.save()
    invitation.send()
    connection = Connections.objects.filter(connector_id= user.id)
    variables = RequestContext(request, {'username':username, 'connections': connection, 'users': User.objects.all()})
    return render_to_response('user_connections.html',variables)
Exemple #4
0
def add_group_user(request, groupName=None):

    if request.method == 'POST':
        users = request.POST.getlist('user')
        groupName = request.POST['groupName']
        sgroup = get_object_or_404(SocialGroup, name=groupName)
        if request.user != sgroup.creator:
            msg = 'You dont have the permission'
        else:
            msg = ""
            ul = User.objects.filter(username__in=users)
            for u in ul:
                #to make sure user isnot already in and not already sent
                if not Membership.objects.filter(
                        sgroup=sgroup, member=u
                ).count(
                ):  # = Invitation.objects.get(sgroup, u).response='accept'
                    if not Invitation.objects.filter(
                            socialgroup=sgroup, invite=u, response='').count():
                        invite = Invitation(invite=u, socialgroup=sgroup)
                        invite.save()
                        msg = msg + 'Invitation sent to users'
                else:
                    msg = msg + '%s already in the group or is invited <br />' % u

    else:
        sgroup = get_object_or_404(SocialGroup, name=groupName)
        invitations = Invitation.objects.filter(socialgroup=sgroup).exclude(
            response="reject")
        invitedList = []
        for invitation in invitations:
            invitedList.append(invitation.invite)
        users = User.objects.exclude(id=request.user.id).exclude(
            id__in=sgroup.members.all()).exclude(username__in=invitedList)
        # to exclude members already in or already invited

        return render(request, 'add_group_user.html', {
            'groupName': groupName,
            'users': users
        })
    return render(request, 'add_group_user.html', {
        'groupName': groupName,
        'msg': msg
    })
	def post(self, request):
		form = InvitationForm(request.POST)
		if form.is_valid():
			email = form.cleaned_data['email']
			subject = 'Invitation to join MyTweet App'
			sender_name = request.user.username
			sender_email = request.user.email
			invite_code = Invite.generate_invite_code(email)
			link = 'http://%s/users/invite/accept/%s/' % (settings.SITE_HOST, invite_code)
			context = Context({"sender_name": sender_name, "sender_email": sender_email, "email": email, "link": link})
			invite_email_template = render_to_string('partials/_invite_email_template.html', context)
			msg = EmailMultiAlternatives(subject, invite_email_template,
			settings.EMAIL_HOST_USER, [email], cc=[settings.EMAIL_HOST_USER])
			user = User.objects.get(username=request.user.username)
			invitation = Invitation()
			invitation.email = email
			invitation.code = invite_code
			invitation.sender = user
			invitation.save()
			success = msg.send()
			return HttpResponseRedirect('/users/invite?success='+str(success) +'&email='+email)
Exemple #6
0
def invite(request, code):
    profile = check_profile(code)
    if not profile:
        messages.error(
            request,
            'Your personal URL is incorrect, please reset your account or provide proper url'
        )
        return redirect('index')

    from forms import InvitationForm
    if request.method == 'POST':
        form = InvitationForm(request.POST)
        if form.is_valid():
            emails = form.cleaned_data['emails']
            emails = emails.split(',')
            for e in emails:
                e = e.strip()
                i = Invitation(email=e, key=generate_key())
                i.save()
                u, created = User.objects.get_or_create(username=e[:30],
                                                        email=e)
                notification.send([u], 'invite', {
                    'key': i.key,
                    'profile': profile
                })

            if len(emails):
                messages.info(request,
                              '%d invitation(s) has been sent ' % len(emails))

            return redirect('homepage', code=code)
    else:
        form = InvitationForm(initial={'key': code})

    return render_to_response('researchers/invite.html', {
        'profile': profile,
        'form': form,
        'key': code
    },
                              context_instance=RequestContext(request))
Exemple #7
0
def invite(request):
    emails = request.POST.getlist('emailList[]', '')
    custom_message = request.POST.get('custom_message', '')

    if emails:
        user = User.objects.get(username=request.user.username)
        user_account = Account.objects.get(user=user)
        did_not_invite = []

        # TODO: Move this to string templates
        if custom_message:
            email_body = "{host_name} has invited you to be part of CiviWiki Beta with the following message: {custom_message}".format(
                host_name=user_account.full_name,
                custom_message=custom_message
            )
        else:
            email_body = "{host_name} has invited you to be part of CiviWiki Beta. Follow the link below to get registered.".format(
                host_name=user_account.full_name
            )

        email_messages = []
        valid_emails = []
        for email in emails:
            if Invitation.objects.filter(invitee_email=email).exists():
                did_not_invite.append(email)
            else:
                valid_emails.append(email)
                verification_hash = uuid.uuid4().hex[:31]
                data = {
                    'host_user': user,
                    'invitee_email': email,
                    'verification_code': verification_hash,
                }

                domain = get_current_site(request).domain
                base_url = "http://{domain}/beta_register/{email}/{token}"
                url_with_code = base_url.format(
                    domain=domain,
                    email=email,
                    token=verification_hash
                )

                email_context = {
                    'title' : "You're Invited to Join CiviWiki Beta",
                    'greeting' : "You're Invited to Join CiviWiki Beta",
                    'body' : email_body,
                    'link': url_with_code,
                    'recipient': [email]
                }
                email_messages.append(email_context)

                new_invitation = Invitation(**data)
                # new_invitation.host_user = user
                # new_invitation.invitee_email = email
                # new_invitation.verification_code = ""
                new_invitation.save()

        if email_messages:
            email_subject = "Invitation to CiviWiki"
            send_mass_email.delay(
                subject=email_subject,
                contexts=email_messages
            )


        if len(did_not_invite) == len(emails):
            response_data = {
                "message": "Invitations exist for submitted email(s). No new invitations sent",
                "error":"INVALID_EMAIL_DATA"
            }
            return JsonResponse(response_data, status=400)

        invitations = Invitation.objects.filter_by_host(host_user=user).order_by("-date_created").all()
        invitees = [invitation.summarize() for invitation in invitations]

        response_data = {
            'did_not_invite': did_not_invite,
            'invitees': invitees
        }
        return JsonResponse(response_data)

    else:
        # Return an 'invalid login' error message.
        response = {
            "message": 'Invalid Email Data',
            "error":"INVALID_EMAIL_DATA"
        }
        return JsonResponse(response, status=400)
Exemple #8
0
def submitcircle(request):
    new_member = get_current_member(request)
    new_circle = get_current_circle(request)

    count = 2
    posted_members = {}

    custom_errors = ""

    while count <= settings.CIRCLE_MAX_SIZE:
        member_contact = {}

        current_name = request.POST.get("name_" + str(count), None)
        current_contact = request.POST.get("contact_" + str(count), None)

        if (current_name):
            if (current_contact):
                # Check to see if current contact info is valid phone or email
                if is_phone(current_contact):
                    member_contact["contact_type"] = "phone"

                if is_email(current_contact):
                    member_contact["contact_type"] = "email"

                if not is_phone(current_contact) and not is_email(current_contact):
                    # Bad data error
                    custom_errors += "<li>contact_" + str(count) + " must be either a valid phone number OR email</li>"

                member_contact["contact_info"] = current_contact

                posted_members[current_name] = member_contact
            else:
                # Missing contact data error
                custom_errors += "<li>name_" + str(count) + " is present but contact_" + str(count) + " is missing</li>"
        else:
            if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
                # Missing name data error
                custom_errors += "<li>name_" + str(count) + " is missing</li>"

        count += 1

    # Check to see if we have minimum more members added
    if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
        custom_errors += "<li>You need at least " + str(settings.CIRCLE_MIN_SIZE) + " members (including yourself) in your circle</li>"

    if custom_errors != "":
        custom_errors = format_html("<p><ul>{}</ul></p>",
                                    mark_safe(custom_errors))

        # If there are any errors, kick out and display them
        context = {"member":new_member, "num_range_str":settings.CONTACT_RANGE_STR, "custom_errors":custom_errors, }
        return render(request, "circly/network.html", context)

    for each_member in posted_members.keys():
        # Create new members and add to the circle
        if (posted_members[each_member]["contact_type"] == "email"):
            next_member = Member(circle=new_circle,
                                 circle_owner=False,
                                 member_name=each_member,
                                 member_email=posted_members[each_member]["contact_info"],
                                 member_created_date=timezone.now(), )
        elif (posted_members[each_member]["contact_type"] == "phone"):
            new_phone = phonenumbers.parse(posted_members[each_member]["contact_info"], "US")
            new_phone = phonenumbers.format_number(new_phone, phonenumbers.PhoneNumberFormat.E164)

            next_member = Member(circle=new_circle,
                                 circle_owner=False,
                                 member_name=each_member,
                                 member_phone=new_phone,
                                 member_created_date=timezone.now(), )

        next_member.save()

        # Create invite code with short link for profile sign up
        invite_code = hash_code(posted_members[each_member]["contact_info"])

        invite_url = "http://www.circly.org/invite/" + invite_code
        new_short_url = random_bitly(invite_url)

        invite = Invitation(member=next_member,
                            invite_code=invite_code, 
                            invite_short_url=new_short_url, 
                            invite_created_date=timezone.now(),
                            invite_send_date=timezone.now())
        invite.save()

        # Create reminders for all new members to join the circle
        remind = Reminder(member=next_member,
                          reminder_subject=new_circle.circle_owner_name() + " would like you to join their circle of support",
                          reminder_message="Hey " + each_member + ", visit " + new_short_url + " to fill in your profile and join a circle of preventive care.",
                          reminder_created_date=timezone.now(),
                          reminder_send_date=timezone.now(), )
        remind.save()

    if new_member.member_email:
        owner_hash = hash_code(new_member.member_email)

    if new_member.member_phone:
        owner_hash = hash_code(new_member.member_phone)

    dashboard_url = "http://www.circly.org/dashboard/" + owner_hash
    new_short_dashboard_url = random_bitly(dashboard_url)

    new_circle.circle_short_url = new_short_dashboard_url
    new_circle.save()

    set_member_and_circle(request, new_circle, new_member)

    return HttpResponseRedirect(reverse("connect:dashboard", 
                                        kwargs={"owner_hash":owner_hash}))