#module: member.py # from pso import parser, form, fields, tags import login from datamodel import Member import datamodel class MemberMixin(tags.DataMixin): KEY= Member.IDKEY DATAMODEL=datamodel def getRecord(self, handler, key): return Member.load(key) class MemberForm(form.Form): def goNext(self, handler, cdata): handler.req().redirect('test.cgi') class NewForm(MemberForm): def submit(self, handler, cdata): data = self.prepareData(handler) member = Member(**data) member.save() #while we are at it lets log the bugger in. login.LoginLogout().logIn(handler, data['memberId']) class EditForm(MemberForm): def submit(self, handler, cdata): data = self.prepareData(handler) member = Member.load(data[Member.IDKEY]) member.update(self.prepareData(handler)) member.save() class NameInput(form.Input, MemberMixin): pass class EmailInput(fields.EmailInput, MemberMixin):pass class StateSelect(fields.StateSelect, MemberMixin):pass class ZipInput(fields.ZipInput, MemberMixin):pass class MemberIdInput(fields.UserIdInput, MemberMixin):pass class PasswordGroup(form.PasswordGroup):pass class PasswordInput(form.PasswordInput, MemberMixin):pass class PasswordConfirmInput(form.PasswordConfirmInput, MemberMixin):pass class Os( form.Options, MemberMixin):pass class OsCheckBox(form.CheckBox, MemberMixin):pass class Spam(form.Options, MemberMixin):pass class SpamRadio(form.Radio, MemberMixin):pass class JoinUpSubmit(form.Submit):pass class MessageTextArea(form.TextArea, MemberMixin):pass class PhotoFile(form.File, MemberMixin): pass class MyAccount(parser.Tag): """ if user is logged in shows welcome with link to edit""" WELCOME="Welcome" def __call__(self, handler, cdata=''): user = login.LoginLogout().getLogin(handler) if user: welcome = self.getAttrs().get('welcome', self.WELCOME) return '%s' % (user, user) return "" class Security(parser.Tag): def __call__(self, handler, cdata): if self.check(handler): return '' # if so do nothing # not authorized or some malicious exception ? bang him to the login page handler.req().redirect('test.cgi?action=login') def check(self, handler): user = login.LoginLogout().getLogin(handler) # check if the user owns the record return user == handler.req().getInput('memberId')