def save_and_notify(self, notify=True): self.save() # notify user that they have a friend request if not notify: return True ctx = { 'actor': self.from_user.get_profile(), 'actee': self.to_user.get_profile(), 'actor_child': self.from_child, 'actee_child': self.to_child, 'message': self.message } create_message(self.from_user, self.to_user, 'playlist_request_received', ctx, category='Friend Request', associated_item=self.id) email_pref = get_message_preference(self.to_user, 'friend_related') if email_pref: send_email(self.to_user.email, 'playlist_request_received', ctx)
def accept_and_notify(self, notify=True): self.accept() # notify user that friend request accepted # notify friends that connection has been made if not notify: return True ctx = { 'actor': self.to_user.get_profile(), 'actee': self.from_user.get_profile(), 'actor_child': self.to_child, 'actee_child': self.from_child } create_message(self.to_user, self.from_user, 'playlist_request_confirmed', ctx, category='Message', respond=False) email_pref = get_message_preference(self.from_user, 'friend_related') if email_pref: send_email(self.from_user.email, 'playlist_request_confirmed', ctx)
def send_invitation(self, from_user, contact, to_email, message=None): salt = sha_constructor(str(random())).hexdigest()[:5] confirmation_key = sha_constructor(salt + to_email).hexdigest() accept_url = u"http://%s%s" % ( settings.WWW_HOST, reverse("acct_signup_key", args=(confirmation_key,)), ) ctx = { "SITE_NAME": unicode(Site.objects.get_current()), "CONTACT_EMAIL": settings.DEFAULT_FROM_EMAIL, "contact": contact, "email": to_email, "user": from_user, "actor": from_user.get_profile(), "message": message, "accept_url": accept_url, } # subject = render_to_string("friends/join_invite_subject.txt", ctx) # subject = subject.rstrip() # email_message = render_to_string("friends/join_invite_message.txt", ctx) send_email(to_email, 'join_invitation', ctx = ctx, skip_footer = True) # send_html_mail(subject, 'text message', email_message, settings.DEFAULT_FROM_EMAIL, [to_email]) # send_mail(subject, email_message, settings.DEFAULT_FROM_EMAIL, [to_email]) return self.create(from_user=from_user, contact=contact, message=message, status="2", confirmation_key=confirmation_key)
def send_invitation(self, from_user, contact, to_email, message=None): salt = sha_constructor(str(random())).hexdigest()[:5] confirmation_key = sha_constructor(salt + to_email).hexdigest() accept_url = u"http://%s%s" % ( settings.WWW_HOST, reverse("acct_signup_key", args=(confirmation_key, )), ) ctx = { "SITE_NAME": unicode(Site.objects.get_current()), "CONTACT_EMAIL": settings.DEFAULT_FROM_EMAIL, "contact": contact, "email": to_email, "user": from_user, "actor": from_user.get_profile(), "message": message, "accept_url": accept_url, } # subject = render_to_string("friends/join_invite_subject.txt", ctx) # subject = subject.rstrip() # email_message = render_to_string("friends/join_invite_message.txt", ctx) send_email(to_email, 'join_invitation', ctx=ctx, skip_footer=True) # send_html_mail(subject, 'text message', email_message, settings.DEFAULT_FROM_EMAIL, [to_email]) # send_mail(subject, email_message, settings.DEFAULT_FROM_EMAIL, [to_email]) return self.create(from_user=from_user, contact=contact, message=message, status="2", confirmation_key=confirmation_key)
def notify_invitee(self, notify, ctx, message_type): if not notify: return True ctx.update({ 'this_invite':self, }) send_email(self.email, message_type, ctx)
def save(self, request=None): # don't assume a username is available. it is a common removal if # site developer wants to use e-mail authentication. # username = self.cleaned_data.get("username") email = self.cleaned_data["email"].strip().lower() password = self.cleaned_data.get("password1") profile_data = { 'first_name': self.cleaned_data["first_name"], 'last_name': self.cleaned_data["last_name"], 'zip_code': self.cleaned_data["zip_code"], 'gender': self.cleaned_data["gender"], 'source': request.session.get('source', settings.DEFAULT_SOURCE) } is_join_invitation = False if self.cleaned_data["confirmation_key"]: from friends.models import JoinInvitationEmail # @@@ temporary fix for issue 93 try: join_invitation = JoinInvitationEmail.objects.get(confirmation_key=self.cleaned_data["confirmation_key"]) is_join_invitation = True except JoinInvitationEmail.DoesNotExist: pass new_user = self.create_user(profile_data['first_name'],profile_data['last_name'],email, password) new_profile = None try: new_profile = self.create_profile(new_user, profile_data) except: pass if new_profile is None: new_user.delete() raise Exception('User creation failed. Please try again later') else: if is_join_invitation: join_invitation.accept(new_user) # should go before creation of EmailAddress below if email == join_invitation.contact.email: EmailAddress(user=new_user, email=email, verified=True, primary=True).save() send_email(new_user.email, 'welcome_email', ctx = { 'actor':new_profile }, skip_footer=True) else: EmailAddress.objects.add_email(new_user, email) if EMAIL_VERIFICATION: new_user.is_active = False new_user.save() self.after_signup(new_user) return new_user
def confirm_email(request, confirmation_key): confirmation_key = confirmation_key.lower() email_address = EmailConfirmation.objects.confirm_email(confirmation_key) if email_address is not None: request.session["message"] = "You have verified " + str(email_address.email) + " as your address." send_email( email_address.email, "welcome_email", ctx={"actor": email_address.user.get_profile()}, skip_footer=True ) else: request.session["message"] = "Invalid confirmation key." return HttpResponseRedirect(reverse("acct_login"))
def notify_invitee(self, notify, ctx, message_type): if not notify: return True ctx.update({ 'this_invite':self, }) create_message(self.playdate.organizer, self.to_user, message_type, ctx, respond=False) email_pref = get_message_preference(self.to_user, 'playdate_attendee_related') if email_pref: send_email(self.to_user.email, message_type, ctx)
def confirm_email(request, confirmation_key): confirmation_key = confirmation_key.lower() email_address = EmailConfirmation.objects.confirm_email(confirmation_key) if email_address is not None: request.session["message"] = 'You have verified ' + str( email_address.email) + ' as your address.' send_email(email_address.email, 'welcome_email', ctx={'actor': email_address.user.get_profile()}, skip_footer=True) else: request.session["message"] = 'Invalid confirmation key.' return HttpResponseRedirect(reverse("acct_login"))
def notify_organizer(self, notify, message_type): if not notify: return True ctx = { 'email': self.email, 'actee': self.playdate.organizer.get_profile(), 'actee_child': self.organizer_child, 'response':self.response, 'playdate':self.playdate, 'active_invite':self, } create_message_anon(self.playdate.organizer, message_type, ctx) email_pref = get_message_preference(self.playdate.organizer, 'playdate_host_related') if email_pref: send_email(self.playdate.organizer.email, message_type, ctx)
def send_confirmation(self, email_address): salt = sha_constructor(str(random())).hexdigest()[:5] confirmation_key = sha_constructor(salt + email_address.email).hexdigest() current_site = Site.objects.get_current() # check for the url with the dotted view path try: path = reverse("emailconfirmation.views.confirm_email", args=[confirmation_key]) except NoReverseMatch: # or get path with named urlconf instead path = reverse( "emailconfirmation_confirm_email", args=[confirmation_key]) protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http") activate_url = u"%s://%s%s" % ( protocol, settings.WWW_HOST, path ) ctx = { "user": email_address.user, "activate_url": activate_url, "current_site": current_site, "confirmation_key": confirmation_key, } # subject = render_to_string( # "emailconfirmation/email_confirmation_subject.txt", context) # remove superfluous line breaks # subject = "".join(subject.splitlines()) # message = render_to_string( # "emailconfirmation/email_confirmation_message.txt", context) # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, # [email_address.email], priority="high") send_email(email_address.email, 'email_confirmation', ctx=ctx, skip_footer=True) return self.create( email_address=email_address, sent=datetime.now(), confirmation_key=confirmation_key)
def accept_and_notify(self, notify=True): self.accept() # notify user that friend request accepted # notify friends that connection has been made if not notify: return True ctx = { 'actor': self.to_user.get_profile(), 'actee': self.from_user.get_profile(), 'actor_child':self.to_child, 'actee_child':self.from_child } create_message(self.to_user, self.from_user, 'playlist_request_confirmed', ctx, category='Message', respond=False ) email_pref = get_message_preference(self.from_user, 'friend_related') if email_pref: send_email(self.from_user.email, 'playlist_request_confirmed', ctx)
def save_and_notify(self, notify=True): self.save() # notify user that they have a friend request if not notify: return True ctx = { 'actor': self.from_user.get_profile(), 'actee': self.to_user.get_profile(), 'actor_child':self.from_child, 'actee_child':self.to_child, 'message':self.message } create_message(self.from_user, self.to_user, 'playlist_request_received', ctx, category='Friend Request', associated_item=self.id ) email_pref = get_message_preference(self.to_user, 'friend_related') if email_pref: send_email(self.to_user.email, 'playlist_request_received', ctx)
def send_confirmation(self, email_address): salt = sha_constructor(str(random())).hexdigest()[:5] confirmation_key = sha_constructor(salt + email_address.email).hexdigest() current_site = Site.objects.get_current() # check for the url with the dotted view path try: path = reverse("emailconfirmation.views.confirm_email", args=[confirmation_key]) except NoReverseMatch: # or get path with named urlconf instead path = reverse("emailconfirmation_confirm_email", args=[confirmation_key]) protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http") activate_url = u"%s://%s%s" % (protocol, settings.WWW_HOST, path) ctx = { "user": email_address.user, "activate_url": activate_url, "current_site": current_site, "confirmation_key": confirmation_key, } # subject = render_to_string( # "emailconfirmation/email_confirmation_subject.txt", context) # remove superfluous line breaks # subject = "".join(subject.splitlines()) # message = render_to_string( # "emailconfirmation/email_confirmation_message.txt", context) # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, # [email_address.email], priority="high") send_email(email_address.email, 'email_confirmation', ctx=ctx, skip_footer=True) return self.create(email_address=email_address, sent=datetime.now(), confirmation_key=confirmation_key)
sys.path.append('/var/www/playdation.net') sys.path.append('/var/www/playdation.net/playdation') sys.path.append('/var/www/playdation.net/playdation/apps') from playdation import settings setup_environ(settings) from django.db import connection from django import db from mydebug import * from notify.models import MessagePreference, MessagePreferenceDefaults, Update, InternalMessage, Email, FBPost, create_message_content, create_message, get_message_content, inbox_count_for, create_update, send_email from profiles.models import Child from django.contrib.auth.models import User from playdates.models import * import time max_limit = 5 f = open("/tmp/emails.list") for line in f: print "sending to: " + line.rstrip() send_email(line.rstrip(), 'beta_2_invite', ctx={}, skip_footer=True) time.sleep(5) f.close()
sys.path.append('/var/www/playdation.net') sys.path.append('/var/www/playdation.net/playdation') sys.path.append('/var/www/playdation.net/playdation/apps') from playdation import settings setup_environ(settings) from django.db import connection from django import db from mydebug import * from notify.models import MessagePreference, MessagePreferenceDefaults, Update, InternalMessage, Email, FBPost, create_message_content, create_message, get_message_content, inbox_count_for, create_update, send_email from profiles.models import Child from django.contrib.auth.models import User from playdates.models import * import time max_limit=5 f = open("/tmp/emails.list") for line in f: print "sending to: " + line.rstrip() send_email(line.rstrip(), 'beta_2_invite', ctx={}, skip_footer=True) time.sleep(5) f.close()
def connect_login(request): import account.graphapi as facebook token = uid = fb_exists = name = None fb_user = facebook.get_user_from_cookie(request.COOKIES, settings.FB_API_KEY, settings.FB_SECRET_KEY) if fb_user is None: return HttpResponseRedirect(reverse("nl_home")) token = fb_user['access_token'] uid = fb_user['uid'] try: fb_user = FacebookUser.objects.select_related('user').get( facebook_id=uid) if (token is not None) and (fb_user.access_token != token): fb_user.access_token = token fb_user.save() user = fb_user.user user.backend = "django.contrib.auth.backends.ModelBackend" perform_login(request, user) return HttpResponseRedirect(reverse("home")) except FacebookUser.DoesNotExist: pass fb_api = facebook.GraphAPI(fb_user['access_token']) data = fb_api.get_object("me") todebug(data) zs = None if 'location' in data: location = data['location'] zs = determine_zip(location) profile_data = { 'first_name': data.get('first_name', None), 'last_name': data.get('last_name', None), 'email': data.get('email', None), 'name': data.get('name', None), 'gender': data.get("gender", 'female'), 'fb_id': uid, 'fb_stream_publish': False, 'fb_login': True, 'fb_account_linked': True, 'source': request.session.get('source', settings.DEFAULT_SOURCE), 'zip_code': zs, } try: check_user = User.objects.get(email=profile_data['email']) request.session[ "message"] = "Your email address is already registered. Please log in" return HttpResponseRedirect(reverse("acct_login")) except User.DoesNotExist: pass new_user = create_user(profile_data['first_name'], profile_data['last_name'], profile_data['email'], 'nrd9371933722#2') new_profile = None try: new_profile = create_profile(new_user, profile_data) except: import sys todebug("Unexpected error:" + str(sys.exc_info()[0])) new_user.delete() fb_user = create_fbuser(new_user, uid, token, name=profile_data['name']) new_user.backend = "django.contrib.auth.backends.ModelBackend" perform_login(request, new_user) args = { 'link': 'http://' + settings.WWW_HOST + reverse("nl_home"), 'attribution': 'Playdation', 'name': new_profile.first_name + "'s life just got easier. " + new_profile.third_person + " just joined Playdation!", 'description': "Playdation is what the other parents and I are now using to schedule our children's playdates.", 'picture': 'http://' + settings.WWW_HOST + '/static/images/pd_square.png', } # post_to_own_facebook(token, 'user_joined', { 'actor': new_profile }, **args) send_email(new_user.email, 'welcome_email', ctx={'actor': new_profile}, skip_footer=True) if "confirmation_key" in request.session: ck = request.session["confirmation_key"] from friends.models import JoinInvitationEmail try: join_invitation = JoinInvitationEmail.objects.get( confirmation_key=ck) join_invitation.accept( new_user) # should go before creation of EmailAddress below except JoinInvitationEmail.DoesNotExist: pass request.session["new_user"] = True request.session["event"] = 'Facebook Registration' return HttpResponseRedirect(reverse("signup_add_children"))
def save(self, request=None): # don't assume a username is available. it is a common removal if # site developer wants to use e-mail authentication. # username = self.cleaned_data.get("username") email = self.cleaned_data["email"].strip().lower() password = self.cleaned_data.get("password1") profile_data = { 'first_name': self.cleaned_data["first_name"], 'last_name': self.cleaned_data["last_name"], 'zip_code': self.cleaned_data["zip_code"], 'gender': self.cleaned_data["gender"], 'source': request.session.get('source', settings.DEFAULT_SOURCE) } is_join_invitation = False if self.cleaned_data["confirmation_key"]: from friends.models import JoinInvitationEmail # @@@ temporary fix for issue 93 try: join_invitation = JoinInvitationEmail.objects.get( confirmation_key=self.cleaned_data["confirmation_key"]) is_join_invitation = True except JoinInvitationEmail.DoesNotExist: pass new_user = self.create_user(profile_data['first_name'], profile_data['last_name'], email, password) new_profile = None try: new_profile = self.create_profile(new_user, profile_data) except: pass if new_profile is None: new_user.delete() raise Exception('User creation failed. Please try again later') else: if is_join_invitation: join_invitation.accept( new_user ) # should go before creation of EmailAddress below if email == join_invitation.contact.email: EmailAddress(user=new_user, email=email, verified=True, primary=True).save() send_email(new_user.email, 'welcome_email', ctx={'actor': new_profile}, skip_footer=True) else: EmailAddress.objects.add_email(new_user, email) if EMAIL_VERIFICATION: new_user.is_active = False new_user.save() self.after_signup(new_user) return new_user
def connect_login(request): import account.graphapi as facebook token = uid = fb_exists = name = None fb_user = facebook.get_user_from_cookie(request.COOKIES, settings.FB_API_KEY, settings.FB_SECRET_KEY) if fb_user is None: return HttpResponseRedirect(reverse("nl_home")) token = fb_user["access_token"] uid = fb_user["uid"] try: fb_user = FacebookUser.objects.select_related("user").get(facebook_id=uid) if (token is not None) and (fb_user.access_token != token): fb_user.access_token = token fb_user.save() user = fb_user.user user.backend = "django.contrib.auth.backends.ModelBackend" perform_login(request, user) return HttpResponseRedirect(reverse("home")) except FacebookUser.DoesNotExist: pass fb_api = facebook.GraphAPI(fb_user["access_token"]) data = fb_api.get_object("me") todebug(data) zs = None if "location" in data: location = data["location"] zs = determine_zip(location) profile_data = { "first_name": data.get("first_name", None), "last_name": data.get("last_name", None), "email": data.get("email", None), "name": data.get("name", None), "gender": data.get("gender", "female"), "fb_id": uid, "fb_stream_publish": False, "fb_login": True, "fb_account_linked": True, "source": request.session.get("source", settings.DEFAULT_SOURCE), "zip_code": zs, } try: check_user = User.objects.get(email=profile_data["email"]) request.session["message"] = "Your email address is already registered. Please log in" return HttpResponseRedirect(reverse("acct_login")) except User.DoesNotExist: pass new_user = create_user( profile_data["first_name"], profile_data["last_name"], profile_data["email"], "nrd9371933722#2" ) new_profile = None try: new_profile = create_profile(new_user, profile_data) except: import sys todebug("Unexpected error:" + str(sys.exc_info()[0])) new_user.delete() fb_user = create_fbuser(new_user, uid, token, name=profile_data["name"]) new_user.backend = "django.contrib.auth.backends.ModelBackend" perform_login(request, new_user) args = { "link": "http://" + settings.WWW_HOST + reverse("nl_home"), "attribution": "Playdation", "name": new_profile.first_name + "'s life just got easier. " + new_profile.third_person + " just joined Playdation!", "description": "Playdation is what the other parents and I are now using to schedule our children's playdates.", "picture": "http://" + settings.WWW_HOST + "/static/images/pd_square.png", } # post_to_own_facebook(token, 'user_joined', { 'actor': new_profile }, **args) send_email(new_user.email, "welcome_email", ctx={"actor": new_profile}, skip_footer=True) if "confirmation_key" in request.session: ck = request.session["confirmation_key"] from friends.models import JoinInvitationEmail try: join_invitation = JoinInvitationEmail.objects.get(confirmation_key=ck) join_invitation.accept(new_user) # should go before creation of EmailAddress below except JoinInvitationEmail.DoesNotExist: pass request.session["new_user"] = True request.session["event"] = "Facebook Registration" return HttpResponseRedirect(reverse("signup_add_children"))