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 handle(request): 
    try:      
        username = dataplus.dictGetVal(request.REQUEST,'username').strip()
        #checking for reserved key words
        if username.lower() in config.reserved_words:
            return ajaxian.getSuccessResp('account_exists')
        
        #see if such a friend request exists
        if (models.Account.objects.filter(username=username).count() > 0):
            return ajaxian.getSuccessResp('account_exists')
        else:
            return ajaxian.getSuccessResp('no_account')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        user_id = dataplus.dictGetVal(request.REQUEST, 'userId')
        #see if such a friend exists
        friend = dataplus.returnIfExists(myself.friends.filter(id=user_id))
        if friend:
            myself.friends.remove(friend)
            return ajaxian.getSuccessResp('removed_friend')
        else:
            return ajaxian.getSuccessResp('not_a_friend')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')

        comm_id = string.atoi(dataplus.dictGetVal(request.REQUEST,'commId'))
        community = models.Community.objects.get(id=comm_id)
        title = dataplus.dictGetSafeVal(request.REQUEST,'title')
        text = dataplus.dictGetSafeVal(request.REQUEST,'text')
        
        if community.is_moderated:
            if not community.members.filter(id=myself.id):
                return ajaxian.getFailureResp('This is a moderated community. So only members can post.')
        
        topic = models.CommunityTopic()
        topic.community = community
        topic.title = title
        topic.started_by = myself        
        topic.last_post_at = datetime.utcnow()
        topic.save()
        
        post = models.CommunityPost()
        post.topic = topic
        post.posted_by = myself
        post.text = text
        post.save()
        
        return ajaxian.getSuccessResp(me_communities_show.getTopicBoxHtml(topic, True))
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #5
0
def handle(request): 
    try:
        logged_in_type = siteaction.getLoggedInAccountType(request)
        rcvr_usrname = dataplus.dictGetVal(request.REQUEST,'sendTo')
        
        if logged_in_type == 'U':
            myself = siteaction.getLoggedInUser(request)
        elif logged_in_type == 'R':
            myself = siteaction.getLoggedInRecruiter(request)
        else:
            return ajaxian.getFailureResp('not_logged_in')
        
        rcvr_account = models.Account.objects.get(username=dataplus.dictGetVal(request.REQUEST,'sendTo'))
        text_message = dataplus.dictGetSafeVal(request.REQUEST,'text')
        html_message = dataplus.replaceHtmlLineBreaks(text_message)
        subject = dataplus.dictGetSafeVal(request.REQUEST,'subject')
        
        def internalSender(rcvr_accounts):
            mailman.sendMessage(myself.username, [rcvr.username for rcvr in rcvr_accounts], subject, html_message)
        
        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
            mailman.sendMail(sender, receivers, subject, html_message, None, None, text_message, reply_to=myself.email)
            
        mailman.sendBySettings([rcvr_account], internalSender, externalSender, 'TextMessage')
                
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #6
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')
def handle(request):
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp("not_logged_in")

        id = dataplus.dictGetVal(request.REQUEST, "id", -1, string.atoi)
        if id == -1:
            return ajaxian.getSuccessResp("not_found")

        testimonial = dataplus.returnIfExists(myself.testimonials_for_me.filter(id=id))
        if testimonial:
            testimonial.delete()
            return ajaxian.getSuccessResp("deleted")
        else:
            return ajaxian.getSuccessResp("not_found")
    except:
        return ajaxian.getFailureResp("unknown")
