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
Esempio n. 3
0
def validateRequest(request):
    if dataplus.dictGetVal(request.REQUEST,'username') == '' or dataplus.dictGetVal(request.REQUEST,'name') == '' or dataplus.dictGetVal(request.REQUEST,'email') == '' or dataplus.dictGetVal(request.REQUEST,'password1') == '' or dataplus.dictGetVal(request.REQUEST,'password2') == '':
        return False, errorResponse('All fields are required.', request)
    
    result, errMsg = dataplus.validateErrorConditions(
        [lambda : codejar_validation.validateUsername(dataplus.dictGetVal(request.REQUEST,'username')),
        lambda : codejar_validation.validateName(dataplus.dictGetVal(request.REQUEST,'name')),
        lambda : codejar_validation.validateEmail(dataplus.dictGetVal(request.REQUEST,'email')),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'password1'), 6, 16, 'Password'),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'email'), 5, 75, 'Email')
        ])
    if not result:
        return result, errorResponse(errMsg, request)    
    elif dataplus.dictGetVal(request.REQUEST,'password1') != dataplus.dictGetVal(request.REQUEST,'password2'):
        return False, errorResponse('Passwords do not match.', request)
    elif dataplus.dictGetVal(request.REQUEST,'captcha_text') != request.session['signup_captcha_text']:
        return False, errorResponse('The captcha text entered is incorrect.', request)
    else:
        return True, None
Esempio n. 4
0
def validateRequest(request):
    if not dataplus.dictGetVal(request.REQUEST, 'acceptterms', False, lambda x:True):
        return False, errorResponse('Please accept the terms and conditions to continue.',request)
        
    if dataplus.dictGetVal(request.REQUEST,'user-name') == '' or dataplus.dictGetVal(request.REQUEST,'name') == '' or dataplus.dictGetVal(request.REQUEST,'email') == '' or dataplus.dictGetVal(request.REQUEST,'password1') == '' or dataplus.dictGetVal(request.REQUEST,'password2') == '' or dataplus.dictGetVal(request.REQUEST,'country') == '' or dataplus.dictGetVal(request.REQUEST,'industry_category') == '' or dataplus.dictGetVal(request.REQUEST,'experience') == '-1':
        return False, errorResponse('All fields are required.', request)
    
    result, errMsg = dataplus.validateErrorConditions(
        [lambda : codejar_validation.validateName(dataplus.dictGetVal(request.REQUEST,'name')),
        lambda : codejar_validation.validateUsername(dataplus.dictGetVal(request.REQUEST,'user-name')),
        lambda : codejar_validation.validateEmail(dataplus.dictGetVal(request.REQUEST,'email')),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'password1'), 6, 16, 'Password'),
        lambda : dataplus.isLengthValid(dataplus.dictGetVal(request.REQUEST,'email'), 5, 75, 'Email')
        ])
    if not result:
        return result, errorResponse(errMsg, request)    
    elif dataplus.dictGetVal(request.REQUEST,'password1') != dataplus.dictGetVal(request.REQUEST,'password2'):
        return False, errorResponse('Passwords do not match.', request)
    elif models.Account.objects.filter(username=dataplus.dictGetVal(request.REQUEST, 'user-name')).count() > 0:
        return False, errorResponse('Username already exists. Please choose another.', request)
    else:
        return True, None
Esempio n. 5
0
def handle(request):  
    account = siteaction.getLoggedInAccount(request)
    if not account:
        return HttpResponseRedirect('/login.htm')
    
    #TODO: notify user about success, success_page will change
    logged_in_type = siteaction.getLoggedInAccountType(request)
    if logged_in_type == 'U':
        entry_page = 'me/changeemail.htm'
        success_page = '/me/editsettings.htm?flashId=email_chnged'
        error_page = 'me/showmessage.htm'
        myself = siteaction.getLoggedInUser(request)
    elif logged_in_type == 'R':
        entry_page = 'recruiters/changeemail.htm'    
        success_page = '/recruiters/'
        error_page = 'recruiters/showmessage.htm'
        myself = siteaction.getLoggedInRecruiter(request)
    
    if request.method == 'GET':
        return siteaction.render_to_response(entry_page, {'myself':myself})

    elif request.method == 'POST':
        #Password Check
        if (siteaction.validatePassword(myself.account.id, dataplus.dictGetVal(request.REQUEST, 'password'))):
            
            result, errMsg = codejar_validation.validateEmail(dataplus.dictGetVal(request.REQUEST,'email'))
            if not result:
                return siteaction.render_to_response(error_page, {'myself':myself, 'msg_heading':'Error', 'msg_html':'Invalid user input.'})
            
            email_address = dataplus.dictGetSafeVal(request.REQUEST, 'email')
            account.email = email_address
            account.save()
            myself.email = email_address
            myself.save()
            return HttpResponseRedirect(success_page)
        else:
            return siteaction.render_to_response(entry_page, 
                {'error_html': '<p class="error-note">Password was incorrect. Try again.</p>'})
