# limitations under the License.
#
from .models import OsmUser
-
+from lib.osm.osmclient.clientv2 import Client
class OsmBackend(object):
password = kwargs['password']
project_id = kwargs['project_id']
- print username
- print password
- print project_id
+ client = Client()
+ result = client.auth(kwargs)
+ print "######"
+ print result
+
+ if 'error' in result and result['error'] == True:
+ return None
+ else:
+
+ try:
+ user = OsmUser.objects.get(username=username)
- try:
+ except OsmUser.DoesNotExist:
+ # Create a new user. There's no need to set a password
+ # we will keep just some preferences
+ user = OsmUser(username=username)
- return OsmUser.objects.get(username=username)
- except OsmUser.DoesNotExist:
- # Create a new user. There's no need to set a password
- # we will keep just some preferences
- user = OsmUser(username=username)
- user.save()
+ user.save()
+ user.session = result['data']
return user
return None
user = authenticate(username=request.POST.get('username'),
password=request.POST.get('password'),
project_id=request.POST.get('project_id'))
-
if user and user.is_active:
if user.is_authenticated():
login(request, user)
return HttpResponseRedirect(next_page)
else:
error_message = 'Login failed!'
- return render(request, 'login.html', {'error_message':error_message, 'collapsed_sidebar': False})
+ return render(request, 'login.html', {'error_message': error_message, 'collapsed_sidebar': False})
class Client(object):
- def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', ro_host=None, ro_port=9090, **kwargs):
+ def __init__(self, host=os.getenv('OSM_SERVER', "192.168.100.199"), so_port=9999, so_project='admin', ro_host=None, ro_port=9090, **kwargs):
self._user = 'admin'
self._password = 'admin'
--- /dev/null
+import requests
+import logging
+import json
+import tarfile
+import yaml
+import pyaml
+import StringIO
+from lib.util import Util
+import hashlib
+import os
+
+logging.basicConfig(level=logging.DEBUG)
+log = logging.getLogger('helper.py')
+
+
+class Client(object):
+ def __init__(self):
+ self._token_endpoint = 'admin/v1/tokens'
+ self._user_endpoint = 'admin/v1/users'
+ self._host = os.getenv('OSM_SERVER', "192.168.1.73")
+ self._so_port = 9999
+ self._base_path = "https://{0}:{1}/osm".format(self._host, self._so_port)
+
+ def auth(self, args):
+ result = {'error': True, 'data': ''}
+ token_url = "{0}/{1}".format(self._base_path, self._token_endpoint)
+ headers = {"Content-Type": "application/yaml", "accept": "application/json"}
+ try:
+ r = requests.post(token_url, json=args, verify=False, headers=headers)
+ except Exception as e:
+ print "saltata"
+ log.exception(e)
+ result['data'] = str(e)
+ return result
+ if r.status_code == requests.codes.ok:
+ result['error'] = False
+
+ result['data'] = Util.json_loads_byteified(r.text)
+
+ return result
+
from django.shortcuts import render, redirect
from lib.util import Util
from projecthandler.osm_model import OsmProject
-from lib.osm.osmclient.client import Client
+from lib.osm.osmclient.clientv2 import Client
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
- 'sf_user',
+ 'django.contrib.sessions',
'authosm',
'projecthandler',
'vimhandler',
]
-SESSION_ENGINE='sf_user.sessions'
+SESSION_ENGINE ='django.contrib.sessions.backends.db'
SESSION_COOKIE_AGE = 3500 #25 min
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_SAVE_EVERY_REQUEST = True
3. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import url, include
-from sf_user import views as user_views
+#from sf_user import views as user_views
from authosm import views as user_views
from sf_t3d import views
# limitations under the License.
#
-from django.contrib.sessions.backends.db import SessionStore as DBStore
-import sf_user
-
-class SessionStore(DBStore):
- @classmethod
- def get_model_class(cls):
- return sf_user.models.CustomSession
-
- def create_model_instance(self, data):
- obj = super(SessionStore, self).create_model_instance(data)
- try:
- account_id = int(data.get('_auth_user_id'))
- except (ValueError, TypeError):
- account_id = None
- obj.account_id = account_id
- return obj
\ No newline at end of file
+# from django.contrib.sessions.backends.db import SessionStore as DBStore
+# import sf_user
+#
+# class SessionStore(DBStore):
+# @classmethod
+# def get_model_class(cls):
+# return sf_user.models.CustomSession
+#
+# def create_model_instance(self, data):
+# obj = super(SessionStore, self).create_model_instance(data)
+# try:
+# account_id = int(data.get('_auth_user_id'))
+# except (ValueError, TypeError):
+# account_id = None
+# obj.account_id = account_id
+# return obj
\ No newline at end of file
<input id="next_input" type="hidden" name="next" class="form-control">
{% csrf_token %}
<div class="form-group has-feedback">
- <input type="username" name="username" class="form-control" placeholder="Username">
+ <input type="username" name="username" class="form-control" placeholder="Username" required>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
- <input type="password" name="password" class="form-control" placeholder="Password">
+ <input type="password" name="password" class="form-control" placeholder="Password" required>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">