예제 #1
0
파일: resources.py 프로젝트: baziz/twt
	def is_valid(self, bundle, request=None):
		if not bundle.data:
			return {'__all__': 'Not quite what I had in mind.'}
		errors = {}
		mySuggestorID = filter(None, re.split("\/+",bundle.data.get('suggestorID', '')))[-1]
		myOfUserID = str(bundle.data.get('ofUserID', ''))
		myToUserID = str(bundle.data.get('toUserID', ''))
		mySuggestionStatus = bundle.data.get('suggestionStatus', '')
		toUser = User.objects.get(twtID=myToUserID)
		if myOfUserID == myToUserID:
			errors['error_message'] = 'suggesttoThemselves'
		elif suggestions.objects.filter(suggestorID=mySuggestorID,ofUserID=myOfUserID, toUserID=myToUserID) and mySuggestionStatus == 'pending':
			errors['error_message'] = 'duplicateSuggestion' + myOfUserID
		elif mySuggestorID == myToUserID:	
			if likes.objects.filter(likedUserID=myOfUserID, likerID=myToUserID):
				errors['error_message'] = 'likedAlready'
			else:
				likes(likeDate=datetime.datetime.now(),likedUserID=myOfUserID,likerID=toUser).save()
			bundle.obj.suggestionStatus = 'liked'
			mySuggestionStatus = 'liked'
			User.objects.filter(twtID=myOfUserID).update(likeCount=F('likeCount')+1)
		#	errors['error_message'] = 'suggestToMyself'
		#elif not (wings.objects.filter(wingerID=mySuggestorID,wingUserID=myToUserID, wingStatus='accepted') or wings.objects.filter(wingerID=myToUserID,wingUserID=mySuggestorID, wingStatus='accepted')):
		#	bundle.data['nonWing'] = True
		if not errors and mySuggestionStatus == 'pending':
			myKarma = User.objects.get(twtID=mySuggestorID).karma + 3
			User.objects.filter(twtID=mySuggestorID).update(karma=myKarma)	
			User.objects.filter(twtID=myOfUserID).update(suggCount=F('suggCount')+1)
			suggestorAug = urllib.urlopen('https://graph.facebook.com/'+str(mySuggestorID)).read()
			ofUserAug = urllib.urlopen('https://graph.facebook.com/'+str(myOfUserID)).read()
			myNotifVals = mySuggestorID +","+ json.loads(suggestorAug)['name'] +","+ myOfUserID +","+ json.loads(ofUserAug)['name']

			#if bundle.data.get('nonWing',''):
			#	notifications(writeDate=datetime.datetime.now(), notifID=toUser, notifType='suggestion', readStatus=False, status='pending', notifVals=myNotifVals).save()				
			#else:
			notifications(writeDate=datetime.datetime.now(), notifID=toUser, notifType='suggestion', readStatus=False, status='', notifVals=myNotifVals).save()				
			if toUser.email:
				mailMessage = json.loads(suggestorAug)['name'] + " has suggested someone for you on Twowaytag."
				mailTail = """Visit the site at: 
							
		http://beta.twowaytag.com

		Twowaytag is a site where single people and even coupled people make suggestions for each other 
		and singles keep track of who they're interested in.  We keep things really private and fun.  
		It's all Facebook-enabled, so no need to fill out a profile, and no one but your wings will know
		you're on the site.  
		"""
				send_mail(mailMessage, mailMessage+mailTail, '*****@*****.**',[toUser.email], fail_silently=False)
			
		return errors
