def post(self): data = request.get_json(force=True) old_pass = convert_to_md5(data.get('old_pass')) new_pass = convert_to_md5(data.get('new_pass')) user_info = User.query.fileter_by(uid=g.uid).first() if old_pass != user_info.password: return {'code': 50008, 'message': '原密码不对'} user_info.password = new_pass db.session.commit() return {'code': 20000}
def post(self): parse = reqparse.RequestParser() parse.add_argument('username', type=str, required=True) parse.add_argument('password', type=str, required=True) args = parse.parse_args() # 查询是否为已注册用户 user_info_check = User.query.filter_by(username=args.username).first() if not user_info_check: return {'code': 20001, 'message': '不存在该用户'} if user_info_check.password != args.password: return {'code': 20001, 'message': '密码错误'} # 加密信息获取token token = convert_to_md5('{0}true{1}false{2}'.format( args.username, args.password, str(time.time()))) # 将信息写入redis redis.set(token, { 'uid': user_info_check.uid, 'username': user_info_check.username }) return {'code': 20000, 'data': {'token': token}}
def initdata(): fake = Faker('zh_CN') # 插入用户信息 for _ in range(10): new_user = User(username=fake.name(), password=convert_to_md5('adminadmin')) db.session.add(new_user) db.session.commit()
def post(self): parse = reqparse.RequestParser() parse.add_argument('old_pass', type=str, required=True) parse.add_argument('new_pass', type=str, required=True) args = parse.parse_args() old_pass = convert_to_md5(args.old_pass) new_pass = convert_to_md5(args.new_pass) user_info = User.query.fileter_by(uid=g.uid).first() if old_pass != user_info.password: return {'code': 50008, 'message': '原密码不对'} user_info.password = new_pass db.session.commit() return {'code': 20000}
def initdata(): fake = Faker('zh_CN') # 插入用户信息 for _ in range(10): new_user = User(username=fake.name(), password=convert_to_md5('adminadmin')) db.session.add(new_user) for i in range(10): new_article = Article(title='title{}'.format(i), content='content{}'.format(i), author_id=1) db.session.add(new_article) db.session.commit()