示例#1
0
 def test_user_token_auth(self):
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******')
     auth_token = user.generate_auth_token()
     invalid_token = ""
     assert User.verify_auth_token(invalid_token) is None
     assert User.verify_auth_token(auth_token) is user
示例#2
0
文件: api.py 项目: etaylork/NextBeer
 def get(self):
     args = recommend_get_parse.parse_args()
     user = User.verify_auth_token(args.access_token)
     if user:
         return make_beers_arr(user.ratings), 200
     else:
         return None, 401
示例#3
0
文件: api.py 项目: etaylork/NextBeer
 def get(self):
     args = recommend_get_parse.parse_args()
     user = User.verify_auth_token(args.access_token)
     if user:
         return {"username": user.username,
                 "taste_profile": user.get_profile(),
                 "initial_profile": user.get_taste_profile(),
                 "ratings": make_beers_arr(user.ratings)}
示例#4
0
文件: api.py 项目: etaylork/NextBeer
 def get(self):
     args = recommend_get_parse.parse_args()
     user = User.verify_auth_token(args.access_token)
     if user:
         #lol for now
         beer = user.reccommend()
         return beer.to_data()
     else:
         return None, 401
示例#5
0
文件: api.py 项目: etaylork/NextBeer
 def get(self):
     profile_get_parser = reqparse.RequestParser()
     profile_get_parser.add_argument('access_token', dest='access_token',
                             type=str, required=True,
                             help='Access token of user profile')
     args = profile_get_parser.parse_args()
     user = User.verify_auth_token(args.access_token)
     if user:
         return user.get_taste_profile(), 201
     else:
         return None, 400
示例#6
0
文件: api.py 项目: etaylork/NextBeer
 def post(self):
     args = rate_post_parser.parse_args()
     user = User.verify_auth_token(args.access_token)
     rating_val = args.rating
     beer_id = args.beer_id
     if user:
         rating = Rating.query.filter(Rating.user_id == user.id, Rating.beer_id == beer_id).first()
         if rating:
             rating = rating.update_time(beer_id=beer_id, user_id=user.id, rating=rating_val)
         else:
             rating = Rating.create(beer_id=beer_id, user_id=user.id, rating=rating_val)
         return rating.id, 201
     else:
         return None, 401
示例#7
0
文件: api.py 项目: etaylork/NextBeer
 def post(self):
     args = profile_set_parser.parse_args()
     user = User.verify_auth_token(args.access_token)
     if user:
         print(args)
         print(user.taste_profile)
         user.update_taste_profile(malty=args.malty, sour=args.sour, wood=args.wood,
                                   spice=args.spice, fruit=args.fruit, sweet=args.sweet,
                                   roasty=args.roasty, bitter=args.bitter, smoke=args.smoke,
                                   hoppy=args.hoppy)
         print(user.taste_profile)
         return user.get_taste_profile(), 201
     else:
         return None, 400
示例#8
0
文件: api.py 项目: etaylork/NextBeer
 def get(self):
     args = recommend_get_parse.parse_args()
     user = User.verify_auth_token(args.access_token)
     x = grab_matching_ratings(user, lambda x: x < 3)
     return {'beers': x, 'total': len(x)}