def PUT_cleaner(id): try: data = JSONencoder.load(request.data) cleaner.update(id, data) return respond200() except Exception as e: return respond500(e)
def send_reset_code(): """ Send reset_code via SMS to the user Each reset_code expires after RESET_CODE_EXPIRATION If not yet set, or if expired, reset reset_code and reset_code_expires """ try: data = json.loads(request.data) if not 'phonenumber' in data: raise APIexception(code=1) phonenumber = data['phonenumber'] c = cleaner.find_one(phonenumber=phonenumber) if not c: raise APIexception(code=2) if ('reset_code' in c and 'reset_code_expires' in c and (datetime.now() < c['reset_code_expires'])): reset_code = c["reset_code"] else: (reset_code, reset_code_expires) = cleaner.generate_reset_code() cleaner.update(c["_id"], { "reset_code": reset_code, "reset_code_expires": reset_code_expires }) twilio_tools.send_SMS( phonenumber, str("Your password reset code is: " + reset_code)) return respond200() except Exception as e: return respond500(e)
def PUT_send_list(id): """ Sends new agreement to client via SMS @param {id} _id of list to send as agreement to client payload: Request is made with entire list object - have _cleaner as cleaner._id Returns 200 response """ try: list_data = JSONencoder.load(request.data) # verify phonenumber in list_data -- need it to send link to receipt to client if not 'phonenumber' in list_data: raise APIexception(code=1) phonenumber = list_data['phonenumber'] # need to fetch cleaner for just cleaner's name in SMS message cleaner_id = list_data[ '_cleaner'] # something went wrong with request if _cleaner not in payload c = cleaner.find_one(id=cleaner_id) # send SMS to client that has link to viewable agreement twilio_tools.send_agreement(phonenumber, c['name'], id) return respond200() except Exception as e: return respond500(e)
def POST_reset_password(): try: data = json.loads(request.data) c = cleaner.find_one(phonenumber=data['phonenumber']) if not (c and 'reset_code' in c): raise APIexception(code=0) if not ((data['reset_code'] == c["reset_code"]) and (datetime.now() < c['reset_code_expires'])): raise APIexception(code=3) # if they made it this far all is good cleaner.update_password(c["_id"], data["password"], c["salt"]) login(cleaner.public(c)) return respond200() except Exception as e: return respond500(e)
def GET_validate_new_phonenumber(): """ Expects phonenumber and name in request arguments Validates that phonenumber is new and sends welcome message via SMS """ try: # get name from request if 'name' not in request.args: raise APIexception(code=6) name = request.args['name'] # get phonenumber from request if 'phonenumber' not in request.args: raise APIexception(code=1) phonenumber = request.args['phonenumber'] # insure phonenumber is new if cleaner.find(phonenumber=phonenumber): raise APIexception(code=5) twilio_tools.send_welcome(phonenumber, name) return respond200() except Exception as e: return respond500(e)
def DELETE_task(id): try: task.delete(id) return respond200() except Exception as e: return respond500(e)
def DELETE_feedback(id): try: feedback.delete(id) return respond200() except Exception as e: return respond500(e)
def DELETE_list(id): try: List.delete(id) return respond200() except Exception as e: return respond500(e)
def DELETE_cleaner(id): try: cleaner.delete(id) return respond200() except Exception as e: return respond500(e)
def HTTP_logout(): """ Import that logout performed with a POST due to mobile browsers' aggressive caching """ logout() return respond200( ) # dont redirect -- then caches will remember where to redirect to rather than making POST