Esempio n. 1
0
def inviteToChatByEmail(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        username = dataplus.dictGetVal(request.REQUEST, 'username', '')
        name = dataplus.dictGetVal(request.REQUEST, 'name', '')
        invited_name = dataplus.dictGetVal(request.REQUEST, 'invitedName', '', lambda x: x.strip())
        invited_email = dataplus.dictGetVal(request.REQUEST, 'invitedEmail', '', lambda x: x.strip())
        text = dataplus.dictGetSafeVal(request.REQUEST, 'text', '')
        
        subject = 'Chat Invitation to Socialray'
        sender = name + '<' + username + '*****@*****.**>'
        html_message = '<p>Hello ' + invited_name + '</p><p>' + name + ' wants to have a chat with you and has sent you the following message ' + \
            'inviting you to a chat session in Socialray.</p><p>"' + text + '"</p>' + \
            '<p>You can <a href="' + config.server_base_url + '/chat/startchat.htm?chatId=' + chat_id + '">join ' + name + '</a> in chat now.</p>' + \
            '<p>Regards,<br />from Socialray</p>'
        text_message = 'Hello ' + invited_name + '\r\n' + name + ' wants to have a chat with you and has sent you the following message ' + \
            'inviting you to a chat session in Socialray.\r\n"' + text + '"\r\n' + \
            'Please visit ' + config.server_base_url + '/chat/startchat.htm?chatId=' + chat_id + ' to join ' + name + ' in chat now.\r\n' + \
            'regards,\r\nfrom Socialray\r\n\r\n'
        mailman.sendOneWayMail(sender, [invited_name + '<' + invited_email + '>'], subject, html_message, None, None, text_message)
        livewire_client.command('inviteByEmail', [session_id, chat_id, invited_name, invited_email])
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 2
0
def doLogout(request):
    try:
        session_id = request.COOKIES['session_id']
        username = getUsernameForSession(session_id)
        sessions_client.command('logoutAccount', [username])
        livewire_client.command('clearSession', [session_id])
    except KeyError:
        pass
Esempio n. 3
0
def handle(request):   
    if request.method == 'GET':
        return siteaction.render_to_response('idxcaptcha.htm')
    elif request.method == 'POST':
        captchatextin = request.session['signup_captcha_text']
        if dataplus.dictGetVal(request.REQUEST,'captcha_text') != captchatextin:
            return siteaction.render_to_response('idxcaptcha.htm',
                    {'error_html':'The captcha text entered is incorrect.'})
                
        params = request.session['signup-params']
        if params['username'].lower() in config.reserved_words or models.Account.objects.filter(username=params['username']).count() > 0:
            countries = models.Country.objects.all().order_by('name')
            country_select_html = hotmetal.elemSelect([('Select', '')], countries,
                lambda x:x.name, lambda x:x.code, dataplus.dictGetVal(request.REQUEST,'country'), 'name="country" id="country" style="width:160px"')
            
            industry_cats = models.IndustryCategory.objects.all()
            industry_cats_html = hotmetal.elemSelect([('Select', '')], industry_cats,
                lambda x:x.name, lambda x:x.name, dataplus.dictGetVal(request.REQUEST,'industry_category'), 'name="industry_category" id="industry_category" style="width:160px"')
            
            experience_select_html = hotmetal.elemSelect([('Select', '-1')], range(0,51),
                lambda x:x, lambda x:x, dataplus.dictGetVal(request.REQUEST,'experience'), 'name="experience" id="experience" style="width:90px"')
                    
            error_message = 'Username already exists. Please choose another'
            return siteaction.render_to_response('index.htm', 
                {'error_html': '<p class="error-note">' + error_message + '</p>',
                'name':params['name'],
                'username':params['username'],
                'email':params['email'],
                'country_select_html':country_select_html,
                'industry_categories_html':industry_cats_html,
                'experience_select_html':experience_select_html})
        else:           
            req_username = params['username'].lower()
            user = siteaction.createUser(req_username, params['name'], params['password'], params['email'], 
                    params['country'], params['industry_category'].replace('&amp;','&'), params['experience'])                 
           
            request.session['signup-params'] = None
            
            useraccount = user.account
        
            #none if these users would have posted their resume, or setup preferences....
            todoResumeMail_subject = '<span style="color:#FF9900">Next step: Update your Resume</span>'
            todoResumeMail_body_html = '<p>To effectively use socialray for Professional Networking and Jobs, you need to update your resume. You can do so by opening the <a href="http://www.socialray.org/me/editresume.htm">Resume Editor</a>.</p>' + \
                '<p>Regards,<br />Socialray Team</p>'
            mailman.sendToInbox(None, req_username, todoResumeMail_subject, todoResumeMail_body_html, 'SA')
            
            session_id = sessions_client.query('addNewSession', [useraccount.username])
            if session_id:
                chat_settings = models.ChatSettings.objects.get(account=useraccount)
                livewire_client.command('updateUserSession', [session_id, useraccount.username, useraccount.name, chat_settings.online_status, 
                    chat_settings.custom_message, chat_settings.invite_preference, chat_settings.ignore_list, 
                    dataplus.getStaticUrl(chat_settings.image_size1_file_path), dataplus.getStaticUrl(chat_settings.image_size2_file_path), 
                    dataplus.getStaticUrl(chat_settings.image_size3_file_path)])

                return siteaction.redirectWithCookie('/me', 'session_id', session_id)
            else:
                return HttpResponseRedirect('500.html')
Esempio n. 4
0
def handle(request):
    import website.bigfoot.models as models
    zoomo_id = dataplus.dictGetVal(request.REQUEST, 'zid')
    hresume_contents = get_object_or_404(models.HResumeContents, zoomo_id=zoomo_id)
    
    if request.method == 'GET':      
        return render_to_response('resumitypublish.htm', 
            {'zid':zoomo_id})
    
    #Handles only post requests
    elif request.method == 'POST':
        html = hresume_contents.resume
        
        action = dataplus.dictGetSafeVal(request.REQUEST, 'action')
        user = None
        from website.bigfoot.utils import siteaction, codejar_resume, sessions_client, livewire_client
        if action == 'new_publish':
            username = dataplus.dictGetSafeVal(request.REQUEST, 'new_username')
            password1 = dataplus.dictGetSafeVal(request.REQUEST, 'password1')
            password2 = dataplus.dictGetSafeVal(request.REQUEST, 'password2')
            industry_category = hresume_contents.industry_category.name
            posted_data = simplejson.loads(base64.b64decode(hresume_contents.post_dict))
            experience = calculateExperience(posted_data)
            country = models.Country.objects.get(name=hresume_contents.country)
            
            full_name = (hresume_contents.fname + ' ' + hresume_contents.lname).strip()
            
            user = siteaction.createUser(username, full_name, password1, hresume_contents.email, country.code, industry_category, experience)
            session_id = sessions_client.query('addNewSession', [user.username])
        elif action == 'login_publish':
            username = dataplus.dictGetSafeVal(request.REQUEST, 'username')
            password = dataplus.dictGetSafeVal(request.REQUEST, 'password')
            success, session_id, url, info = siteaction.doAjaxLogin(username, password)
            if not success:
                return render_to_response('resumitypublish.htm', 
                    {'zid':zoomo_id,
                    'error_text': info})
            else:
                user = models.User.objects.get(username=username)
                
        html_body = html[html.index('<body>')+len('<body>'):html.index('</body>')]
        codejar_resume.saveResume(user, html_body)
        useraccount = user.account
        
        hresume_contents = models.HResumeContents.objects.get(zoomo_id=zoomo_id)
        hresume_contents.account = useraccount
        hresume_contents.save()

        if session_id:
            chat_settings = models.ChatSettings.objects.get(account=useraccount)
            livewire_client.command('updateUserSession', [session_id, useraccount.username, useraccount.name, chat_settings.online_status, 
                chat_settings.custom_message, chat_settings.invite_preference, chat_settings.ignore_list, 
                dataplus.getSocialrayStaticUrl(chat_settings.image_size1_file_path), dataplus.getSocialrayStaticUrl(chat_settings.image_size2_file_path), 
                dataplus.getSocialrayStaticUrl(chat_settings.image_size3_file_path)])
        
        return siteaction.redirectWithCookie('/me/', 'session_id', session_id)
Esempio n. 5
0
def handle(request):   
    if request.method == 'GET':
        socialray_invite = dataplus.dictGetSafeVal(request.REQUEST,'inviteId','')
        comm_invite = dataplus.dictGetSafeVal(request.REQUEST,'commInviteId','')
        comm_friend_invite = dataplus.dictGetSafeVal(request.REQUEST,'commFriendInviteId','')
        invitation = ''
        if socialray_invite:
            invitation = 'inviteId=' + socialray_invite
        elif comm_invite:
            invitation = 'commInviteId=' + comm_invite
        elif comm_friend_invite:
            invitation = 'commFriendInviteId=' + comm_friend_invite
        
        countries = models.Country.objects.all().order_by('name')
        country_select_html = hotmetal.elemSelect([('Select', '')], countries,
            lambda x:x.name, lambda x:x.code, '', 'name="country" id="country" style="width:160px"')   
        
        return siteaction.render_to_response('me/signup.htm', 
            {'invitation':invitation,
            'cid':dataplus.getUniqueId(),
            'country_select_html':country_select_html})
    elif request.method == 'POST':
        result, response = validateRequest(request)
        if not result:
            return response
        
        username = dataplus.dictGetVal(request.REQUEST, 'username')
        if username.lower() in config.reserved_words or models.Account.objects.filter(username=username).count() > 0:
            return siteaction.render_to_response('me/signup.htm', 
                {'error_html': '<p class="error-note">Username already exists. Please choose another.</p>',
                'name':dataplus.dictGetVal(request.REQUEST, 'name'),
                'username':dataplus.dictGetVal(request.REQUEST, 'username'),
                'email':dataplus.dictGetVal(request.REQUEST, 'email'),
                'cid':dataplus.getUniqueId()})
        else:
            username = dataplus.dictGetVal(request.REQUEST,'username').lower()
            siteaction.createUser(username, dataplus.dictGetSafeVal(request.REQUEST, 'name'), 
                dataplus.dictGetSafeVal(request.REQUEST, 'password1'), dataplus.dictGetSafeVal(request.REQUEST, 'email'), 
                dataplus.dictGetSafeVal(request.REQUEST, 'country'), 'Software/IT', 0, dataplus.dictGetVal(request.REQUEST, 'invitation'))
            
            account = models.Account.objects.get(username=username)
            session_id = sessions_client.query('addNewSession', [account.username])
            if session_id:
                chat_settings = models.ChatSettings.objects.get(account=account)
                livewire_client.command('updateUserSession', [session_id, account.username, account.name, chat_settings.online_status, 
                    chat_settings.custom_message, chat_settings.invite_preference, chat_settings.ignore_list, 
                    dataplus.getStaticUrl(chat_settings.image_size1_file_path), dataplus.getStaticUrl(chat_settings.image_size2_file_path), 
                    dataplus.getStaticUrl(chat_settings.image_size3_file_path)])
    
            return siteaction.redirectWithCookie('createresume.htm', 'session_id', session_id)
Esempio n. 6
0
def blockUser(request, session_id):
    try:
        username = dataplus.dictGetVal(request.REQUEST, 'username', '')
        if not username:
            return ajaxian.getFailureResp('error:empty_username')
        account = siteaction.getLoggedInAccount(request)
        if not account:
            return ajaxian.getFailureResp('error:not_logged_in')
        cs = models.ChatSettings.objects.get(account=account)
        ignore_list = cs.ignore_list.split(',')
        if not username in ignore_list:
            ignore_list.append(username);
            cs.ignore_list = string.join(ignore_list, ',')
            cs.save()
            livewire_client.command('updateUserSession', [session_id, account.username, account.name, cs.online_status, 
                cs.custom_message, cs.invite_preference, cs.ignore_list, 
                dataplus.getStaticUrl(cs.image_size1_file_path), dataplus.getStaticUrl(cs.image_size2_file_path), 
                dataplus.getStaticUrl(cs.image_size3_file_path)])
                
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 7
0
def leaveChat(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        
        status = livewire_client.command('leaveChat', [session_id, chat_id])
        if status == 'success':
            return ajaxian.getSuccessResp('')
        else:
            return ajaxian.getFailureResp(status)
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 8
0
def fileUploadStart(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        filename = dataplus.dictGetVal(request.REQUEST, 'filename', '')
        if not filename:
            return ajaxian.getFailureResp('error:invalid_filename')
        
        result = livewire_client.command('fileUploadStart', [session_id, chat_id, filename])
        if result.startswith('error:'):
            return ajaxian.getFailureResp(result)
        else:
            return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 9
0
def buzzUser(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        
        receiver = dataplus.dictGetVal(request.REQUEST, 'receiver')
        if not receiver:
            return ajaxian.getFailureResp('error:invalid_parameters')
        
        data = livewire_client.command('buzzUser', [session_id, chat_id, receiver])
        if data.startswith('error:'):
            return ajaxian.getFailureResp(data)
        else:
            return ajaxian.getSuccessResp('')        
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 10
0
def inviteUsers(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        receivers = dataplus.dictGetVal(request.REQUEST, 'receivers', '')
        text = dataplus.dictGetVal(request.REQUEST, 'text', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        if not receivers:
            return ajaxian.getFailureResp('error:empty_receivers')
        receivers = receivers.split(',')
        receivers_infos = getRelationships(request, receivers)
        status = livewire_client.command('inviteUsers', [session_id, chat_id, dataplus.listToString(receivers_infos), text])
        if status == 'success':
            return ajaxian.getSuccessResp('')
        else:
            return ajaxian.getFailureResp(status)
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 11
0
def sendMessage(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        text = dataplus.dictGetSafeVal(request.REQUEST, 'text', '')
        receivers = dataplus.dictGetVal(request.REQUEST, 'receivers', '')
        last_message_id = dataplus.dictGetVal(request.REQUEST, 'lastMessageId','0')
        
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        if receivers:
            receivers = dataplus.listToString(receivers.split(','))
        data = livewire_client.query('getChatMessages', [session_id, chat_id, last_message_id])
        if data.startswith('error:'):
            return ajaxian.getFailureResp(data)
        data = cPickle.loads(data)
        result = livewire_client.command('sendMessage',[session_id, chat_id, text, receivers])
        if result.startswith('error:'):
            return ajaxian.getFailureResp(result)
        return ajaxian.getSuccessResp(data)
    except:
        return ajaxian.getFailureResp('error:unknown')
Esempio n. 12
0
def updateLivewireData(session_id, account):
    chat_settings = models.ChatSettings.objects.get(account=account)
    livewire_client.command('updateUserSession', [session_id, account.username, account.name, chat_settings.online_status, 
            chat_settings.custom_message, chat_settings.invite_preference, chat_settings.ignore_list, 
            dataplus.getStaticUrl(chat_settings.image_size1_file_path), dataplus.getStaticUrl(chat_settings.image_size2_file_path), 
            dataplus.getStaticUrl(chat_settings.image_size3_file_path)])
Esempio n. 13
0
def handle(request):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        new_user = dataplus.dictGetVal(request.REQUEST, 'newUser')
        new_guest = dataplus.dictGetVal(request.REQUEST, 'newGuest')
        session_id = ''
        if new_user or new_guest:
            result = ''
            if new_user:
                session_id = request.COOKIES['session_id']
                result = livewire_client.command('addUser', [chat_id, new_user])
            elif new_guest:
                session_id = '#' + dataplus.getUniqueId(19)
                result = livewire_client.command('addGuest',[chat_id,session_id, new_guest, 'Invited Guest.', dataplus.getStaticUrl(config.chat_guest_img_50), 
                    dataplus.getStaticUrl(config.chat_guest_img_72), dataplus.getStaticUrl(config.chat_guest_img_128)])
            if(result != 'success'):
                if result == 'error:max_users_exceeded':
                    return HttpResponse('Failed to join chat. The chat session has exceeded the maximum number of users.')
                elif result == 'error:invalid_chat_id':
                    return siteaction.render_to_response('500.html')
                else:
                    return HttpResponse('Failed to join chat.')
        else:
            session_id = request.COOKIES['session_id']

        data = livewire_client.query('getChatInfo', [session_id, chat_id])
        if data == 'error:invalid_chat_id':
            return HttpResponse('This chat does not exist.')
        chat_info = cPickle.loads(data)

        is_member = False
        friends_select_html = ''
        self = chat_info['self']
        current_username = self['username']
        current_name = self['name']
        current_user_online_status = self['online_visibility']
        if not current_username.startswith('#'):
            try:
                account = models.Account.objects.get(username=current_username)
                is_member = True
                if account.account_type == 'U':
                    friends = models.User.objects.filter(friends__username=account.username).order_by('name')
                    friends_select_html = hotmetal.elemSelect([('Select', '')], friends,
                    lambda x:x.name, lambda x:x.username, '', 'name="friends_select" id="friends_select" style="width:160px"')
            except:
                pass
        
        response = siteaction.render_to_response('chat/chatbox.htm', { 'current_chat_id':chat_id,
                                                        'current_username':current_username,
                                                        'current_name':current_name,
                                                        'current_user_online_status':current_user_online_status,
                                                        'is_member':is_member,
                                                        'friends_select_html':friends_select_html})
        
        expiry_time = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(days=90), "%a, %d-%b-%Y %H:%M:%S GMT")
        response.set_cookie('session_id', session_id, expires=expiry_time)
        return response
        
    except:
        return HttpResponse('Invalid Chat.')