def post(self): id = str(uuid.uuid4()) username = request.json.get('username') password = request.json.get('password') email = request.json.get('email') user = LocalAuth.query.filter_by(username=username).first() user_mail = LocalAuth.query.filter_by(email=email).first() if user != None: return make_response(201, message='该用户名已被注册') elif user_mail != None: return make_response(201, message='该邮箱已被注册') else: user_local_auth = LocalAuth(id=id, username=username, password=password, email=email) user_profile = Profile(id=id, username=username, email=email) db.session.add(user_local_auth) db.session.add(user_profile) db.session.commit() token = user_profile.generate_confirmation_token() send_mail(user_local_auth.email, 'Confirm Your Account', 'auth/email/confirm', user=user_profile, token=token) return make_response(data=token)
def get(self): user = LocalAuth.confirm(self.args.get('token')) if user != None: url_for('auth.ResetPwdPage') print('tiaozhuan') else: return make_response(Code.BAD_REQUEST, message='该用户不存在') return make_response(Code.OK)
def post(self): username = request.json.get('username') password = request.json.get('password') user = LocalAuth.query.filter_by(username=username).first() if user is not None and user.password == password: login_user(user) return make_response() elif user is not None and user.password != password: return make_response(Code.BAD_REQUEST, message='密码错误') elif user is None: return make_response(Code.BAD_REQUEST, message='该用户未注册')
def get(self): user = Profile.confirm(self.args.get('token')) user_profile = Profile.query.filter_by(username=user.username).first() user_profile.confirmed = True db.session.add(user_profile) db.session.commit() return make_response(Code.OK, data=user_profile.confirmed)
def put(self): username = request.json.get('username') new_password = request.json.get('new_password') user_local_auth = LocalAuth.query.filter_by(username=username).first() user_local_auth.password = new_password db.session.add(user_local_auth) db.session.commit() return make_response()
def put(self): username = request.json.get('username') password = request.json.get('new_password') user = LocalAuth.query.filter_by(username=username).first() user.password = password db.session.add(user) db.session.commit() return make_response(Code.OK, message='change password success')
def get(self): user_local_auth = LocalAuth.confirm(self.args.get('token')) user_profile = Profile.query.filter_by(id=user_local_auth.id).first() user_local_auth.email = new_email user_profile.email = new_email db.session.add(user_local_auth) db.session.add(user_profile) db.session.commit() return make_response(Code.OK, message='修改邮箱成功')
def post(self): username = request.json.get('username') email = request.json.get('email') new_email = request.json.get('new_email') global new_email user = LocalAuth.query.filter_by(username=username).first() token = user.generate_reset_token() send_mail(new_email,'Change Your Email','auth/email/reset_email', \ user=user, token=token, next=request.args.get('next')) return make_response()
def post(self): email = request.json.get('email') user = LocalAuth.query.filter_by(email=email).first() print(user) if user: token = user.generate_reset_token() print(token) send_mail(user.email, 'Reset Your Password', 'auth/email/reset_password', \ user=user, token=token, next=request.args.get('next')) return make_response()
def post(self): page = request.json.get('page') page = int(page) query = Articles.query pagination = query.order_by().paginate( page, per_page=current_app.config['FLASK_POSTS_PER_PAGE'], error_out=False) posts = pagination.items # print(posts) resp = [item.to_json() for item in posts] return make_response(data=resp)
def post(self): id = str(uuid.uuid4()) title = request.json.get('title') content = request.json.get('content') body_html = request.json.get('body_html') user_id = '56defb16-2512-4b8f-aab8-72897fe13ef7' article = Articles(uuid=id, title=title, content=content, body_html=body_html, author_id=user_id) db.session.add(article) db.session.commit() return make_response()
def get(self): logout_user() return make_response()
def get(self): a = 'hello,world' return make_response(Code.OK, data=a)
def get(self): query = Articles.query.order_by(Articles.create_time.desc()).all() resp = [item.to_json() for item in query] return make_response(data=resp)