half baked tinder view
This commit is contained in:
parent
87c7e9c8ed
commit
455cbf921d
|
@ -2,25 +2,13 @@ from rest_framework.request import Request
|
||||||
|
|
||||||
from django.http import HttpResponseBadRequest, HttpResponse, JsonResponse, HttpRequest
|
from django.http import HttpResponseBadRequest, HttpResponse, JsonResponse, HttpRequest
|
||||||
|
|
||||||
import ipware as iplib
|
from .models import User, AuthToken
|
||||||
|
|
||||||
|
import ipware as iplib, time, requests, uuid
|
||||||
ipware = iplib.IpWare();
|
ipware = iplib.IpWare();
|
||||||
|
|
||||||
def client_ip(req: HttpRequest):
|
def client_ip(req: HttpRequest):
|
||||||
return ipware.get_client_ip(req)[0].exploded;
|
return ipware.get_client_ip(req.META)[0].exploded;
|
||||||
|
|
||||||
def VVSUAuthProxy(req: HttpRequest):
|
|
||||||
proxy = 'https://vvsu.ru/connect' + req.path[len('/api/auth/vvsu'):];
|
|
||||||
|
|
||||||
preq = requests.request(req.method, proxy, headers={
|
|
||||||
'User-Agent': 'OIDC Client / Pairent',
|
|
||||||
'Origin': 'http://pairent.vvsu.ru',
|
|
||||||
'Referer': 'http://pairent.vvsu.ru'
|
|
||||||
});
|
|
||||||
|
|
||||||
resp = HttpResponse(preq.content);
|
|
||||||
resp.headers['Content-Type'] = preq.headers['Content-Type'];
|
|
||||||
|
|
||||||
return resp;
|
|
||||||
|
|
||||||
def register(oid, provider_id, name):
|
def register(oid, provider_id, name):
|
||||||
user = User(
|
user = User(
|
||||||
|
@ -82,7 +70,7 @@ def verify_auth_token(key, ip):
|
||||||
token.delete();
|
token.delete();
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
if (token.expires > time.time()):
|
if (token.expires < time.time()):
|
||||||
token.delete();
|
token.delete();
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
|
@ -92,9 +80,26 @@ def auth_required(func):
|
||||||
"""
|
"""
|
||||||
Use authorization for this route.
|
Use authorization for this route.
|
||||||
"""
|
"""
|
||||||
def inner(req: HttpRequest):
|
def inner(req: HttpRequest, *args, **kwargs):
|
||||||
|
|
||||||
if ('Authorization' not in req.headers.keys()):
|
if ('Authorization' not in req.headers.keys()):
|
||||||
return JsonResponse({'error': 'no auth token'});
|
return JsonResponse({'error': 'no auth token'});
|
||||||
if (not verify_auth_token(req.headers['Authorization'], client_ip(req))):
|
if (not verify_auth_token(req.headers['Authorization'], client_ip(req))):
|
||||||
return JsonResponse({'error': 'auth token invalid or expired'});
|
return JsonResponse({'error': 'auth token invalid or expired'});
|
||||||
func();
|
func(req, *args, **kwargs);
|
||||||
|
|
||||||
|
return inner;
|
||||||
|
|
||||||
|
def rest_auth_required(func):
|
||||||
|
"""
|
||||||
|
Use authorization for this restframework view.
|
||||||
|
"""
|
||||||
|
def inner(self, req: HttpRequest, *args, **kwargs):
|
||||||
|
|
||||||
|
if ('Authorization' not in req.headers.keys()):
|
||||||
|
return JsonResponse({'error': 'no auth token'});
|
||||||
|
if (not verify_auth_token(req.headers['Authorization'], client_ip(req))):
|
||||||
|
return JsonResponse({'error': 'auth token invalid or expired'});
|
||||||
|
func(self, req, *args, **kwargs);
|
||||||
|
|
||||||
|
return inner;
|
|
@ -27,7 +27,8 @@ class Migration(migrations.Migration):
|
||||||
('tenth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на десятый вопрос')),
|
('tenth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на десятый вопрос')),
|
||||||
('eleventh_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на одиннадцатый вопрос')),
|
('eleventh_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на одиннадцатый вопрос')),
|
||||||
('twelfth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на двенадцатый вопрос')),
|
('twelfth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на двенадцатый вопрос')),
|
||||||
('users', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pairent_app.user', verbose_name='Пользователь')),
|
# ('users', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pairent_app.user', verbose_name='Пользователь')),
|
||||||
|
('user', models.BigIntegerField(verbose_name='ID Пользователя')),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
@ -28,7 +28,11 @@ class PsychTestAddResultSerializer(serializers.ModelSerializer):
|
||||||
class PublicUserSerializer(serializers.ModelSerializer):
|
class PublicUserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
exclude = ('favorites_apartments', 'comparison_apartments')
|
exclude = (
|
||||||
|
'favorites_apartments',
|
||||||
|
'comparison_apartments',
|
||||||
|
'openid_id',
|
||||||
|
)
|
||||||
|
|
||||||
class PsychTestReultsSerializer(serializers.ModelSerializer):
|
class PsychTestReultsSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -122,29 +122,17 @@ class PsychTestAddResultViewSet(viewsets.ViewSet):
|
||||||
|
|
||||||
|
|
||||||
class CompatibleUsersView(viewsets.ViewSet):
|
class CompatibleUsersView(viewsets.ViewSet):
|
||||||
|
@rest_auth_required
|
||||||
def list(self, req: Request):
|
def list(self, req: Request):
|
||||||
user_data = dict(req.data);
|
user_data = dict(req.data);
|
||||||
|
|
||||||
# TODO: Verify auth
|
token = AuthToken.objects.get(key=req.headers['authorization']);
|
||||||
vvsu_login = user_data['openid'];
|
|
||||||
|
|
||||||
# Exclude already viewed users
|
|
||||||
exclude = [];
|
|
||||||
if ('exclude' in user_data.keys()):
|
|
||||||
exclude = user_data['exclude'];
|
|
||||||
|
|
||||||
try:
|
this_user = User.objects.get(pk=token.user);
|
||||||
validate_email(vvsu_login);
|
|
||||||
except ValidationError:
|
|
||||||
return Request({'error': 'bad login'}, 400);
|
|
||||||
|
|
||||||
try:
|
|
||||||
this_user = User.objects.get(openid_addr=vvsu_login);
|
|
||||||
except User.DoesNotExist:
|
|
||||||
return Response({'error': 'user not found'}, 404);
|
|
||||||
|
|
||||||
|
answers_this_user = None;
|
||||||
try:
|
try:
|
||||||
answers_this_user = PsychTestReultsSerializer(PsychTestAnswers.objects.get(user=this_user)).dict;
|
answers_this_user = PsychTestReultsSerializer(PsychTestAnswers.objects.get(user=this_user.id)).dict;
|
||||||
except PsychTestAnswers.DoesNotExist:
|
except PsychTestAnswers.DoesNotExist:
|
||||||
return Response({'error': 'answers not found'}, 404);
|
return Response({'error': 'answers not found'}, 404);
|
||||||
|
|
||||||
|
@ -160,10 +148,6 @@ class CompatibleUsersView(viewsets.ViewSet):
|
||||||
if score / 12 * 100 > 30:
|
if score / 12 * 100 > 30:
|
||||||
users.append(UserSerializer(User.objects.get(pk=user_answers[0])).data)
|
users.append(UserSerializer(User.objects.get(pk=user_answers[0])).data)
|
||||||
|
|
||||||
# for user in users_query:
|
|
||||||
# if (abs(user.psych_test_result - score) < 20):
|
|
||||||
# users.append(PublicUserSerializer(user).data);
|
|
||||||
|
|
||||||
|
|
||||||
return Response(users);
|
return Response(users);
|
||||||
|
|
||||||
|
@ -257,3 +241,17 @@ class UserGet(APIView):
|
||||||
|
|
||||||
return JsonResponse(PublicUserSerializer(user).data);
|
return JsonResponse(PublicUserSerializer(user).data);
|
||||||
|
|
||||||
|
|
||||||
|
def VVSUAuthProxy(req: HttpRequest):
|
||||||
|
proxy = 'https://vvsu.ru/connect' + req.path[len('/api/auth/vvsu'):];
|
||||||
|
|
||||||
|
preq = requests.request(req.method, proxy, headers={
|
||||||
|
'User-Agent': 'OIDC Client / Pairent',
|
||||||
|
'Origin': 'http://pairent.vvsu.ru',
|
||||||
|
'Referer': 'http://pairent.vvsu.ru'
|
||||||
|
});
|
||||||
|
|
||||||
|
resp = HttpResponse(preq.content);
|
||||||
|
resp.headers['Content-Type'] = preq.headers['Content-Type'];
|
||||||
|
|
||||||
|
return resp;
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { IAPIObject } from "./IAPIObject";
|
||||||
|
import { Client } from './Client';
|
||||||
|
|
||||||
|
class Tinder extends IAPIObject {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Client} client Client to use to create requests
|
||||||
|
*/
|
||||||
|
constructor(client) {
|
||||||
|
super();
|
||||||
|
this.client = client;
|
||||||
|
this.viewed = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCompatible() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import axios from 'axios';
|
||||||
import constants from '../constants';
|
import constants from '../constants';
|
||||||
|
|
||||||
import { IAPIObject } from './IAPIObject';
|
import { IAPIObject } from './IAPIObject';
|
||||||
|
import { APIToken } from './APIToken';
|
||||||
|
|
||||||
const { API_ROOT, api_path } = constants;
|
const { API_ROOT, api_path } = constants;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue