def login(self,userName,subject):
     """
     A user connects to the chat room.
     """
     # Generate unique userID
     chars = string.letters + string.digits
     userID = ''.join([choice(chars) for i in range(10)])
     self.core.setStateVar("helpdesk-userID",userID)
     self.core.setStateVar("helpdesk-lastMsgFrom",'')
     self.core.focus("#jabberHelpdeskMsgInput")
     try:
         
         agent=self.mh.userLogin(self.botJid,userID,userName,subject)
         vCard = self.mh.getAgentVCard(self.botJid,userID)
         self.core.setStateVar("helpdesk-lastMsgFrom",'')
         self.core.setStateVar("helpdesk-agent",agent)
         self.plonekss.issuePortalMessage(
             _(u"You are connected to the helpdesk. " \
                "Someone will be with you shortly."),'info')
         vCardElem = self.core.getHtmlIdSelector("jabberHelpdeskAgentDetails")
         vCardDetails='<img id="agentAvatar" src="%s/helpdesk_avatar?userID=%s"/>'%(aq_inner(self.context).absolute_url(),userID)
         if vCard['FN'] or vCard['DESC']:
             vCardDetails += "<label>"+_(u"Talking with: ")+"</label>"+'<span id="jabberHelpdeskAgentDesc">'+vCard['FN']+" "+vCard['DESC']+"</span>"
         self.core.insertHTMLAsLastChild(vCardElem, vCardDetails)
     except Exception,Detail:
         return self._connectionError(Detail)
 def action_submit(self, action, data):
     """
     """
     
     context = aq_inner(self.context)
     subject = data['subject']
     if not data.has_key('name'):
         name = self.memberName
     else:
         name = data['name']
     
     try:
         if self.mh.loadBot(context.botJid,
                            context.botPassword,
                            context.persistent):
             if self.availableAgents()[0]:
                 return self.request.response.redirect(
                     '@@chatView?name=%s&subject=%s'%(name,subject))
             else:
                 IStatusMessage(self.request).addStatusMessage(
                     _(u"No available agents."), type='error')
         else:
             IStatusMessage(self.request).addStatusMessage(
                 _(u"Could not connect to helpdesk server"), type='error')
             logger.error(
                 "Could not connect to bot:%s"%self.context.botJid)
     
     except:
         IStatusMessage(self.request).addStatusMessage(
             _(u"Could not connect to helpdesk server"), type='error')
         logger.error("Could not connect to bot:%s"%self.context.botJid)
 def title(self):
     return _(u"Helpdesk portlet")
 def _connectionError(self,Detail):
     """
     """
     self.plonekss.issuePortalMessage(_("Connection error"),'error')
     return self.render()
     
示例#5
0
import md5
from zope.interface import implements

from zope.component.factory import Factory
from plone.app.content.interfaces import INameFromTitle
from plone.app.content.item import Item
from qi.jabberHelpdesk.interfaces import IHelpdesk
from qi.jabberHelpdesk import HelpdeskMessageFactory as _

class Helpdesk(Item):
    implements(IHelpdesk, INameFromTitle)
    portal_type="Jabber Helpdesk"
    title=u""
    description = u""
    botJid = u""
    botPassword = u""
    persistent = False
    
    def __init__(self,id=None):
        super(Helpdesk,self).__init__(id)
    
    def passwordHash(self):
        """Returns a hash for the bot's password.
        """
        return md5.new(self.botPassword).hexdigest()

helpdeskFactory = Factory(Helpdesk, title=_(u"Create a new jabber helpdesk"))