don't use PhantomJS when using archimed ws (#14967)

This commit is contained in:
Josue Kouka 2017-02-14 17:14:08 +01:00
parent 5bc4ca8e75
commit ab720fc59b
5 changed files with 568 additions and 36 deletions

View File

@ -28,8 +28,8 @@ urlpatterns = patterns('',
url(r'^_mandaye/post-login/$', 'mandayejs.mandaye.views.post_login', name='post-login'),
url(r'^_mandaye/post-login-do/$', 'mandayejs.mandaye.views.post_login_do', name='post-login-do'),
url(r'^_mandaye/admin/', include(admin.site.urls)),
url(r'^_mandaye/ws/(?P<path>.*)$', app_web_services),
url(r'^_mandaye/api/','mandayejs.mandaye.api.api', name='api')
url(r'^_mandaye/ws/(?P<path>.*)$', app_web_services, name='app-web-services'),
url(r'^_mandaye/api/', 'mandayejs.mandaye.api.api', name='api')
)
if 'mellon' in settings.INSTALLED_APPS:
@ -37,4 +37,3 @@ if 'mellon' in settings.INSTALLED_APPS:
url(r'^_mandaye/logout/$', 'mandayejs.mandaye.views.logout', name='logout'),
url(r'^_mandaye/accounts/mellon/', include('mellon.urls')),
)

View File

@ -18,8 +18,6 @@ from __future__ import absolute_import
import logging
import requests
from pprint import pprint
from requests.cookies import RequestsCookieJar
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
@ -29,7 +27,6 @@ from rest_framework.views import APIView
from rest_framework.response import Response
from mandayejs.mandaye.models import UserCredentials
from mandayejs.mandaye.utils import exec_phantom, get_login_info
from mandayejs.applications import get_app_settings
@ -40,43 +37,31 @@ class ArchimedAccountDetails(APIView):
def get(self, request, *args, **kwargs):
logger = logging.getLogger(__name__)
app_settings = get_app_settings()
ws_uri = app_settings.SITE_WS_ENDPOINT['account_details']
ws_uri = request.build_absolute_uri(
app_settings.SITE_WS_ENDPOINT['account_details'])
username = kwargs['username']
user = get_object_or_404(User, username=username)
credentials = get_object_or_404(UserCredentials, user=user)
login_info = get_login_info(request, credentials)
logger.debug(login_info)
login_info['locators'] = [credentials.to_login_info(decrypt=True)]
result = exec_phantom(login_info)
login_url = request.build_absolute_uri(
'/DEFAULT/Ermes/Recherche/logon.svc/logon')
if result.get('result') != 'ok':
return Response(status=status.HTTP_401_UNAUTHORIZED)
with requests.Session() as session:
login_info = credentials.to_login_info(decrypt=True)
login_info = {'username': login_info['#carte'], 'password': login_info['#code']}
response = session.post(login_url, data=login_info)
logger.debug("Archimed login response {}".format(response.json()))
if not response.json()['success']:
return Response('Authentication failed', status=status.HTTP_401_UNAUTHORIZED)
session = requests.session()
r_cookies = RequestsCookieJar()
content = {
'codeConfig': '',
'xslPath': 'Services/LectorShortAccount.xslt'
}
response = session.post(ws_uri, json=content)
logger.debug("Archimed ws response {}".format(response.json()))
return Response(response.json())
for cookie in result.get('cookies'):
r_cookies.set(
cookie['name'],
cookie['value'],
domain=cookie['domain'],
path=cookie['path'],
secure=cookie['secure']
)
session.cookies = r_cookies
headers = {
'Content-Type': 'application/json',
}
content = '{"codeConfig":"", "xslPath":"Services/LectorShortAccount.xslt"}'
url = request.build_absolute_uri(ws_uri)
logger.debug(url)
request_response = session.post(url, headers=headers, data=content, verify=False)
data = request_response.json()
logger.debug(pprint(data))
return Response(data)
archimed_account_details = ArchimedAccountDetails.as_view()

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,18 @@
{
"d": "Anonymous",
"errors": [
{
"data": {
"__type": "ObjectCollection:#Archimed.Serialization",
"badPasswordCount": 0,
"checkAdditionalsResult": true,
"doCheckAdditionals": true
},
"id": "CF30AuthenticationProvider",
"msg": "L'utilisateur sp\u00e9cifi\u00e9 est introuvable, v\u00e9rifiez la syntaxe et r\u00e9essayez.",
"type": "UserNotFound"
}
],
"message": "",
"success": false
}

View File

@ -0,0 +1,6 @@
{
"d": "1432555",
"errors": [],
"message": "",
"success": true
}