def deleteInfo(): if 'g-recaptcha-response' in request.args: g_recaptcha_response = request.args['g-recaptcha-response'] if recaptcha.verify(g_recaptcha_response): u_mail = request.args['mail'] u_password = request.args['password'] if database.is_exist(u_mail): d_status, d_password = database.query_password(u_mail) if d_status: if database.check_password( u_password, base64.b64decode(d_password).decode()): id_status, u_id = database.find_ID(u_mail) if id_status: database.delete(u_id) status, msg = database.reformat_id() if status: return {'status': True, 'data': '重新排序成功'} else: return {'status': True, 'data': msg} return {'status': True, 'data': '删除成功'} else: return {'status': False, 'data': '服务器错误'} else: return {'status': False, 'data': '密码错误'} else: return {'status': False, 'data': '服务器错误'} else: {'status': False, 'data': '邮箱不存在'} else: return errors.recaptcha_verify_failed else: return errors.recaptcha_not_found
def oauth(): global user url = request.url print(url) text = re.sub('.*\?', '', url) params = parser(text) user = OAuth1Session(CK, CS, params['oauth_token'], params['oauth_verifier']) res = user.post('https://api.twitter.com/oauth/access_token', params) params = parser(res.text) print(params) AK, AS = params['oauth_token'], params['oauth_token_secret'] id_ = params['user_id'] user = OAuth1Session(CK, CS, AK, AS) with open('datas.json', 'r') as f: obj = json.load(f) if is_exist(id_): print('update') update_user(id_, AK, AS) else: print('insert') insert_user(id_, AK, AS) return redirect(url_for('application'))
def update(): if 'g-recaptcha-response' in request.form: g_recaptcha_response = request.form['g-recaptcha-response'] if recaptcha.verify(g_recaptcha_response): u_name = request.form['name'] u_mail = request.form['mail'] u_password = request.form['password'] origin_mail = request.form['originMail'] origin_password = request.form['originPassword'] has_new_password = False if u_password == '' else True # 过滤异常请求,分为更改了密码和未更改密码 if has_new_password: # 更改了密码 u_repeat_password = request.form['repeat-password'] password = u_password if u_password == u_repeat_password else False if not password: return redirect(f'/updateInfo.html?msg=输入的密码不相同', 302) if database.is_exist(origin_mail): d_status, d_password = database.query_password(origin_mail) if d_status: if not database.check_password( origin_password, base64.b64decode(d_password).decode()): return redirect(f'/updateInfo.html?msg=认证失败', 302) else: u_password = database.encrypt_password( u_password.encode()) # 成功 else: return redirect(f'/updateInfo.html?msg=原密码查询失败', 302) else: return redirect(f'/updateInfo.html?msg=邮箱不存在', 302) else: # 未更改密码 qp_status, p_data = database.query_password(origin_mail) if qp_status: # 成功 u_password = base64.b64decode(p_data).decode() else: return redirect(f'/updateInfo.html?msg=原密码查询失败', 302) # 执行 update u_pubkey = request.form['pubkey'] u_uuid = database.get_u_uuid(u_mail) u_date = database.get_u_date() id_status, u_id = database.find_ID(origin_mail) if id_status: status, msg = database.update(u_uuid, u_name, u_mail, u_password, u_pubkey, u_date, u_id) if status: return redirect(f'/searchKey.html?mail={u_mail}&msg=更改成功', 302) else: return redirect(f'/searchKey.html?mail={u_mail}&msg={msg}', 302) else: return redirect(f'/updateInfo.html?msg=停止你的黑客行为!', 302) else: return redirect(f'/updateInfo.html?msg=reCAPTCHA 令牌无效,请尝试刷新页面', 302) else: return redirect(f'/updateInfo.html?msg=reCAPTCHA 令牌未找到,停止你的黑客行为!', 302)
def searchKey(): u_mail = request.args['mail'] exist = database.is_exist(u_mail) if exist: status, data = database.find(u_mail) return {'status': status, 'data': data} else: return {'status': exist, 'data': '信息不存在'}
def oauth(): global user url = request.url text = re.sub('.*\?', '', url) params = parser(text) user = OAuth1Session(CK, CS, params['oauth_token'], params['oauth_verifier']) res = user.post('https://api.twitter.com/oauth/access_token', params) params = parser(res.text) AK, AS = params['oauth_token'], params['oauth_token_secret'] id_ = params['user_id'] user = OAuth1Session(CK, CS, AK, AS) if is_exist(id_): update_user(id_, AK, AS) else: insert_user(id_, AK, AS) return redirect(url_for('application'))
def verifyPassword(): if 'g-recaptcha-response' in request.args: g_recaptcha_response = request.args['g-recaptcha-response'] if recaptcha.verify(g_recaptcha_response): u_mail = request.args['mail'] u_password = request.args['password'] if database.is_exist(u_mail): d_status, d_password = database.query_password(u_mail) if d_status: if database.check_password( u_password, base64.b64decode(d_password).decode()): return {'status': True, 'data': '认证成功'} else: return {'status': False, 'data': '认证失败'} else: return {'status': False, 'data': '服务器错误'} else: return {'status': False, 'data': '邮箱不存在'} else: return errors.recaptcha_verify_failed else: return errors.recaptcha_not_found
def is_exist(): status = database.is_exist(request.args['mail']) return {'status': status}
def encode_url(url): if database.is_exist(url): return database.local_storage[url] new_url = create_short_url() return new_url