def newaccount( self, environ ) : """Create new user account URLS : /accounts/newaccount?form=request&formname=createuser /accounts/newaccount?form=request&formname=createuser&digest=<digest> /accounts/newaccount?form=submit&formname=createuser /accounts/newaccount?form=submit&formname=createuser&digest=<digest> """ from zeta.config.environment import userscomp, vfcomp c.rclose = h.ZResp() # Calculate whether registration is allowed. regrbyinvite = h.str2bool( c.sysentries['regrbyinvite'] ) c.uinv = None if not regrbyinvite : c.allowregistration = True elif c.digest : c.uinv = userscomp.invbydigest( c.digest ) c.allowregistration = bool(c.uinv) else : c.uinv = None c.allowregistration = False # Setup context for page generation c.usernames = userscomp.usernames # Form handling def errhandler(ERROR_FLASH, errmsg) : h.flash( ERROR_FLASH + errmsg ) h.redirect_url( h.url_register ) vfcomp.process( request, c, defer=True, errhandler=h.hitchfn(errhandler, ERROR_FLASH), formnames=['createuser'] ) # If registeration was successful in `form handling` go-to-signin if c.form == 'submit' : username = request.POST.get( 'username', None ) c.uinv and userscomp.acceptedby( unicode(username), c.uinv ) h.flash( self.okmsg1 ) h.redirect_url( h.url_signin ) # Generate page c.rclose.append(render( '/derived/accounts/register.html' )) return c.rclose
def resetpass( self, environ ) : """Reset user password by validating emailid against `digest`, this controller / action will be invoked when user clicks the reset-link sent to his/her mail-id. URLS : /accounts/resetpass?form=request&formname=resetpass &digest=<digest>&emailid=<emailid> /accounts/resetpass?form=submit&formname=resetpass &emailid=<emailid> """ from zeta.config.environment import userscomp, vfcomp c.rclose = h.ZResp() # Form handling def errhandler(ERROR_FLASH, errmsg) : h.flash( ERROR_FLASH + errmsg ) h.redirect_url( h.url_sitehome ) vfcomp.process( request, c, defer=True, errhandler=h.hitchfn(errhandler, ERROR_FLASH), emailid=c.emailid, formnames=['resetpass'] ) if c.form == 'submit' : # Reset password completed h.flash( self.okmsg2 ) h.redirect_url( h.url_signin ) if c.emailid and c.digest : # Prompt user for new password user = userscomp.userbyemailid( unicode(c.emailid) ) refdigest = sha1( user.username + user.emailid + user.password ).hexdigest() c.allowreset = True # (refdigest == c.digest) # Generate page c.rclose.append( render( '/derived/accounts/resetpass.html' )) return c.rclose h.redirect_url( h.url_sitehome )
def errhandler(ERROR_FLASH, errmsg) : h.flash( ERROR_FLASH + errmsg ) h.redirect_url( h.url_register )
def errhandler(ERROR_FLASH, errmsg) : h.flash( ERROR_FLASH + errmsg ) h.redirect_url( h.url_sitehome )
def createticket(self, environ, projectname): """Create ticket URLS : /p/{projectname}/t/createticket?form=request&formname=createtck /p/{projectname}/t/createticket?form=submit&formname=createtck """ from zeta.config.environment import vfcomp, projcomp, tckcomp c.rclose = h.ZResp() # Handle forms def errhandler(errmsg): c.errmsg = errmsg vfcomp.process(request, c, defer=True, errhandler=h.hitchfn(errhandler), formnames=['createtck'], user=c.authuser) # Setup context for page generation c.project = c.project or projcomp.get_project(projectname) c.projectname = c.project.projectname c.projsummary = c.project.summary # HTML page generation if c.errmsg: html = self.returnerrmsg(environ) elif c.form == 'submit': h.flash(MESSAGE_FLASH + 'Created ticket ...') # Ticket creation, redirect after submit c.title = '-Skip-' h.redirect_url(h.url_ticketcreate) else: # Setup context for page generation c.seltickets = self._seltickets() c.tck_typenames = tckcomp.tcktypenames c.tck_statusnames = tckcomp.tckstatusnames c.tck_severitynames = tckcomp.tckseveritynames c.pcomponents, c.pmilestones, c.pversions, c.projusers = \ tckcomp.projdetails( c.project ) c.projusers = list(set(c.projusers + [c.project.admin.username])) c.pmilestones = [m[:2] for m in c.pmilestones if not any(m[2:])] c.mstnnames = sorted([m[0] for m in c.pmilestones]) c.pcompnames = sorted([comp[0] for comp in c.pcomponents]) c.vernames = sorted([ver[0] for ver in c.pversions]) c.pcomponents = [(tup[1], tup[0]) for tup in c.pcomponents] c.pmilestones = [(tup[1], tup[0]) for tup in c.pmilestones] c.pversions = [(tup[1], tup[0]) for tup in c.pversions] c.title = 'CreateTicket' c.tckeditable = h.authorized(h.HasPermname('TICKET_CREATE')) html = render('/derived/projects/ticketcreate.html') h.flash.pop_messages( ) # Clear flashmessage if any ! after page generation c.rclose.append(html) return c.rclose
def wiki(self, environ, projectname, wurl=None): """Project wiki pages. URLS : /p/{projectname}/wiki/*(wurl) /p/{projectname}/wiki/*(wurl)?ver=<num> /p/{projectname}/wiki/*(wurl)?wikiedit=1 /p/{projectname}/wiki/*(wurl)?wikitalkpage=1 /p/{projectname}/wiki/*(wurl)?wikihistory=1 /p/{projectname}/wiki/*(wurl)?wikidiff=1 /p/{projectname}/wiki/*(wurl)?translate=1 /p/{projectname}/wiki/*(wurl)?downloadas=text /p/{projectname}/wiki/*(wurl)?downloadas=ps /p/{projectname}/wiki/*(wurl)?downloadas=pdf /p/{projectname}/wiki/*(wurl)?jsonobj=wikicomments&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikircomments&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikiattach&view=js /p/{projectname}/wiki/*(wurl)?jsonobj=wikitag&view=js /p/{projectname}/wiki/*(wurl)?textobj=wikipreview&view=text /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikiattachs&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikiattachs&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikitags&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikitags&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikicont&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=createwcmt&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=updatewcmt&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=replywcmt&view=js /p/{projectname}/wiki/*(wurl)?wikidiff=1&form=submit&formname=wikidiff /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikifav&view=js /p/{projectname}/wiki/*(wurl)?form=submit&formname=votewiki&view=js """ from zeta.config.environment import projcomp, wikicomp, votcomp, vfcomp version = request.params.get('ver', None) wurl = wurl.rstrip('/') c.rclose = h.ZResp() # Handle forms def errhandler(errmsg): c.errmsg = errmsg if self.formpermission(): c.errmsg = 'Do not have %s permission !!' % tckperm[c.formname] else: vfcomp.process(request, c, defer=True, errhandler=h.hitchfn(errhandler), formnames=[ 'addwikiattachs', 'delwikiattachs', 'addwikitags', 'delwikitags', 'wikicont', 'createwcmt', 'updatewcmt', 'replywcmt', 'wikidiff', 'wikifav', 'votewiki' ], user=c.authuser) # Setup context for page generation c.projsummary = c.project.summary if not c.jsonobj: c.wikipagenames = self.wikipagename(wikicomp.wikiurls(c.project)) c.wikipagename = wurl c.wikieditable = h.authorized(h.HasPermname('WIKI_CREATE')) c.wiki = c.wiki or wikicomp.get_wiki(unicode(c.pathinfo)) # If there is no wiki page by that name then create the wiki and # show the edit page. if not c.wiki and c.wikieditable: c.wiki = wikicomp.create_wiki(unicode(c.pathinfo), wtype=c.sysentries.get( 'def_wikitype', None), creator=c.authusername) c.project and wikicomp.config_wiki(c.wiki, project=c.project) c.wikiedit = '1' elif not c.wiki: raise NotAuthorizedError( 'Do not have permission to create wiki page, WIKI_CREATE') # If the wiki page is empty (ie) no wiki content ever created, then # show the edit page. if not c.wiki.latest_version and c.wikieditable: h.flash(MESSAGE_FLASH + 'Empty page, write some text ...') c.wikiedit = '1' elif not c.wiki.latest_version: raise NotAuthorizedError( 'Do not have permission to create wiki page, WIKI_CREATE') if c.wiki: c.isuserfavorite = wikicomp.isfavorite(c.authuser.id, c.wiki.id) c.title = wurl # HTML page generation html = '' typename = c.wiki.type.wiki_typename if c.errmsg: html = self.returnerrmsg(environ) if c.view == 'js' and c.formname in ['addwikiattachs']: html = IFRAME_RET elif c.view == 'js' and c.jsonobj: html = self.handlejson(environ) elif c.view == 'text' and c.textobj: html = self.handletext(environ) elif typename == h.WIKITYPE_REDIRECT and c.wiki.sourceurl: # Page redirect h.redirect_url(c.wiki.sourceurl) elif c.wikiedit: c.wcnt = wikicomp.get_content(c.wiki) c.wikitypenames = wikicomp.typenames c.title += ':edit' html = render('/derived/projects/wiki.html') elif c.wtalkpage: c.items_wikicomments = self._json_wikicomments() c.title += ':talkpage' html = render('/derived/projects/wiki.html') elif c.whistory: c.wikicontents = wikicomp.get_content(c.wiki, all=True) c.title += ':history' html = render('/derived/projects/wiki.html') elif c.wikidiff: v = c.oldver or 1 c.wcnt_oldver = wikicomp.get_content(c.wiki, version=v) c.wcnt_newver = wikicomp.get_content(c.wiki, version=c.newver) c.oldver = c.wcnt_oldver.id c.newver = c.wcnt_newver.id c.title += ':diff' html = render('/derived/projects/wiki.html') elif c.downloadas: c.wcnt = wikicomp.get_content(c.wiki) wikihtml = c.wcnt.translate( wiki=c.wiki, cache=True) if not c.wcnt.texthtml else c.wcnt.texthtml fmtobj = h.Html2Doc(wikihtml, format=c.downloadas) c.title = '-Skip-' html = fmtobj.convert() response.headers['Content-disposition'] = \ str( 'attachment; filename="%s.%s"' % (c.wiki.wikiurl, c.downloadas) ) elif c.view != 'js': # Refetch the wiki entry from DB with prepared query c.attachs = self._wikiattachs(c.wiki) c.tags = self._wikitags(c.wiki) c.att_editable = c.tag_editable = c.wikieditable c.wcnts = wikicomp.get_content(c.wiki, all=True) c.wikiauthors = h.computecount(c.wcnts, lambda x: x.author) c.wcnt = (version and c.wcnts[int(version) - 1] or c.wcnts[-1]) if c.wcnts else None c.wikitypenames = wikicomp.typenames c.wikihtml = '' if c.wcnt: if not c.wcnt.texthtml: c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True) elif c.translate: c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True) else: c.wikihtml = c.wcnt.texthtml lastver = c.wiki.latest_version fn = lambda v: [ self.url_wikiurl(projectname, wurl, ver=str(v)), str(v) ] c.wversions = map(fn, range(1, lastver + 1)) c.wdownload = [ [h.url_wikidownastext, 'as text'], [h.url_wikidownasps, 'as post-script'], [h.url_wikidownaspdf, 'as pdf'], ] uservote = votcomp.get_wikivote(c.authuser, c.wiki) votes = wikicomp.countvotes(votes=c.wiki.votes) c.upvotes = votes.get('up', 0) c.downvotes = votes.get('down', 0) c.currvote = uservote and uservote.votedas or '' h.url_reviewwiki = self.url_wikireview(projectname, c.wiki.wikiurl, c.wcnt.id) html = render('/derived/projects/wiki.html') c.rclose.append(html) return c.rclose