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)
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')
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
def handle(request): if request.method == 'GET': return siteaction.render_to_response('forgotpassword.htm') elif request.method == 'POST': accounts = models.Account.objects.filter(username=dataplus.dictGetVal(request.REQUEST,'username')) if (accounts.count() > 0): target_acct = accounts[0] uniqueId = dataplus.getUniqueId() password_change_req = models.PasswordChangeRequest() password_change_req.account = target_acct password_change_req.req_random_key = uniqueId password_change_req.created_at = datetime.datetime.utcnow() password_change_req.save() #Send recovery email... mail_subject = 'Reset your Socialray password' mail_body = '<p>Hello,</p>' mail_body += '<p>You received this email because a Password Reset was requested for your Socialray account. <br />' mail_body += 'Just click the link <a href="' + config.server_base_url + '/resetpassword.htm?' + \ 'passwordChangeKey=' + uniqueId + '"><strong>Reset My Password</strong></a> to change your password.</p>' mail_body += '<p>If you did not request it, you can safely ignore this mail.</p>' mail_body += '<p>Regards,<br />from Socialray</p>' mailman.sendOneWayMail(config.system_email, [target_acct.email], mail_subject, mail_body) return siteaction.render_to_response('showmessage.htm', {'msg_heading': 'Password Reset', 'msg_html': 'A link to recover your password was sent to your email address. ' + \ 'The link will expire in 24 hours. <a href="' + config.server_base_url + '">Back to Homepage</a>.'}) else: return siteaction.render_to_response('forgotpassword.htm', {'error_html': '<p style="color:#FF0000">The username does not exist.</p>'})
def sendCommunityInvitationToUser(community, user, sender, message, add_as_friend=False): comm_invite = models.CommunityInvitation(sent_by=sender, community=community) comm_invite.invite_random_key = dataplus.getUniqueId() comm_invite.save() sender_email = '"' + sender.name + '" <' + sender.username + "*****@*****.**>" subject = sender.name + " has invited you to join " + community.name accept_url = ( config.server_base_url + "/me/acceptinvite.htm?commInviteId=" + str(comm_invite.invite_random_key) + "&user="******"' + config.server_base_url + "/profiles/" + sender.username + '">' + sender.name + "</a>" + " feels that you will be interested in joining the " + community.name + " Community and has sent you the following message:</p>" + "<p>" + dataplus.replaceHtmlLineBreaks(message) + "</p>" + '<p>To accept this invitation, visit <a href="' + accept_url + '">' + accept_url + "</a> " + "<p>Regards,<br />from Socialray</p>" ) text_message = ( sender.name + " feels that you will be interested in joining the " + community.name + " Community and has sent you the following message:\r\n" + message + "\r\n\r\n" + "To accept this invitation, visit - " + accept_url + " \r\n" + "Regards,\r\n" + "from Socialray\r\n\r\n" ) def internalSender(rcvr_accounts): mailman.sendToInbox(sender.username, user.username, subject, html_message) def externalSender(rcvr_accounts): mailman.sendMail( sender_email, [user.email], subject, html_message, None, None, text_message, reply_to=user.email ) mailman.sendBySettings([user.account], internalSender, externalSender, "CommunityInvitation")
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 + "&action=invite_more" )
def handle(request): if request.method == 'GET': #there cannot be get requests to this page..... return siteaction.render_to_response('showmessage.htm', {'msg_heading': 'Error', 'msg_html': 'Invalid URL'}) elif request.method == 'POST': if (dataplus.dictGetVal(request.REQUEST,'action') == 'page2'): industry_cat = dataplus.dictGetVal(request.REQUEST,'industry_category') if not (dataplus.dictGetVal(request.REQUEST,'postedby') and dataplus.dictGetVal(request.REQUEST,'industry_category') \ and dataplus.dictGetVal(request.REQUEST,'company') and dataplus.dictGetVal(request.REQUEST,'location') \ and dataplus.dictGetVal(request.REQUEST,'phone') and dataplus.dictGetVal(request.REQUEST,'email')): return siteaction.render_to_response('showmessage.htm', {'msg_heading':'Invalid request', \ 'msg_html':'Required fields were not supplied. Please fill all the required fields and try again.'}) salary_ranges = codejar_resume.getSalaryRanges(dataplus.dictGetVal(request.REQUEST,'country')) salary_range_select_html = hotmetal.elemSelect([('Select', '0-0')], salary_ranges, lambda x:x[1], lambda x:x[0], '0-0', 'name="salary_range" id="salary_range" style="width:160px"') currency_code = models.Country.objects.get(code=dataplus.dictGetVal(request.REQUEST,'country')).currency_code return siteaction.render_to_response('recruiters/postjobsnow2.htm', {'postedby': dataplus.dictGetVal(request.REQUEST,'postedby'), 'industry_category': cgi.escape(dataplus.dictGetVal(request.REQUEST,'industry_category')), 'company': dataplus.dictGetVal(request.REQUEST,'company'), 'location': dataplus.dictGetVal(request.REQUEST,'location'), 'country': dataplus.dictGetVal(request.REQUEST,'country'), 'email': dataplus.dictGetVal(request.REQUEST,'email'), 'phone': dataplus.dictGetVal(request.REQUEST,'phone'), 'salary_range_select_html': salary_range_select_html, 'currency_code':currency_code, 'cid':dataplus.getUniqueId(),}) elif (dataplus.dictGetVal(request.REQUEST,'action') == 'save'): if dataplus.dictGetVal(request.REQUEST,'captcha_text') != request.session['postjob_captcha_text']: return siteaction.render_to_response('recruiters/postjobsnow2.htm', {'postedby': dataplus.dictGetVal(request.REQUEST,'postedby'), 'industry_category': cgi.escape(dataplus.dictGetVal(request.REQUEST,'industry_category')), 'company': dataplus.dictGetVal(request.REQUEST,'company'), 'location': dataplus.dictGetVal(request.REQUEST,'location'), 'country': dataplus.dictGetVal(request.REQUEST,'country'), 'email': dataplus.dictGetVal(request.REQUEST,'email'), 'phone': dataplus.dictGetVal(request.REQUEST,'phone'), 'designation': dataplus.dictGetVal(request.REQUEST,'designation'), 'jobdescription': dataplus.dictGetVal(request.REQUEST,'jobdescription'), 'location': dataplus.dictGetVal(request.REQUEST,'location'), 'exact_salary': dataplus.dictGetVal(request.REQUEST,'exact_salary'), 'mandatory_skills': dataplus.dictGetVal(request.REQUEST,'mandatory_skills'), 'desired_skills': dataplus.dictGetVal(request.REQUEST,'desired_skills'), 'title': dataplus.dictGetVal(request.REQUEST,'title'), 'error_html':'<p class="error-note">The captcha(verification) text entered doesn\'t match.</p>'}) job_pos = models.JobPosition() job_pos.tag = 'name=' + dataplus.dictGetSafeVal(request.REQUEST, 'postedby') + ';' job_pos.company_name = dataplus.dictGetSafeVal(request.REQUEST, 'company') industry_category = models.IndustryCategory.objects.get(name=dataplus.dictGetVal(request.REQUEST,'industry_category')) job_pos.industry_category = industry_category job_pos.designation = dataplus.dictGetSafeVal(request.REQUEST, 'designation') job_pos.job_description = dataplus.dictGetSafeVal(request.REQUEST, 'jobdescription','') job_pos.num_positions = 1 #one for now. job_pos.closing_date = config.max_date job_pos.location = dataplus.dictGetSafeVal(request.REQUEST, 'location') job_pos.country = dataplus.dictGetSafeVal(request.REQUEST, 'country') exact_salary = dataplus.dictGetVal(request.REQUEST,'exact_salary') if exact_salary: exact_salary = string.atoi(exact_salary) job_pos.min_compensation = exact_salary job_pos.max_compensation = exact_salary else: #salary in the format 'min_salary-max_salary' #this string needs to be split into min and max sal = string.split(dataplus.dictGetVal(request.REQUEST,'salary_range'),'-') job_pos.min_compensation = string.atoi(sal[0]) job_pos.max_compensation = string.atoi(sal[1]) job_pos.min_exp_years = dataplus.dictGetVal(request.REQUEST,'min_exp_years',0) job_pos.mandatory_skills = dataplus.dictGetSafeVal(request.REQUEST, 'mandatory_skills') job_pos.desired_skills = dataplus.dictGetSafeVal(request.REQUEST, 'desired_skills') job_pos.educational_qualifications = dataplus.dictGetSafeVal(request.REQUEST,'edu_qualifications') job_pos.contact_email = dataplus.dictGetSafeVal(request.REQUEST,'email') job_pos.contact_phone = dataplus.dictGetSafeVal(request.REQUEST,'phone') if dataplus.dictGetVal(request.REQUEST,'title') != '': job_pos.title = dataplus.dictGetSafeVal(request.REQUEST,'title') else: job_pos.title = (job_pos.designation + ' - ' + job_pos.mandatory_skills + ' (' + str(job_pos.min_exp_years) + ' years)')[:30] + '...' job_pos.currency = config.default_currency job_pos.url = '' job_pos.save() return siteaction.render_to_response('showmessage.htm', { 'msg_heading':'Success', 'msg_html':'The job was added successfully. <a href="/recruiters/postjobsnow1.htm">Add Another</a>.'})
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.')