comparison src/server/blog.py @ 728:9d35d75566fb

server_side (blog): clean error message when unknown profile is requested
author souliane <souliane@mailoo.org>
date Tue, 06 Oct 2015 16:38:41 +0200
parents 3bd097380da7
children 916075bd0356
comparison
equal deleted inserted replaced
727:3bd097380da7 728:9d35d75566fb
21 from sat.core.i18n import _, D_ 21 from sat.core.i18n import _, D_
22 from sat_frontends.tools.strings import addURLToText 22 from sat_frontends.tools.strings import addURLToText
23 from sat.core.log import getLogger 23 from sat.core.log import getLogger
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 25
26 from dbus.exceptions import DBusException
26 from twisted.internet import defer 27 from twisted.internet import defer
27 from twisted.web import server 28 from twisted.web import server
28 from twisted.web.resource import Resource 29 from twisted.web.resource import Resource
29 from twisted.words.protocols.jabber.jid import JID 30 from twisted.words.protocols.jabber.jid import JID
30 from jinja2 import Environment, PackageLoader 31 from jinja2 import Environment, PackageLoader
116 if not request.postpath: 117 if not request.postpath:
117 return self.useTemplate(request, "static_blog_error", {'message': "You must indicate a nickname"}) 118 return self.useTemplate(request, "static_blog_error", {'message': "You must indicate a nickname"})
118 119
119 prof_requested = request.postpath[0] 120 prof_requested = request.postpath[0]
120 #TODO : char check: only use alphanumeric chars + some extra(_,-,...) here 121 #TODO : char check: only use alphanumeric chars + some extra(_,-,...) here
121 prof_found = self.host.bridge.getProfileName(prof_requested) 122 try:
123 prof_found = self.host.bridge.getProfileName(prof_requested)
124 except DBusException:
125 prof_found = None
122 if not prof_found or prof_found == C.SERVICE_PROFILE: 126 if not prof_found or prof_found == C.SERVICE_PROFILE:
123 return self.useTemplate(request, "static_blog_error", {'message': "Invalid nickname"}) 127 return self.useTemplate(request, "static_blog_error", {'message': "Invalid nickname"})
124 128
125 d = defer.Deferred() 129 d = defer.Deferred()
126 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', C.SERVER_SECURITY_LIMIT, prof_found, callback=d.callback, errback=d.errback)) 130 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', C.SERVER_SECURITY_LIMIT, prof_found, callback=d.callback, errback=d.errback))