def update(self, id): domain = meta.Session.query(model.Domain).filter_by(id=id).first() c.fs = DomainFields.bind(domain, data=request.POST) if c.fs.validate(): c.fs.sync() meta.Session.commit() h.flash('Domain updated.') return redirect(url('domains')) else: return render('domains/edit.html')
def update(self, id): record = meta.Session.query(model.Record).filter_by(id=id, domain_id=c.domain.id).first() c.fs = RecordFields.bind(record, data=request.POST) if c.fs.validate(): c.fs.sync() meta.Session.commit() h.flash('Record updated.') return redirect(url('domain', id=c.domain.id)) else: return render('records/edit.html')
def create(self): domain = model.Domain() c.fs = DomainFields.bind(domain, data=request.POST) if c.fs.validate(): c.fs.sync() meta.Session.add(domain) meta.Session.commit() h.flash('Domain created.') return redirect(url('domains')) else: return render('domains/new.html')
def update(self, id): user = meta.Session.query(model.User).filter_by(id=id).first() c.fs = UserFields.bind(user, data=request.POST) c.fs.password.validators.remove(formalchemy.validators.required) if c.fs.validate(): c.fs.sync() meta.Session.commit() h.flash('User updated.') return redirect(url('users')) else: return render('users/edit.html')
def create(self): user = model.User() c.fs = UserFields.bind(user, data=request.POST) if c.fs.validate(): c.fs.sync() meta.Session.add(user) meta.Session.commit() h.flash('User created.') return redirect(url('users')) else: return render('users/new.html')
def create(self): record = model.Record() c.fs = RecordFields.bind(record, data=request.POST) if c.fs.validate(): c.fs.sync() record.domain_id = c.domain.id meta.Session.add(record) meta.Session.commit() h.flash('Record created.') return redirect(url('domain', id=c.domain.id)) else: return render('records/new.html')
def sign_up_submit(self): user = model.User() c.fs = UserFields.bind(user, data=request.POST) if c.fs.validate(): c.fs.sync() meta.Session.add(user) meta.Session.commit() meta.Session.commit() h.flash('You have successfully signed up.') redirect('/') else: return render('/auth/sign_up.html')
def __before__(self): # Authentication required? if (self.requires_auth or self.requires_admin) and "user" not in session: # Remember where we came from so that the user can be sent there # after a successful login session["path_before_login"] = request.path_info session.save() h.flash("You have to sign up or sign in before access this page.") return redirect(url(controller="auth", action="sign_in")) if self.requires_admin: if "user" not in session or session["user"].is_admin == False: h.flash("You don't have permissions to access this page.", "warning") redirect("/")
def sign_in_submit(self): c.fs = UserFields.bind(model.User, data=request.POST) user = meta.Session.query(model.User).filter_by(username=c.fs.username.value).first() if (user and user.authenticate(c.fs.password.value)): if user.is_active == True: session["user"] = user session.save() h.flash('Logged in successfully.') if 'path_before_login' in session: redirect(session['path_before_login']) else: h.flash('Please wait before your account will be activated.') redirect('/') else: h.flash('Username or password doesn\'t match.') return render('/auth/sign_in.html')
def delete(self, id): domain = meta.Session.query(model.Domain).filter_by(id=id).first() meta.Session.delete(domain) meta.Session.commit() h.flash('Domain deleted.') return redirect(url('domains'))
def delete(self, id): user = meta.Session.query(model.User).filter_by(id=id).first() meta.Session.delete(user) meta.Session.commit() h.flash('User deleted.') return redirect(url('users'))
def delete(self, id): record = meta.Session.query(Record).filter_by(id=id, domain_id=c.domain.id).first() meta.Session.delete(record) meta.Session.commit() h.flash('Record deleted.') return redirect(url('domain', id=c.domain.id))
def sign_out(self): session["user"] = None session.delete() h.flash("You have been logged out.") redirect('/')