Exemple #8
0
def getAjaxOnlineStatus(request, session_id):
    try:
        usernames = dataplus.dictGetVal(request.REQUEST, 'usernames')
        if not usernames:
            return ajaxian.getFailureResp('error:invalid_parameters')
        
        members_online_status = getOnlineStatus(request, usernames.split(','), '', session_id)
        return ajaxian.getSuccessResp(members_online_status)
    except:
        return ajaxian.getFailureResp('error:unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')

        html = me_index.getFriendsBoxHtml(myself, request)
        friends_count = myself.friends.count()
        
        return ajaxian.getSuccessResp(friends_count, html)
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #10
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')
Exemple #11
0
def getSharedFolder(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        
        data = livewire_client.query('getSharedFilesInfo', [session_id, chat_id])
        if data.startswith('error:'):
            return ajaxian.getFailureResp(data)
        file_infos = cPickle.loads(data)
        return ajaxian.getSuccessResp(file_infos)
    except:
        return ajaxian.getFailureResp('error:unknown')
Exemple #12
0
def getChatHistory(request, session_id):
    try:
        chat_id = dataplus.dictGetVal(request.REQUEST, 'chatId', '')        
        if not chat_id:
            return ajaxian.getFailureResp('error:invalid_chatId')
        
        data = livewire_client.query('getChatHistory', [session_id, chat_id])
        if data.startswith('error:'):
            return ajaxian.getFailureResp(data)
        messages = cPickle.loads(data)
        return ajaxian.getSuccessResp(messages)
    except:
        return ajaxian.getFailureResp('error:unknown')
Exemple #13
0
def getChatId(request, session_id):
    try:
        receiver = dataplus.dictGetVal(request.REQUEST, 'receiver', '')
        receiver_info = ''
        if receiver:
            receiver_infos = getRelationships(request, [receiver])
            receiver_info = receiver_infos[0]
        data = livewire_client.query('getChatId', [session_id, receiver_info, 'private'])
        if data:
            return ajaxian.getSuccessResp(data)
        else:
            return ajaxian.getFailureResp('error:connection_error')
    except:
        return ajaxian.getFailureResp('error:unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        msg_id = dataplus.dictGetVal(request.REQUEST,'messageId')
        result, msg = mailman.deleteMessage(myself.account, msg_id)
        if not result:
            ajaxian.getFailureResp(msg)
        else:        
            return ajaxian.getSuccessResp(msg)
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')

        new_friend_id = dataplus.dictGetVal(request.REQUEST,'userId')
        new_friend = dataplus.returnIfExists(models.User.objects.filter(id=new_friend_id))
        if not new_friend:
            return ajaxian.getSuccessResp('user_not_exists')
            
        #surprise.... you cannot add yourself, as a friend too!
        if (str(myself.id) == new_friend_id):
            return ajaxian.getSuccessResp('cannot_add_yourself')        
        
        #see if such a friend exists
        #if so, then don't add
        friend = dataplus.returnIfExists(myself.friends.filter(id=new_friend_id))
        
        if not friend:
            #see if there is already a pending friend request
            #if a request exists from the other user lets make them friends
            friend_req_from = dataplus.returnIfExists(models.FriendRequest.objects.filter(sent_by__id=new_friend_id, sent_to__id=myself.id))
            if friend_req_from:
                myself.friends.add(new_friend)
                myself.save()
                friend_req_from.delete()    
                return ajaxian.getSuccessResp('friend_added')        
            
            #if a request from myself is there
            #if so don't add.. its pending
            friend_req_to = dataplus.returnIfExists(models.FriendRequest.objects.filter(sent_to__id=new_friend_id, sent_by__id=myself.id))
            if not friend_req_to:
                friend_req = models.FriendRequest()
                friend_req.sent_by = myself
                friend_req.sent_to = new_friend
                friend_req.sent_on = datetime.datetime.utcnow()
                friend_req.save()
                html_mail_content = '<p>Hello ' + new_friend.name + ',</p><p><a href="' + config.server_base_url + \
                    '/profiles/' + myself.username + '">' + myself.name + '</a> has sent you a friend request. Please <a href="http://www.socialray.org/me/">Login to Socialray</a> to approve or reject the request.</p>' + \
                    '<p>Regards,<br />from Socialray</p><br /><br /><br /><br /><br />' 
                        
                text_mail_content = 'Hello ' + new_friend.name + ',\r\n\r\n' + myself.name + '(' + config.server_base_url + \
                    '/profiles/' + myself.username + ') wants to be your friend. Please login to Socialray to approve or reject the request.\r\n\r\n' + \
                    'Regards,\r\nfrom Socialray\r\n\r\n\r\n\r\n\r\n' 
                    
                mailman.sendMail('"' + myself.name + '" <' + myself.username + '*****@*****.**>', [new_friend.email], 'Socialray: ' + myself.name + ' wants to add you as a friend', html_mail_content, None, None, text_mail_content, reply_to=myself.email)
                return ajaxian.getSuccessResp('request_added')
            else:
                return ajaxian.getSuccessResp('pending_request')
        else:
            return ajaxian.getSuccessResp('already_a_friend')
                
    except:
        return ajaxian.getFailureResp('unknown')        
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        ref_id = dataplus.dictGetVal(request.REQUEST, 'refId', 0, string.atoi)
        job_ref = dataplus.returnIfExists(models.JobReferral.objects.filter(id=ref_id))        
        if not job_ref:
            return ajaxian.getFailureResp('invalid_request')
        return ajaxian.getSuccessResp( {'subject':job_ref.subject, 
                                        'industry_category':job_ref.industry_category.name, 
                                        'min_exp':job_ref.min_experience_years,
                                        'text':job_ref.text})
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #17
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')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        resume_file_path = myself.resume_dir + '/' + myself.username + '.doc'
        if os.path.exists(resume_file_path):
            os.remove(resume_file_path)
        
        settings = models.UserSettings.objects.get(user=myself)
        settings.has_doc_resume = False
        settings.save()
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #19
0
def handle(request): 
    try:
        username = dataplus.dictGetVal(request.REQUEST, 'username')
        password = dataplus.dictGetVal(request.REQUEST, 'password')
        if not (username and password):
            return ajaxian.getFailureResp('Error: Invalid username or password.')

        success, session_id, redirect_url, error_message = siteaction.doAjaxLogin(username, password)
        if success:
            response = ajaxian.getSuccessResp(redirect_url)
            response.set_cookie('session_id', session_id)
            return response
        else:
            return ajaxian.getFailureResp(error_message)
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        msg_id = dataplus.dictGetVal(request.REQUEST,'messageId')
        msg = dataplus.returnIfExists(models.Message.objects.filter(id=msg_id, account__id=myself.account.id, folder='trashcan'))
        if msg:
            msg.folder = 'inbox'
            msg.save()
            return ajaxian.getSuccessResp('moved_to_inbox')
        else:        
            return ajaxian.getFailureResp('invalid_messageId')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        account = siteaction.getLoggedInAccount(request)
        if not account:
            return ajaxian.getFailureResp('not_logged_in')
        
        status = dataplus.dictGetSafeVal(request.REQUEST,'status','everyone')
        cs = models.ChatSettings.objects.get(account=account)
        cs.online_status = status
        cs.save()
        
        session_id = request.COOKIES['session_id']
        siteaction.updateLivewireData(session_id, account)
        
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #22
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')
Exemple #23
0
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        requesting_user = dataplus.dictGetVal(request.REQUEST,'lastMessageId', '')
        if (not myself) or myself.username != requesting_user:
            return ajaxian.getFailureResp('not_logged_in')
        
        last_message_id = dataplus.dictGetVal(request.REQUEST,'lastMessageId')
        
        msgs = models.Message.objects.filter(account__id=myself.account.id, folder='inbox', id__gt=last_message_id).order_by('-sent_at')
        if msgs:
            last_message_id = msgs[0].id
        else:
            last_message_id = -1
            
        return ajaxian.getSuccessResp(last_message_id, me_index.getMessageBoxHtml(msgs))
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #24
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')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        req_id = dataplus.dictGetVal(request.REQUEST, 'requestId')
        #see if such a friend request exists
        friend_req = models.FriendRequest.objects.get(id=req_id)
        
        #check if the friend request is to the same user.
        if (friend_req.sent_to != myself):
            return ajaxian.getFailureResp('request_not_for_user')         
        
        friend_req.delete()
        
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')

        msg_id = dataplus.dictGetVal(request.REQUEST,'messageId')
        message = models.Message.objects.get(id=msg_id)
        
        #check if the message is to the same user.
        if (message.account.id != myself.account.id):
            return ajaxian.getFailureResp('message_not_for_user')
        
        message.read = True
        message.save()
        
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        comm_id = dataplus.dictGetVal(request.REQUEST, 'communityId')
        community = models.Community.objects.get(id=comm_id)
        
        if community.members.filter(id=myself.id).count() > 0:
            if community.owner_username == myself.username:
                return ajaxian.getFailureResp('owner_cannot_unjoin') 
                
            community.members.remove(myself);
            return ajaxian.getSuccessResp('')
        else:
            return ajaxian.getFailureResp('not_a_member')        
    except:
        return ajaxian.getFailureResp('unknown')
Exemple #28
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')
Exemple #29
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')
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        comm_id = dataplus.dictGetVal(request.REQUEST, 'communityId')
        community = models.Community.objects.get(id=comm_id)
        
        if community.members.filter(id=myself.id):
            return ajaxian.getFailureResp('already_member')

        elif not community.is_moderated:            
            myself.communities.add(community)
            myself.save()
            return ajaxian.getSuccessResp('joined_community')
                
        else:
            join_reqs = community.join_requests.filter(sent_by__id=myself.id)
            if join_reqs.count() > 0:
                return ajaxian.getFailureResp('request_pending')            
            
            if dataplus.dictGetVal(request.REQUEST, 'message', '') == '':
                return ajaxian.getFailureResp('community_moderated')
            
            message_to_admin = dataplus.dictGetSafeVal(request.REQUEST, 'message','')
            
            join_req = models.CommunityJoinRequest()
            join_req.sent_by = myself
            join_req.community = community
            join_req.sent_on = datetime.datetime.utcnow()
            join_req.msg_to_admin = message_to_admin
            join_req.save()
            
            msg_to_admin_html = '<p><a href="' + config.server_base_url + '/profiles/' + myself.username + '">' + myself.name + '</a>' + \
                ' wants to join ' + community.name + ' and has sent you a message:<br />' + \
                dataplus.replaceHtmlLineBreaks(message_to_admin) + '</p>' + \
                '<p>To allow/deny membership to this user , <a href="/me/approvecommjoinreq.htm?reqId=' + \
                str(join_req.id) + '">Click Here</a></p>' 
            
            msg_to_admin_text = myself.name + ' wants to join ' + community.name + ' and has sent you a message:\r\n' + \
                message_to_admin + '\r\n\r\nVisit ' + config.server_base_url + '/me/approvecommjoinreq.htm?reqId=' + str(join_req.id) + \
                ' to allow/deny membership to this user.\r\n\r\n'   
            
            def internalSender(rcvr_accounts):
                mailman.sendToInbox(myself.username, rcvr_accounts[0].username, 'Request to join ' + community.name, msg_to_admin_html, 'TM', 'H')
            
            def externalSender(rcvr_accounts):    
                sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
                receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]                
                ext_msg_to_admin_html = msg_to_admin_html + \
                    '<br /><br /><br /><br /><br />' + \
                    'If you don\'t want to receive notification emails, change your Account Settings ' + \
                    '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
                ext_msg_to_admin_text = msg_to_admin_text + \
                    '\r\n\r\n\r\n\r\n\r\n' + \
                    'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
                    config.server_base_url + '/me/editsettings.htm'                                
                mailman.sendMail(sender, receivers, 'Request to join ' + community.name, ext_msg_to_admin_html, 
                    None, None, ext_msg_to_admin_text, reply_to=myself.email)

            admin_account = models.Account.objects.get(username=community.owner_username)
            mailman.sendBySettings([admin_account], internalSender, externalSender, 'SocialrayAlert')
            
            return ajaxian.getSuccessResp('request_sent')
        
    except:
        return ajaxian.getFailureResp('unknown')