Example #1
0
 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
Example #2
0
 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
Example #3
0
 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)
Example #4
0
    def sendLead(self):
        name = request.POST['name']
        email = request.POST['email']
        phone = request.POST['phone']
        message = request.POST['message']
        
        errors = []
        if not valid.email(email):
            errors.append({"selector":"#lead-email", "message":"Please enter a valid email."})
        if len(name) < 3:
            errors.append({"selector":"#lead-name", "message":"Please enter a valid name"})
        
        lead_subj = "Rentfox Lead Inquiry - {0}".format(name)
        lead_msg = """\
Dear Rentfox Sales,

A potential customer would like to be contacted!
Please do your best to provide excellent service and leave a good impression no matter the outcome.

Name: {0}
Email: {1}
Phone (optional): {2}

Message (optional):
{3}

Best Regards,

Rentfox
""".format(name, email, phone, message)

        thanks_subj = "Thanks for your inquiry!"
        thanks_msg = """\
Dear {0},

Thank you for your inquiry regarding Rentfox.
Rentfox is the easy way to manage rental properties online.

We value your business and will respond quickly. We are happy to be of service!

You will hear back from us sometime within the next 24 hours.

Best Regards,

The Rentfox Team
http://{1}
""".format(name, settings.WEBSITE)


        if len(errors) == 0:
            mailman.send([settings.EMAIL_SALES], lead_subj, lead_msg)
            mailman.send([email], thanks_subj, thanks_msg)
        
        return json.dumps({'errors':errors})
        
Example #5
0
 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)
Example #6
0
 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
Example #7
0
 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
Example #8
0
 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})
Example #9
0
 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)