예제 #2
0
파일: resources.py 프로젝트: baziz/twt
	def is_valid(self, bundle, request=None):
		if not bundle.data:
			return {'__all__': 'Not quite what I had in mind.'}
		errors = {}
		myWingerID = filter(None, re.split("\/+",bundle.data.get('wingerID', '')))[-1]
		myWingUserID = str(bundle.data.get('wingUserID', ''))
		myWingStatus = bundle.data.get('wingStatus','')
		if myWingerID == myWingUserID:
			errors['error_message'] = 'selfWinging'
		# case if b rejected a's invite, but changed heart and wants to invite a again
		elif wings.objects.filter(wingerID=myWingUserID,wingUserID=myWingerID, wingStatus="rejected" ):
			wings.objects.filter(wingerID=myWingUserID,wingUserID=myWingerID, wingStatus="rejected" ).delete()	
		elif wings.objects.filter(wingerID=myWingerID,wingUserID=myWingUserID, wingStatus="accepted" ) or wings.objects.filter(wingerID=myWingUserID,wingUserID=myWingerID, wingStatus="accepted") :
			errors['error_message'] = 'alreadyAWing'
		elif wings.objects.filter(wingerID=myWingerID,wingUserID=myWingUserID).exclude(wingStatus='accepted') and myWingStatus!='rejected' and myWingStatus!='accepted':
			errors['error_message'] = 'youSentWingInviteAlready'
		elif wings.objects.filter(wingerID=myWingUserID,wingUserID=myWingerID):
			errors['error_message'] = 'theyWingedAlready'
		if not errors and myWingStatus != 'rejected':
			winger = User.objects.get(twtID=myWingerID)
			winged = User.objects.get(twtID=myWingUserID)
			myKarma = winger.karma + 10
			User.objects.filter(twtID=myWingerID).update(karma=myKarma)
			#send_mail('Subject here', 'Here is the message.', '*****@*****.**',['*****@*****.**'], fail_silently=False)
			#FBResponse = json.loads(urllib.urlopen('https://graph.facebook.com/'+myWingdUserID).reads())			
			if winged.email:
				mailTail = """Visit the site at: 
						
	http://beta.twowaytag.com

	Twowaytag is a site where single people and even coupled people make suggestions for each other 
	and singles keep track of who they're interested in.  We keep things really private and fun.  
	It's all Facebook-enabled, so no need to fill out a profile, and no one but your wings will know
	you're on the site.  
	"""
				if myWingStatus == 'accepted':
					wingedAug = urllib.urlopen('https://graph.facebook.com/'+str(myWingUserID)).read()
					mailMessage = json.loads(wingedAug)['name'] + " is now your wing on Twowaytag. "
					send_mail(mailMessage, mailMessage+mailTail, '*****@*****.**',[winger.email], fail_silently=False)
				else:
					wingerAug = urllib.urlopen('https://graph.facebook.com/'+str(myWingerID)).read()
					mailMessage =  json.loads(wingerAug)['name'] + " has invited you to be their wingman on Twowaytag. "
					send_mail(mailMessage, mailMessage+mailTail, '*****@*****.**',[winged.email], fail_silently=False)
			if myWingStatus == 'accepted':
				notifications(writeDate=datetime.datetime.now(), notifID=winger, notifType='wingAccepted', readStatus=False, status='', notifVals=myWingUserID).save()
			else:
				notifications(writeDate=datetime.datetime.now(), notifID=winged, notifType='wingInvited', readStatus=False, status='', notifVals=myWingerID).save()				
		return errors
def signup(request):
    if request.method =='POST':
        storage = messages.get_messages(request)
        storage.used = True
        user_form = UserForm(request.POST)
        if request.POST.get('password') == request.POST.get('confirm_password'):
            email = request.POST.get('email')
            try:
                email_check = User.objects.get(email=email) 
            except:
                email_check = None
            if email_check is None:

                username = request.POST.get('username')
                try:
                    username_check = User.objects.get(username=username)
                except:
                    username_check = None
                if username_check is None:

                    if user_form.is_valid():
                        user = user_form.save(commit=False)
                        user.set_password(user.password)
                        user.save()
                        notif = notifications()
                        notif.user = user
                        notif.save()
                        return render(request,'login/index.html')
                    else:
                        messages.error(request, 'Invalid Submission')
                        return render(request, 'login/signup.html', {'user_form': user_form})
                else:
                    messages.error(request, 'Username already exists')
                    return render(request, 'login/signup.html', {'user_form': user_form})
            else:
                messages.error(request, 'Email already exists')
                return render(request, 'login/signup.html', {'user_form': user_form})
        else:
            messages.error(request, 'passwords do not match')
            return render(request, 'login/signup.html', {'user_form': user_form})
    else:
        storage = messages.get_messages(request)
        storage.used = True
        
        user_form = UserForm()
        
        return render(request, 'login/signup.html', {'user_form': user_form})