Esempio n. 1
0
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        invite_email = dataplus.dictGetVal(request.REQUEST,'invite_email')
        is_valid, err_msg = codejar_validation.validateEmail(invite_email)
        if not is_valid:
            return ajaxian.getFailureResp('invalid_email')

        #see if a user with the same email exists
        user = dataplus.returnIfExists(models.User.objects.filter(email=invite_email))
        if user:
            if user.username == myself.username:
                return ajaxian.getSuccessResp('cannot_add_self')

        invitation = models.FriendInvitation(sent_by=myself, sent_to_email=invite_email)
        invitation.invite_random_key = dataplus.getUniqueId()
        invitation.save()
        
        subject = myself.name + ' has invited you to Socialray'
        html_file = '/apps/socialray/website/bigfoot/websitetools/mailtemplates/invitation.html'
        text_file = '/apps/socialray/website/bigfoot/websitetools/mailtemplates/invitation.txt'
        
        mailer.sendInvite(html_file, text_file, myself, subject, (invite_email), 
            {'name':lambda x:x.name,  
            'username':lambda x:x.username,
            'message':lambda x:'',
            'invite_random_key':lambda x:str(invitation.invite_random_key)})
        return ajaxian.getSuccessResp('')
    
    except:
        return ajaxian.getFailureResp('unknown')
Esempio n. 2
0
def processEmails(email_ids, message, myself):
    has_valid_emails = False

    for email_id in email_ids:
        email_id = (email_id,email_id.strip(',')) [email_id.find(',') >= 0]
        success, error = codejar_validation.validateEmail(email_id)

        if success:
            has_valid_emails = True
            
            user = dataplus.returnIfExists(models.User.objects.filter(email=email_id))
            if user:                      
                if user.username == myself.username: continue
                
            #need to add code to add existing user for email to friends list if not added
                                    
            invitation = models.FriendInvitation(sent_by=myself, sent_to_email=email_id)
            invitation.invite_random_key = dataplus.getUniqueId()
            invitation.save()                  
           
            subject = myself.name + ' has invited you to Socialray'
            html_file = '/apps/socialray/website/bigfoot/websitetools/mailtemplates/invitation.html'
            text_file = '/apps/socialray/website/bigfoot/websitetools/mailtemplates/invitation.txt'
            
            mailer.sendInvite(html_file, text_file, myself, subject, (email_id), 
                {'name':lambda x:x.name, 
                'username':lambda x:x.username,
                'message':lambda x:(x.name.split()[1],x.name.split()[0])[len(x.name.split()[0]) > 1] + '... says, "' + message + '"',
                'invite_random_key':lambda x:str(invitation.invite_random_key)})
            
    return has_valid_emails