Exemple #1
0
def get_user_reservations(username):
    l_reservations = []
    users = User.objects(username=username)
    if len(users) == 0:
        return jsonify({"msg": "未知用户"}), 404
    reservations = Reservation.objects(owner=users[0])
    for r in reservations:
        l_reservations.append(r.get_dict())
    return jsonify(l_reservations), 200
Exemple #2
0
 def setUpClass(self):
     u = User.objects(username="******", password="******")
     if len(u) > 0:
         u.delete()
     u = User()
     u.username = "******"
     u.password = "******"
     u.save()
     self.user = u
     now = datetime.datetime.now()
     r = Reservation.get_between(now, now + datetime.timedelta(days=1))
     r.delete()
Exemple #3
0
def register_user():
    data = request.get_data()
    data = json.loads(data)
    username = data['username']
    password = data['password']
    users = User.objects(username=username, password=password)
    if len(users) > 0:
        return jsonify({'id': -1}), 409
    else:
        user = User()
        user.username = username
        user.password = password
        user.privilege = 0
        user.save()
        return jsonify(user.get_dict()), 201
Exemple #4
0
def oauth_callback():
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = VkSignIn()
    social_id, name, image_url, friends_count = oauth.callback()
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('index'))
    user = User.objects(social_id=social_id).first()
    if not user:
        user = User(social_id=social_id, ).save()
    login_user(user, True)
    values = {
        'name': name,
        'friends_count': friends_count,
        'image_url': image_url,
    }
    session.update(values)
    return redirect(url_for('index'))
Exemple #5
0
def load_user(id):
    return User.objects(pk=id).first()
Exemple #6
0
 def test_step2_check_reservation(self):
     reservations = self.user.reservations
     User.objects(username="******")[0].delete()
     self.assertEqual(len(Reservation.objects()), 0)
Exemple #7
0
def delete_user(username):
    user = User.objects(username=username)
    if len(user) == 0:
        return jsonify({'status': -1}), 404
    user.delete()
    return jsonify({'status': 0}), 204