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 validate(self): name = request.POST['name'].strip() street = request.POST['street'].strip() city = request.POST['city'].strip() state = request.POST['state'].strip() zip = request.POST['zip'].strip() email = request.POST['email'].strip() phone = request.POST['phone'].strip() errorslist = [] if not valid.label(name): errorslist.append({'selector':'#update-name', "message":"Please enter a valid company name"}) elif street and not valid.street(street): errorslist.append({'selector':'#update-street', "message":"Please enter a valid street address"}) elif phone and not valid.phone(phone): errorslist.append({'selector':'#update-phone', "message":"Please enter a valid phone"}) elif email and not valid.email(email): errorslist.append({'selector':'#update-email', "message":"Please enter a valid email"}) elif city or state or zip: if not valid.city(city): errorslist.append({'selector':'#update-city', "message":"Please enter a valid city"}) if not valid.state(state): errorslist.append({'selector':'#update-state', "message":"Please enter a valid state"}) if not valid.zip(zip): errorslist.append({'selector':'#update-zip', "message":"Please enter a valid zip"}) return errorslist
def saveResidence(self): residenceid = request.POST['residenceId'] tenantid = request.POST['tenantId'] startdate = request.POST['startdate'].strip() enddate = request.POST['enddate'].strip() street = request.POST['street'].strip() city = request.POST['city'].strip() state = request.POST['state'].strip() landlordname = request.POST['landlordname'].strip() landlordphone = request.POST['landlordphone'].strip() landlordemail = request.POST['landlordemail'].strip() reason = request.POST['reason'].strip() errors = [] if not valid.date(startdate): errors.append({'selector':'#residenceStart','message':'Please enter a valid date.'}) if not valid.date(enddate): errors.append({'selector':'#residenceEnd','message':'Please enter a valid date.'}) if not valid.date(startdate, enddate): errors.append({'selector':'#residenceEnd','message':'The end date is greater than the start date.'}) if not valid.street(street): errors.append({'selector':'#residenceStreet','message':'Please enter a valid street.'}) if not valid.city(city): errors.append({'selector':'#residenceCity','message':'Please enter a valid city.'}) if not valid.state(state): errors.append({'selector':'#residenceState','message':'Please enter a valid state.'}) """ if not valid.name(landlordname) and len(landlordname): errors.append({'selector':'#residenceLandlord','message':'Please enter a valid name for the landlord.'}) """ if not valid.phone(landlordphone) and len(landlordphone): errors.append({'selector':'#residenceLandlordPhone','message':'Please enter a phone number for the landlord.'}) if not valid.email(landlordemail) and len(landlordemail): errors.append({'selector':'#residenceLandlordEmail','message':'Please enter a valid email for the landlord.'}) if not valid.text(reason) and len(reason): errors.append({'selector':'#residenceReasonLeaving','message':'There is an error with the "reason for leaving" field. Please double check you didn\'t enter any strange characters.'}) if errors: return json.dumps({'errors':errors}) startdate = startdate.split("/") startdate = datetime.date(int(startdate[2]), int(startdate[0]), int(startdate[1])) enddate = enddate.split("/") enddate = datetime.date(int(enddate[2]), int(enddate[0]), int(enddate[1])) if residenceid == '0': residenceid = str(uuid.uuid1()) model.Previous_residence(residenceid, tenantid, startdate, enddate, street,\ city, state, landlordname, landlordemail, landlordphone, reason) else: model.Previous_residence.save(residenceid, tenantid, startdate, enddate, street,\ city, state, landlordname, landlordemail, landlordphone, reason) redirect_to(protocol=settings.PROTOCOL, controller='tenant', action='json', id=tenantid)
def validate(self): label = request.POST['label'] address = request.POST['address'] city = request.POST['city'] state = request.POST['state'] zip = request.POST['zip'] phone = request.POST['phone'] email = request.POST['email'] type = request.POST['type'].strip() description = request.POST['description'] errorslist = [] if not valid.label(label): errorslist.append({'selector':'#name', "message":"Please enter a valid name"}) if not email and not phone: errorslist.append({'selector':'#email,#phone', "message":"You must enter either an email or a phone number"}) if email and not valid.email(email): errorslist.append({'selector':'#email', "message":"Please enter a valid email"}) if phone and not valid.phone(phone): errorslist.append({'selector':'#phone', "message":"Please enter a valid phone"}) if int(request.POST['newtype']) and not valid.label(type): errorslist.append({'selector':'#new-type-label', "message":"Please enter a valid type name"}) if address and not valid.street(address): errorslist.append({'selector':'#street', "message":"Please enter a valid street"}) if city and not valid.city(city): errorslist.append({'selector':'#city', "message":"Please enter a valid city"}) if state and not valid.state(state): errorslist.append({'selector':'#state', "message":"Please enter a valid state"}) if zip and not valid.zip(zip): errorslist.append({'selector':'#zip', "message":"Please enter a valid zip code"}) if description and not valid.description(description): errorslist.append({'selector':'#description', "message":'Please enter description without special characters\ such as "<","^","@", etc'}) if not type: errorslist.append({'selector':'#new-type-label', "message":"Please enter a valid category"}) return errorslist
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)
def saveContact(self): contactid = request.POST['contactId'] tenantid = request.POST['tenantId'] name = request.POST['name'].strip() phone = request.POST['phone'].strip() relationship = request.POST['relationship'].strip() errors = [] """ if not valid.name(name): errors.append({'selector':'#emergencyName','message':'The name is invalid.'}) """ if not valid.phone(phone): errors.append({'selector':'#emergencyPhone','message':'The phone number is not valid.'}) if not valid.text(relationship): errors.append({'selector':'#emergencyRelationship','message':'Please specify a valid relationship, eg "Friend".'}) if errors: return json.dumps({'errors':errors}) if contactid == '0': contactid = str(uuid.uuid1()) model.Emergency_contact.create( id=contactid, tenantid=tenantid, name=name, phone=phone, relationship=relationship) else: model.Emergency_contact.save( id=contactid, tenantid=tenantid, name=name, phone=phone, relationship=relationship) redirect_to(protocol=settings.PROTOCOL, controller='tenant', action='json', id=tenantid)