Commit d21fc169 authored by Ayush Tiwari's avatar Ayush Tiwari

Added magics for authentication. Now new users can enter their credentials...

Added magics for authentication. Now new users can enter their credentials using %erp5_user {{username}} and %erp5_password {{password}}. Only after authentication will they be able to acces ERP5 and run their code from ERP5
parent 2adcddd1
......@@ -120,7 +120,7 @@ service = $${:etc}/service
promise = $${:etc}/promise/
log = $${:var}/log
notebook_dir = $${:var}/notebooks
ipython_dir = $${:home}/.ipython
ipython_dir = $${:home}/ipython
ipython_kernel_dir = $${:ipython_dir}/kernels
erp5_kernel_dir = $${:ipython_kernel_dir}/ERP5
......
......@@ -55,7 +55,7 @@ output = ${buildout:directory}/instance.cfg
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
download-only = true
md5sum = 460206edb2fc6b21e065b6cbd1475f1a
md5sum = c74ced2f5e20f5509a3aca8d00952499
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = ERP5kernel.py.jinja
mode = 0644
......
#!{{python_executable}}
from IPython.kernel.zmq.kernelbase import Kernel
from IPython.display import display_javascript
from IPython.core.display import HTML
import requests
import logging
class ERP5Kernel(Kernel):
implementation = 'ERP5'
implementation_version = '1.0'
......@@ -12,19 +14,56 @@ class ERP5Kernel(Kernel):
language_info = {'mimetype': 'text/plain', 'name':'python'}
banner = "ERP5 integration with ipython notebook"
def __init__(self, user=None, pwd=None, url=None, status_code=None, *args, **kwargs):
super(ERP5Kernel, self).__init__(*args, **kwargs)
self.user = user
self.pwd = pwd
self.url = url
self.status_code = status_code
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
if not silent:
import requests
res = requests.get('https://zope:insecure@softinst60318.host.vifib.net/erp5/data_set_module/wendelin_1/Base_executePython', verify=False, params={'python_expression': code})
code_result = res.text
if code.startswith('%erp5_user'):
self.user = code.split()[1]
resp = 'Your erp5 username is %s' %self.user
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
data = {
'data': {'text/html': code_result},
'metadata': {}
}
self.send_response(self.iopub_socket, 'display_data', data)
elif code.startswith('%erp5_password'):
self.pwd = code.split()[1]
self.url = 'softinst60318.host.vifib.net/erp5/manage_main'
if self.user:
url = 'https://%s:%s@%s' %(self.user, self.pwd, self.url)
try:
res = requests.get(url, verify=False)
self.status_code = res.status_code
if self.status_code != 200:
resp = 'Incorrect username or password'
else:
resp = 'Please proceed'
except requests.exceptions.RequestException as e:
resp = e
else:
resp = 'Please enter your username in next cell'
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
else:
if self.status_code == 200:
url = 'https://%s:%s@softinst60318.host.vifib.net/erp5/data_set_module/wendelin_1/Base_executePython' %(self.user, self.pwd)
res = requests.get(url, verify=False, params={'python_expression': code})
code_result = res.text
else:
code_result = 'Unauthorized access'
data = {
'data': {'text/html': code_result},
'metadata': {}
}
self.send_response(self.iopub_socket, 'display_data', data)
return {'status': 'ok',
# The base class increments the execution count
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment