def get(self): id = self.get_argument("uuid", "").strip() result = CMDBOpreate.get_cmdb_info_by_uuid(uuid=id) if not result: self.write({"code": 0, "message": "", "data": []}) return data_obj = AuthInfoCMDBParser(data=result) db_obj = AuthInfo.query.filter(AuthInfo.id == data_obj.id).first() if data_obj.status == 1: msg = options.sms_real_name_auth_template.format("已", ".") # 更新状态为已通过 db_obj.status = data_obj.status elif data_obj.status == 0: msg = options.sms_real_name_auth_template.format("未", ",请重新提交申请") # 删除申请 db_obj.status = data_obj.status db_obj.deleted = True else: em = "undefine status code <{0}>".format(data_obj.status) LOG.exception(em) self.json_response(code=1, result=[], message=em) return # 发送短信 send_msg(phone=data_obj.auth_phone, msg=msg) db_session.commit() # 同步数据到cmdb CMDBOpreate.syncdata2cmdb(resouce_type="new_realauth", id=id) self.json_response(code=0, result=db_obj)
def post(self): data = json.loads(self.request.body) user_id = str(data.get("user_id", "")).strip() user_name = str(data.get("user_name", "")).strip() auth_phone = str(data.get("auth_phone", "")).strip() if not user_id or not auth_phone: em = "Error. sync user real name auth. argment error" LOG.exception(em) self.write({"code": 1, "result": em}) return # 更新数据库,如果存在则更新,不存在则添加 check_user = RegisterPhones.query.filter( RegisterPhones.user_id == user_id).first() if not check_user: db_obj = RegisterPhones(id=str(uuid.uuid1()), user_name=user_name, user_id=user_id, phone=auth_phone, is_real_auth=True, is_sms_auth=True) db_session.add(db_obj) else: # 实名认证的手机和注册的手机是否相同 if check_user.phone != auth_phone: self.write({"code": 1, "result": "与注册手机不相符,请重新输入手机号"}) return check_user.is_real_auth = True check_user.is_sms_auth = True db_session.commit() self.write({"code": 0, "result": ""})
def delete_auth_info(id): result = AuthInfo.query.filter( and_(AuthInfo.id == id, AuthInfo.deleted == False)).first() # 认证已通过,不能删除 if result.status: return False result.deleted = True db_session.commit() return result
def update_user_info(user_id, **kwargs): """不能更新手机号,需要调用单独的接口""" user_info = RegisterPhones.query.filter( RegisterPhones.user_id == user_id).first() if not user_info: em = u"未找到记录" return {"code": 1, "result": em} name = kwargs.get("name", "") company = kwargs.get("company", "") RegisterPhones.query.filter(RegisterPhones.user_id == user_id).\ update({RegisterPhones.name: name, RegisterPhones.company: company}) db_session.commit() return {"code": 0, "result": ""}
def update_auth_info(id, data): # 只能更新腾讯打款过来的金额 result = AuthInfo.query.filter( and_(AuthInfo.id == id, AuthInfo.deleted == False)).first() if not result: em = "can not found id: <{0}> from authinfo".format(id) LOG.exception(em) return {} result.auth_money = data.get("auth_money") db_session.commit() result.image_list = [] images = Images.query.filter( and_(Images.deleted == False, Images.auth_info_id == result.id)).all() for image in images: result.image_list.append({ "id": image.id, "url": get_pictuer_url(image.name) }) return result
def update_phone(new_phone, session_id, auth_code, user_id, user_name): """用户修改手机号码""" session_id = session_id + "_" + new_phone # 检查验证码 ret = SendSmsMsg.check_auth_code(session_id=session_id, auth_code=auth_code) if ret.get("code") != 0: return ret db_obj = RegisterPhones.query.filter( RegisterPhones.user_id == user_id).first() if not db_obj: # 没有就添加 add_obj = RegisterPhones(id=str(uuid.uuid1()), user_id=user_id, phone=new_phone, user_name=user_name) db_session.add(add_obj) else: RegisterPhones.query.filter(RegisterPhones.user_id == user_id).\ update({RegisterPhones.phone: new_phone, RegisterPhones.user_name: user_name}) db_session.commit() return {"code": 0, "result": ""}
def add_user_info(user_id, user_name, name, company): """添加用户信息""" user_info = RegisterPhones.query.filter( RegisterPhones.user_id == user_id).first() # 找到,更新 if user_info: if name: user_info.name = name if company: user_info.company = company # 未找到,添加 else: # 检查验证码 user_info = RegisterPhones( id=str(uuid.uuid1()), user_name=user_name, user_id=user_id, name=name, company=company, ) db_session.add(user_info) db_session.commit() return {"code": 0, "result": ""}
def post(self): try: data = json.loads(self.request.body) user_name = data.get("user_name").strip() password = data.get("password").strip() phone = str(data.get("phone")).strip() session_id = data.get("session_id").strip() auth_code = str(data.get("auth_code")).strip() description = json.dumps({"phone": phone}) if not user_name: self.write({"code": 1, "result": "用户名无效"}) self.set_status(500) return if not password: self.write({"code": 1, "result": "密码无效"}) self.set_status(500) return if not phone: self.write({"code": 1, "result": "手机号无效"}) self.set_status(500) return if not session_id: self.write({"code": 1, "result": "会话ID无效"}) self.set_status(500) return # 检查用户是否存在 ret = UserManager.get_user_id_by_name(user_name) if ret[0]: self.set_status(409) self.write({"code": 1, "result": "用户已存在"}) return # 检查验证码 ret = SendSmsMsg.check_phone(session_id + "_" + phone) if not ret: self.write({"code": 1, "result": "无效的验证码"}) self.set_status(500) return if str(auth_code) != str(ret): self.write({"code": 1, "result": "无效的验证码"}) self.set_status(500) return # 检查手机号码是否被注册 phone_check = RegisterPhones.query.filter( RegisterPhones.phone == phone).first() if phone_check: self.set_status(409) self.write({"code": 1, "result": "手机已被注册"}) return ret = UserManager.create_user_project(user_name, password, description) if not ret[0]: self.write({"code": 1, "result": "创建失败"}) return # 添加到数据库 user_id = UserManager.get_user_id_by_name(user_name) db_obj = RegisterPhones(id=str(uuid.uuid1()), user_name=user_name, user_id=user_id, phone=phone) db_session.add(db_obj) db_session.commit() # 清除redis中的数据 SendSmsMsg.delete_phone_auth_code(session_id + "_" + phone) self.write({"code": 0, "result": "创建成功"}) except Exception as e: LOG.exception(e) self.set_status(500) self.write({"code": 1, "result": "未知错误{0}".format(e)})