def validate(self, action=None): company_id = request.environ.get("COMPANY_ID") first_name = request.POST['fname'].strip() last_name = request.POST['lname'].strip() email = request.POST['email'].strip() phone = request.POST['phone'].strip() usertype = int(request.POST['admin']) and 'admin' or 'manager' userid = action == 'update' and request.POST['userId'] or None errorslist = [] if not valid.name(first_name): errorslist.append({'selector':'#{0}-fname'.format(action), "message":"Please enter a valid first name"}) if not valid.name(last_name): errorslist.append({'selector':'#{0}-lname'.format(action), "message":"Please enter a valid last name"}) if not valid.phone(phone): errorslist.append({'selector':'#{0}-phone'.format(action), "message":"Please enter a valid phone number"}) if not valid.email(email): errorslist.append({'selector':'#{0}-email'.format(action), "message":"Please enter a valid email"}) else: if model.Manager.email_exist(email, userid): errorslist.append({"selector":"#{0}-email".format(action), "message":"Sorry, this email address is taken."}) return errorslist
def exists(self): fname = request.POST['fname'] lname = request.POST['lname'] email = request.POST['email'] phone = request.POST['phone'] if len(request.POST['dob'].strip()): birthday = request.POST['dob'].split('/') dob = datetime.date(int(birthday[2]), int(birthday[0]), int(birthday[1])) else: dob = None ssn = request.POST['ssn'] leaseId = request.POST['leaseId'] fullName = fname + ' ' + lname errors = [] if not valid.name(fname): errors.append({'selector':'#fname','message':'The first name is invalid.'}) if not valid.name(lname): errors.append({'selector':'#lname','message':'The last name is invalid.'}) if not valid.email(email) and len(email): errors.append({'selector':'#email','message':'Please enter a valid email address.'}) if errors: return json.dumps({'errors':errors}) tenant_q = model.Tenant.name_match(fname, lname) if tenant_q: tenantsArray = [] for tenant in tenant_q: # improve this code with join later tenant_lease = meta.Session.query(model.Tenant_lease).filter_by(tenantid=tenant.id).first() if tenant_lease: lease = meta.Session.query(model.Lease).filter_by(id=tenant_lease.leaseid).first() unitid = lease.unitid unit = meta.Session.query(model.Unit).filter_by(id=unitid).first() unit = { 'id': unit.id, 'display': unit.label } else: unit = 0 tenantObj = { 'id': tenant.id, 'name': tenant.first_name + ' ' + tenant.last_name, 'email': tenant.email, 'unit': unit } tenantsArray.append(tenantObj) matchJSON = { 'match': 1, 'tenants': tenantsArray } return json.dumps(matchJSON) else: self.create(fname, lname, email, phone, dob, ssn, leaseId)
def validate(self): fname = request.POST['fname'].strip() lname = request.POST['lname'].strip() email = request.POST['email'].strip() phone = request.POST['phone'].strip() errorslist = [] if email and not valid.email(email): errorslist.append({'selector':'#update-email', "message":"Please enter a valid email"}) elif phone and not valid.phone(phone): errorslist.append({'selector':'#update-phone', "message":"Please enter a valid phone"}) else: if not valid.name(fname): errorslist.append({'selector':'#update-fname', "message":"Please enter a valid name"}) if not valid.name(lname): errorslist.append({'selector':'#update-lname', "message":"Please enter a valid name"}) return errorslist
def signUpBasicInfoCheck(self): company = request.POST['company'].strip() fname = request.POST['fname'].strip() lname = request.POST['lname'].strip() email = request.POST['email'].strip() phone = request.POST['phone'].strip() errors = [] if not valid.text(company): errors.append({"selector":"#signupCompany", "message":"Invalid characters detected."}) if not valid.name(fname): errors.append({"selector":"#signupFName", "message":"Please enter a valid first name."}) if not valid.name(lname): errors.append({"selector":"#signupLName", "message":"Please enter a valid last name."}) if not valid.email(email): errors.append({"selector":"#signupEmail", "message":"Please enter a valid email."}) if not valid.phone(phone): errors.append({"selector":"#signupPhone", "message":"Please enter a valid phone #."}) return json.dumps({"errors":errors})
def updateTenant(self): tenantid = request.POST['tenantId'] fname = request.POST['fname'] lname = request.POST['lname'] email = request.POST['email'] phone = request.POST['phone'] if len(request.POST['dob'].strip()): birthday = request.POST['dob'].split('/') dob = datetime.date(int(birthday[2]), int(birthday[0]), int(birthday[1])) else: dob = None ssn = request.POST['ssn'] errors = [] if not valid.name(fname): errors.append({'selector':'#tenantFname','message':'The first name is invalid.'}) if not valid.name(lname): errors.append({'selector':'#tenantLname','message':'The last name is invalid.'}) if not valid.phone(phone) and len(phone): errors.append({'selector':'#tenantPhone','message':'The phone number is not valid.'}) if not valid.email(email) and len(email): errors.append({'selector':'#tenantEmail','message':'Please enter a valid email address.'}) if not valid.date(request.POST['dob']) and len(request.POST['dob']): errors.append({'selector':'#tenantDOB','message':'Please enter a valid date for the D.O.B.'}) if not valid.ssn(ssn) and len(ssn): errors.append({'selector':'#tenantSSN','message':'Please enter a valid social security number.'}) if errors: return json.dumps({'errors':errors}) model.Tenant.update( id=tenantid, first_name=fname, last_name=lname, email=email, phone=phone, dob=dob, ssn=ssn) redirect_to(protocol=settings.PROTOCOL, controller='tenant', action='json', id=tenantid)