# Path: applications/utils.py
# def generate_session_id():
#     """
#     Returns a random, 45-character session ID.  Example:
# 
#     .. code-block:: python
# 
#         >>> generate_session_id()
#         "NzY4YzFmNDdhMTM1NDg3Y2FkZmZkMWJmYjYzNjBjM2Y5O"
#         >>>
#     """
#     import base64, uuid
#     from applications.configuration import utf8
#     session_id = base64.b64encode(
#         utf8(uuid.uuid4().hex + uuid.uuid4().hex))[:45]
#     if bytes != str: # Python 3
#         return str(session_id, 'UTF-8')
#     return session_id
# 
# def mkdir_p(path):
#     """
#     Pythonic version of "mkdir -p".  Example equivalents::
# 
#         >>> mkdir_p('/tmp/test/testing') # Does the same thing as...
#         >>> from subprocess import call
#         >>> call('mkdir -p /tmp/test/testing')
# 
#     .. note:: This doesn't actually call any external commands.
#     """
#     try:
#         os.makedirs(path)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST:
#             pass
#         else:
#             logging.error(_("Could not create directory: %s") % path)
#             raise # The original exception
# 
# Path: applications/utils.py
# def getsettings(name,default=None):
#     return getattr(settings, name, default)


from django.shortcuts import render,HttpResponse,Http404
from django.views.generic import View
from django.shortcuts import render_to_response,HttpResponseRedirect,reverse,redirect
from applications.utils import generate_session_id,mkdir_p
from django.core import signing #encrypted the strings
from django.contrib.auth.views import login,logout
from applications.utils import getsettings
import os
import ast
import tornado
import io
import datetime
import hashlib
        import stat, mimetypes
            import email.utils
        import httplib
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


# Create your views here.

class basehttphander(View):
    def user_login(self,request):
        self.request.session.clear_expired()
        if self.request.META.has_key('HTTP_X_FORWARDED_FOR'):  
            ip = self.request.META['HTTP_X_FORWARDED_FOR']
        else:  
            ip = self.request.META['REMOTE_ADDR']
        user = {u'upn': str(self.request.user), u'ip_address': ip}        
        user_dir = os.path.join(getsettings('BASE_DIR'),'users')
        user_dir = os.path.join(user_dir, user['upn'])
        if not os.path.exists(user_dir):
            mkdir_p(user_dir)
            os.chmod(user_dir, 0o700)
        if not self.request.session.get('session',None):
            session_info = {

# Path: applications/utils.py
# def generate_session_id():
#     """
#     Returns a random, 45-character session ID.  Example:
# 
#     .. code-block:: python
# 
#         >>> generate_session_id()
#         "NzY4YzFmNDdhMTM1NDg3Y2FkZmZkMWJmYjYzNjBjM2Y5O"
#         >>>
#     """
#     import base64, uuid
#     from applications.configuration import utf8
#     session_id = base64.b64encode(
#         utf8(uuid.uuid4().hex + uuid.uuid4().hex))[:45]
#     if bytes != str: # Python 3
#         return str(session_id, 'UTF-8')
#     return session_id
# 
# def mkdir_p(path):
#     """
#     Pythonic version of "mkdir -p".  Example equivalents::
# 
#         >>> mkdir_p('/tmp/test/testing') # Does the same thing as...
#         >>> from subprocess import call
#         >>> call('mkdir -p /tmp/test/testing')
# 
#     .. note:: This doesn't actually call any external commands.
#     """
#     try:
#         os.makedirs(path)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST:
#             pass
#         else:
#             logging.error(_("Could not create directory: %s") % path)
#             raise # The original exception
# 
# Path: applications/utils.py
# def getsettings(name,default=None):
#     return getattr(settings, name, default)


# Path: applications/views.py
from django.shortcuts import render,HttpResponse,Http404
from django.views.generic import View
from django.shortcuts import render_to_response,HttpResponseRedirect,reverse,redirect
from applications.utils import generate_session_id,mkdir_p
from django.core import signing #encrypted the strings
from django.contrib.auth.views import login,logout
from applications.utils import getsettings
import os
import ast
import tornado
import io
import datetime
import hashlib
        import stat, mimetypes
            import email.utils
        import httplib

# -*- coding: utf-8 -*-
from __future__ import unicode_literals


# Create your views here.

class basehttphander(View):
    def user_login(self,request):
        self.request.session.clear_expired()
        if self.request.META.has_key('HTTP_X_FORWARDED_FOR'):  
            ip = self.request.META['HTTP_X_FORWARDED_FOR']
        else:  
            ip = self.request.META['REMOTE_ADDR']
        user = {u'upn': str(self.request.user), u'ip_address': ip}        
        user_dir = os.path.join(getsettings('BASE_DIR'),'users')
        user_dir = os.path.join(user_dir, user['upn'])
        if not os.path.exists(user_dir):
            mkdir_p(user_dir)
            os.chmod(user_dir, 0o700)
        if not self.request.session.get('session',None):
            session_info = {

                'session': generate_session_id()