class Login(Form, Breadcrumbs): subTitle = 'Login Form' title = "ZODB Crud Demo" fields = Fields(ILogin) ignoreContent = True @property def action_url(self): return self.request.url def acquireTitle(self): return "ZODB Demo" def breadcrumbs(self): return '' @action('Log me') def login(self): data, errors = self.extractData() if errors: form.errors = errors return FAILURE success = self.context.authenticate(data['username'], data['password']) if not success: self.errors.append( Error( title='Login failed', identifier=self.prefix, )) return FAILURE raise HTTPFound(self.request.url)
class Login(Form): fields = Fields(ILogin) ignoreContent = True @property def action_url(self): return self.request.url @action('Log me') def login(self): data, errors = self.extractData() if errors: form.errors = errors return FAILURE success = self.context.authenticate( data['username'], data['password']) if not success: self.errors.append(Error( title='Login failed', identifier=self.prefix, )) return FAILURE raise HTTPFound(self.request.url)
class ChangePassword(uvcsite.Form): """A Form for updating a User in ENMS. """ grok.title(u'Passwort ändern') grok.context(IMyHomeFolder) label = _(u'Passwort ändern') description = _(u'Hier können Sie Ihr Passwort ändern') # uvcsite.menu(uvcsite.PersonalMenu) grok.require('zope.View') ignoreContext = True fields = Fields(IExtranetMember).select('passwort', 'confirm') @base.action(_(u"Bearbeiten")) def changePasswort(self): data, errors = self.extractData() if errors: self.flash('Es sind Fehler aufgetreten', type='error') return um = getUtility(IUserManagement) principal = self.request.principal.id data['mnr'] = principal um.updatePasswort(**data) self.flash(_(u'Ihr Passwort wurde gespeichert!')) self.redirect(self.url(self.context))
class Login(Form): name('login') context(Interface) require('zope.Public') fields = Fields(ILoginForm) fields['came_from'].mode = HIDDEN fields['came_from'].ignoreRequest = False fields['username'].ignoreRequest = False ignoreRequest = True def make_principal(self, **kwargs): return Principal(**kwargs) def credentials_managers(self): site = getSite() if site is not None: for credential in getattr(site, 'credentials', []): yield getUtility(ICredentials, name=credential) @action(_(u'Login')) def log_me(self): data, errors = self.extractData() if errors: self.submissionError = errors return FAILURE credendials_managers = list(self.credentials_managers()) if credendials_managers is None: self.flash(_(u"Missing credentials.")) return SuccessMarker('Login failed', False) for credentials_manager in credendials_managers: result = credentials_manager.log_in(self.request, **data) if isinstance(result, SuccessMarker): self.flash(result.name) return result elif result: session = getSession() session['username'] = data['username'] self.flash(_(u"Login successful.")) principal = self.make_principal(id=data['username']) self.request.principal = principal notify(UserLoggedInEvent(principal)) camefrom = data.get('camefrom', self.url(self.context)) return SuccessMarker( 'Login successful', True, url=camefrom, code=302) self.flash(_(u'Login failed.')) return FAILURE
class Edit(Form): fields = Fields(ILeaf) ignoreContent = False @action('Apply') def apply(self): data, errors = self.extractData() if errors: form.errors = errors return FAILURE content = self.getContent() apply_data_event(self.fields, content, data) raise HTTPFound(IURL(content, self.request))
class AddLeaf(Form): fields = Fields(ILeaf) ignoreContent = True @action('Add') def add(self): data, errors = self.extractData() if errors: form.errors = errors return FAILURE uid = str(uuid.uuid4()) # a simple UUID id to avoid conflict. content = Leaf(data['title'], data['body']) self.context[uid] = content raise HTTPFound(IURL(self.context, self.request))
def extract(self): value = self.request.form.get(self.identifier, NO_VALUE) if value is not NO_VALUE: try: value = int(value) except ValueError: return (None, u"Invalid internal input") collectedValues = [] for position in range(0, int(value)): value_present = '%s.present.%d' % ( self.identifier, position) in self.request.form if not value_present: # This value have been removed continue field = self.valueField.clone(new_identifier=str(position)) form = cloneFormData(self.form, prefix=self.identifier) data, errors = form.extractData(Fields(field)) if errors: return (None, errors) collectedValues.append(data[field.identifier]) value = self.component.collectionType(collectedValues) return (value, None)
def getAllFields(obj, *ignore): ifaces = tuple(providedBy(obj)) return Fields(*ifaces).omit(*ignore)
def getFactoryFields(form, factory, *ignore): ifaces = factory.getInterfaces() if ifaces: fields = Fields(*ifaces).omit(*ignore) return fields return Fields()
def __init__(self, field): super(ObjectSchemaField, self).__init__(field) self.schema = field.schema self.__object_fields = Fields(self.schema)
def __init__(self, parent, name): self.__parent__ = parent self.__name__ = "++%s++" % name self.um = getUtility(IUserManagement) self.mnr, self.az = self.um.zerlegUser(parent.__name__) self.user_schema = Fields(self.um.UserInterface)
def fields(self): return Fields(self.context.__parent__.user_schema)
def fields(self): return Fields(self.context.user_schema)
def update(self): self.fields = Fields(self.context.user_schema).omit( 'passwort', 'confirm') self.users = iter(self.context)
def fields(self): content_object = self.context schemas = schema.bind().get(content_object) return Fields(*schemas)
def fields(self): if hasattr(self,'interface'): return Fields(IName,self.interface).omit("__parent__") return Fields()