Esempio n. 6
0
def handle(request, comm_id):
    community = models.Community.objects.get(id=comm_id)
    community.image_url = dataplus.getStaticUrl(community.image_size3_file_path)
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect("/login.htm")

    if community.members.filter(id=myself.id).count() == 0:
        return siteaction.render_to_response(
            "me/showmessage.htm", {"myself": myself, "msg_heading": "Error", "msg_html": "Access denied"}
        )

    action = dataplus.dictGetVal(request.REQUEST, "action")

    if request.method == "GET":
        action_result = ""
        if dataplus.dictGetVal(request.REQUEST, "flashId"):
            action_result = dataplus.dictGetVal(
                statix.action_messages, dataplus.dictGetVal(request.REQUEST, "flashId"), ""
            )

        return siteaction.render_to_response(
            "communities/invite.htm",
            {
                "community": community,
                "friend_count": myself.friends.count(),
                "friends_html": getFriendsTable(myself, community),
                "invite_more": (action == "invite_more"),
                "action_result": action_result,
                "myself": myself,
            },
        )

    elif request.method == "POST":
        if action == "external_invite":
            message = dataplus.dictGetSafeVal(request.REQUEST, "msgToMembers", "")
            add_to_friend_list = dataplus.dictGetVal(request.REQUEST, "add_to_friend_list", False, lambda x: True)
            has_valid_emails = False

            for i in range(1, 6):
                email = dataplus.dictGetVal(request.REQUEST, "email" + str(i), "").strip()
                success, error = codejar_validation.validateEmail(email)

                if success:
                    has_valid_emails = True

                    invitation = models.FriendInvitation(sent_by=myself, sent_to_email=email)
                    invitation.invite_random_key = dataplus.getUniqueId()
                    invitation.save()

                    comm_invite = models.CommunityInvitation(sent_by=myself, community=community)
                    comm_invite.invite_random_key = invitation.invite_random_key
                    comm_invite.save()

                    sender = '"' + myself.name + '" <' + myself.username + "*****@*****.**>"
                    subject = myself.name + " has invited you to join " + community.name + " - Socialray"
                    if add_to_friend_list:
                        accept_url = (
                            config.server_base_url
                            + "/me/acceptinvite.htm?commFriendInviteId="
                            + str(invitation.invite_random_key)
                        )
                    else:
                        accept_url = (
                            config.server_base_url
                            + "/me/acceptinvite.htm?commInviteId="
                            + str(invitation.invite_random_key)
                        )

                    html_message = (
                        '<p><a href="'
                        + config.server_base_url
                        + "/profiles/"
                        + myself.username
                        + '">'
                        + myself.name
                        + "</a>"
                        + " feels that you will be interested in joining the "
                        + community.name
                        + " Community in Socialray and has sent you the following message:</p>"
                        + "<p>"
                        + dataplus.replaceHtmlLineBreaks(message)
                        + "</p>"
                        + '<p>To accept this invitation and create an account, visit <a href="'
                        + accept_url
                        + '">'
                        + accept_url
                        + "</a> "
                        + "<br />Once you create your account, "
                        + myself.name
                        + " will be connected to you as a friend.</p>"
                        + "<p>Regards,<br />from Socialray</p>"
                    )

                    text_message = (
                        myself.name
                        + " feels that you will be interested in joining the "
                        + community.name
                        + " Community in Socialray and has sent you the following message:\r\n"
                        + message
                        + "\r\n\r\n"
                        + "To accept this invitation and create an account, visit - "
                        + accept_url
                        + " \r\n"
                        + "Once you create your account, "
                        + myself.name
                        + " will be connected to you as a friend.\r\n"
                        + "You can check "
                        + myself.name
                        + "'s profile at "
                        + config.server_base_url
                        + "/profiles/"
                        + myself.username
                        + "\r\n\r\n"
                        + "Regards,\r\n"
                        + "from Socialray\r\n\r\n"
                    )

                    mailman.sendMail(
                        sender, [email], subject, html_message, None, None, text_message, reply_to=myself.email
                    )
            if not has_valid_emails:
                return siteaction.render_to_response(
                    "communities/invite.htm",
                    {
                        "community": community,
                        "friend_count": myself.friends.count(),
                        "friends_html": getFriendsTable(myself, community),
                        "myself": myself,
                    },
                )

        elif action == "internal_invite":
            message = dataplus.dictGetSafeVal(request.REQUEST, "msgToFriends", "")
            friend_count = dataplus.dictGetVal(request.REQUEST, "friendCount", 0, string.atoi)

            has_selected_users = False
            for i in range(1, friend_count + 1):
                chk_id = dataplus.dictGetVal(request.REQUEST, "checkbox" + str(i))
                if chk_id:
                    user = models.User.objects.get(id=chk_id)
                    has_selected_users = True
                    sendCommunityInvitationToUser(community, user, myself, message)

            if not has_selected_users:
                return siteaction.render_to_response(
                    "communities/invite.htm",
                    {
                        "community": community,
                        "friend_count": myself.friends.count(),
                        "friends_html": getFriendsTable(myself, community),
                        "myself": myself,
                    },
                )

        if community.is_moderated:
            flash_id = "mod_comm_invites_sent"
        else:
            flash_id = "comm_invites_sent"

        return HttpResponseRedirect(
            "/communities/" + str(community.id) + "/invite.htm?flashId=" + flash_id + "&amp;action=invite_more"
        )