def Logout(self, ident): """ Logout and delete session data """ user = self.GetUser(ident) if not user: return False if not IUser.providedBy(user): user = self.LookupUser(id=user.id) if user: user.Logout() return True
def contact(self): """ Contact form with several configuration options. Can be used to send mails to other users or the system administrator. **Settings** - *title*: (string) title displayed above the form - *receiver*: (string/tuple/callback) send the email to this user. Can be a user id, a `(email, name)` tuple or callback to dynamically lookup the receiver. The callback takes one parameter `form`. - *replyToSender*: (bool) sets the reply to adress to the authenticated sender. - *form*: (dict) the form setup including fields and form settings for the form setup. - *mail*: (nive.views.Mail) The template used to render the email. Form values are passed as `data` to the mail template. Uses `nive_userdb:userview/mails/contact.pt` by default. See nive_userdb.application configuration. **Return values** - *body*: This function returns rendered html code as body. - *X-Result header*: http header indicating whether the new item has been created or not. """ title = u"" mail = receiver = None replyToSender = False subset = u"contact" viewconf = self.GetViewConf() if viewconf and viewconf.get("settings"): title = viewconf.settings.get("title",u"") receiver = viewconf.settings.get("receiver") replyToSender = viewconf.settings.get("replyToSender") subset = viewconf.settings.get("form") mail = viewconf.settings.get("mail") # get the receiver if isinstance(receiver, basestring): user = self.context.root().GetUser(receiver) receiver = ((user.data.get("email"), user.meta.get("title")),) elif IUser.providedBy(receiver): receiver = ((receiver.data.get("email"), receiver.meta.get("title")),) elif callable(receiver): receiver = receiver(self) form, subset = self._loadForm(subset, viewconf=viewconf, defaultsubset="contact") form.startEmpty = True form.Setup(subset=subset) result, data, action = form.Process(receiver=receiver, replyToSender=replyToSender, mail=mail, renderSuccess=False) self.AddHeader("X-Result", str(result).lower()) return {u"content": data, u"result": result, u"head": form.HTMLHead(ignore=[a[0] for a in self.configuration.assets]), u"title": title}