def post(self): data = self.get_data() if 'phone' in data and 'code' in data: user = User.query.get_by_phone(data['phone']) if not user: sms_send(data['phone'], {'code': data['code']}, 1) msg = self.message("Message be sent.") else: self.set_status(409) msg = self.message("The user is already existed.") else: self.set_status(400) msg = self.message("phone, code fields are required.") self.render_json(msg)
def put(self, phn): user = User.query.get_by_phone(phn) if user: new_password = generate_password() if sms_send(user.phone, {'name': user.name, 'password': new_password}, 2) > 0: user.password = new_password user.save() msg = self.message("Message be sent.") else: self.set_status(404) msg = self.message("The user is not exsited.") self.render_json(msg)