def add_channel_member(request, channel_id): """ Invite channel members. """ context = {} channel = get_object_or_404(Channel, id=channel_id, owner=request.user) form = InvitationForm() if request.method == "POST": form = InvitationForm(request.POST) if form.is_valid(): # Save confirmation data email = form.cleaned_data['email'] status = 'pending' # Automatically adds the invited user to the channel; invited user still receives confirmation link # Update: Create the user when it does not exist. user_created = False try: invited_user = User.objects.get(email=email) new_username = '' new_password = '' except User.DoesNotExist: new_username = generate_username(email) new_password = generate_random_string(6) invited_user = User.objects.create_user(username=new_username, password=new_password, email=email) user_created = True invited_user_profile = invited_user.userprofile invited_user_profile.channels.add(channel) invited_user_profile.save() Message.objects.create(user=invited_user, from_user=request.user, level=persistent_messages.INFO, message="Congratulations! You are now a contributor on the %s channel. You can \ create videos and save them to this channel after they are created. Now \ you can enjoy the features of a premium account at no cost to you." % channel.name) confirmation_info, created = ConfirmationInfo.objects.get_or_create( email=email, channel=channel ) # Send email to the new user confirmation_info.status = 'pending' confirmation_info.save() subject = "Invitation from Screenbird" from_mail = settings.DEFAULT_FROM_EMAIL link = "".join(("http://",request.META['HTTP_HOST'],reverse("confirm_channel_member"),"?key="+confirmation_info.key)) reg_link = "".join(("http://",request.META['HTTP_HOST'],reverse("register"))) if user_created: account_link = "".join(("http://",request.META['HTTP_HOST'],reverse("manage_account"))) message = render_to_string("email/collaborate_user_created.txt", { 'username':new_username, 'password':new_password, 'email': email, 'user':request.user.username, 'account_link':account_link, 'confirm_link':link }) else: message = render_to_string("email/collaborate.txt", { 'email': email, 'user':request.user.username, 'reg_link':reg_link, 'confirm_link':link }) send_mail(subject, message, from_mail, [email], fail_silently=False) context = {"success":True} messages.success(request, 'An invitation has been sent to %s.' % email) else: messages.error(request, 'Failed to send invitation.') context['form'] = form context['channel'] = channel return redirect(reverse('update_channel', args=[channel.id,]))
def add_channel_member(request, channel_id): """ Invite channel members. """ context = {} channel = get_object_or_404(Channel, id=channel_id, owner=request.user) form = InvitationForm() if request.method == "POST": form = InvitationForm(request.POST) if form.is_valid(): # Save confirmation data email = form.cleaned_data['email'] status = 'pending' # Automatically adds the invited user to the channel; invited user still receives confirmation link # Update: Create the user when it does not exist. user_created = False try: invited_user = User.objects.get(email=email) new_username = '' new_password = '' except User.DoesNotExist: new_username = generate_username(email) new_password = generate_random_string(6) invited_user = User.objects.create_user(username=new_username, password=new_password, email=email) user_created = True invited_user_profile = invited_user.userprofile invited_user_profile.channels.add(channel) invited_user_profile.save() Message.objects.create( user=invited_user, from_user=request.user, level=persistent_messages.INFO, message= "Congratulations! You are now a contributor on the %s channel. You can \ create videos and save them to this channel after they are created. Now \ you can enjoy the features of a premium account at no cost to you." % channel.name) confirmation_info, created = ConfirmationInfo.objects.get_or_create( email=email, channel=channel) # Send email to the new user confirmation_info.status = 'pending' confirmation_info.save() subject = "Invitation from Screenbird" from_mail = settings.DEFAULT_FROM_EMAIL link = "".join(("http://", request.META['HTTP_HOST'], reverse("confirm_channel_member"), "?key=" + confirmation_info.key)) reg_link = "".join( ("http://", request.META['HTTP_HOST'], reverse("register"))) if user_created: account_link = "".join(("http://", request.META['HTTP_HOST'], reverse("manage_account"))) message = render_to_string( "email/collaborate_user_created.txt", { 'username': new_username, 'password': new_password, 'email': email, 'user': request.user.username, 'account_link': account_link, 'confirm_link': link }) else: message = render_to_string( "email/collaborate.txt", { 'email': email, 'user': request.user.username, 'reg_link': reg_link, 'confirm_link': link }) send_mail(subject, message, from_mail, [email], fail_silently=False) context = {"success": True} messages.success(request, 'An invitation has been sent to %s.' % email) else: messages.error(request, 'Failed to send invitation.') context['form'] = form context['channel'] = channel return redirect(reverse('update_channel', args=[ channel.id, ]))
def add_cocreate_member(request, cocreate_id): """ Invite cocreate members. """ context = {} cocreate = get_object_or_404(CoCreate, id=cocreate_id, owner=request.user) form = InvitationForm() if request.method == "POST": form = InvitationForm(request.POST) if form.is_valid(): # Save confirmation data email = form.cleaned_data['email'] status = 'pending' # Automatically adds the invited user to the channel; invited user still receives confirmation link # Update: Create the user when it does not exist. created = False try: invited_user = User.objects.get(email=email) new_username = '' new_password = '' except User.DoesNotExist: new_username = generate_username(email) new_password = generate_random_string(6) invited_user = User.objects.create_user(username=new_username, password=new_password, email=email) created = True option = CocreateOption(user=invited_user, cocreate=cocreate) option.save() Message.objects.create(user=invited_user, from_user=request.user, level=persistent_messages.INFO, message="Congratulations! You are now a contributor on %s co-create videos. You can \ create videos and save them as a part of one big video project" % request.user.username) """ # Send email to the new user subject = "Invitation from Screenbird" from_mail = settings.DEFAULT_FROM_EMAIL reg_link = "".join(("http://",request.META['HTTP_HOST'],reverse("register"))) # TODO: Move mailing part to after create cocreate section # TODO: use date_joined and last_login to determine whether user is new or not if created: account_link = "".join(("http://",request.META['HTTP_HOST'],reverse("manage_account"))) cocreate_section_link = "".join(("http://", request.META['HTTP_HOST'], reverse("cocreate", args=(cocreate.pk,)))) message = render_to_string("email/cocreate_invite_screenbird.txt", { 'username':new_username, 'password':new_password, 'email': email, 'user':request.user.username, 'account_link':account_link, 'cocreate_section_link': cocreate_section_link, }) html_message = render_to_string("email/cocreate_invite_screenbird.html", { 'username': new_username, 'password': new_password, 'email': email, 'user': request.user.username, 'account_link': account_link, 'cocreate_section_link': cocreate_section_link }) mail = EmailMultiAlternatives(subject, message, from_mail, [email]) mail.attach_alternative(html_message, "text/html") mail.send() else: message = render_to_string("email/cocreate_collaborate.txt", { #'name':name, 'email': email, 'user':request.user.username, 'reg_link':reg_link, }) send_mail(subject, message, from_mail, [email], fail_silently=False) """ context = {"success":True} messages.success(request, 'An invitation has been sent to %s.' % email) if request.is_ajax(): return HttpResponse(simplejson.dumps({ 'status': 'OK', 'pk': invited_user.pk, 'username': invited_user.username }), mimetype='application/json') else: messages.error(request, 'Failed to send invitation.') if request.is_ajax(): return HttpResponse(simplejson.dumps({ 'status': 'ERROR', 'errors': form.errors }), mimetype='application/json') return redirect(reverse('cocreate', args=[cocreate.id,]))
def add_cocreate_member(request, cocreate_id): """ Invite cocreate members. """ context = {} cocreate = get_object_or_404(CoCreate, id=cocreate_id, owner=request.user) form = InvitationForm() if request.method == "POST": form = InvitationForm(request.POST) if form.is_valid(): # Save confirmation data email = form.cleaned_data['email'] status = 'pending' # Automatically adds the invited user to the channel; invited user still receives confirmation link # Update: Create the user when it does not exist. created = False try: invited_user = User.objects.get(email=email) new_username = '' new_password = '' except User.DoesNotExist: new_username = generate_username(email) new_password = generate_random_string(6) invited_user = User.objects.create_user(username=new_username, password=new_password, email=email) created = True option = CocreateOption(user=invited_user, cocreate=cocreate) option.save() Message.objects.create( user=invited_user, from_user=request.user, level=persistent_messages.INFO, message= "Congratulations! You are now a contributor on %s co-create videos. You can \ create videos and save them as a part of one big video project" % request.user.username) """ # Send email to the new user subject = "Invitation from Screenbird" from_mail = settings.DEFAULT_FROM_EMAIL reg_link = "".join(("http://",request.META['HTTP_HOST'],reverse("register"))) # TODO: Move mailing part to after create cocreate section # TODO: use date_joined and last_login to determine whether user is new or not if created: account_link = "".join(("http://",request.META['HTTP_HOST'],reverse("manage_account"))) cocreate_section_link = "".join(("http://", request.META['HTTP_HOST'], reverse("cocreate", args=(cocreate.pk,)))) message = render_to_string("email/cocreate_invite_screenbird.txt", { 'username':new_username, 'password':new_password, 'email': email, 'user':request.user.username, 'account_link':account_link, 'cocreate_section_link': cocreate_section_link, }) html_message = render_to_string("email/cocreate_invite_screenbird.html", { 'username': new_username, 'password': new_password, 'email': email, 'user': request.user.username, 'account_link': account_link, 'cocreate_section_link': cocreate_section_link }) mail = EmailMultiAlternatives(subject, message, from_mail, [email]) mail.attach_alternative(html_message, "text/html") mail.send() else: message = render_to_string("email/cocreate_collaborate.txt", { #'name':name, 'email': email, 'user':request.user.username, 'reg_link':reg_link, }) send_mail(subject, message, from_mail, [email], fail_silently=False) """ context = {"success": True} messages.success(request, 'An invitation has been sent to %s.' % email) if request.is_ajax(): return HttpResponse(simplejson.dumps({ 'status': 'OK', 'pk': invited_user.pk, 'username': invited_user.username }), mimetype='application/json') else: messages.error(request, 'Failed to send invitation.') if request.is_ajax(): return HttpResponse(simplejson.dumps({ 'status': 'ERROR', 'errors': form.errors }), mimetype='application/json') return redirect(reverse('cocreate', args=[ cocreate.id, ]))