Exemple #1
0
def splash(request):
    if request.user.is_authenticated():
        return shortcuts.redirect(horizon.get_user_home(request.user))
    form = views.Login(request)
    request.session.clear()
    request.session.set_test_cookie()
    return shortcuts.render(request, 'splash.html', {'form': form})
Exemple #2
0
def splash(request):
    LOG.info(request.__dict__)
    LOG.info("In splash function")
    LOG.info(request.user)
    LOG.info('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4')
    if not request.user.is_authenticated():
        LOG.info("User not autenticated ")
        raise exceptions.NotAuthenticated()

    if TWO_FACTOR_ENABLED:

        #check whether otp page is shown, if not show.
        if not 'otp_shown' in request.session:
            LOG.info('otp_shown is not present in the session')
            response = shortcuts.redirect('/dashboard/otp')
        else:
            LOG.info('otp_shown value is present in session')
            if not request.session['otp_shown']:
                LOG.info('enter-1')
                response = shortcuts.redirect('/dashboard/otp')
        response = shortcuts.redirect('/dashboard/otp')
    else:
        print "npoooooooooooooooooooooo"
        response = shortcuts.redirect(horizon.get_user_home(request.user))

    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    #response.delete_cookie('sessionid')
    LOG.info('response returned')
    LOG.info('++++++++++++++++++++++++++++')
    LOG.info(response)

    return response
Exemple #3
0
def splash(request):
    LOG.info(request.__dict__)
    LOG.info("In splash function")
    LOG.info(request.user)
    LOG.info('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4')
    if not request.user.is_authenticated():
        LOG.info("User not autenticated ")
        raise exceptions.NotAuthenticated()

    user_id = api.keystone.get_user_id(request)
    print "USER CHECK"

    #LOG.info(user_info)
    #LOG.info('############################################')
    #LOG.info(user_info.two_factor_enabled)
    #two_factor_enabled = user_info.two_factor_enabled
    #two_factor_enabled = str2bool(two_factor_enabled)
    LOG.info('##############################################')
    user_details = api.keystone.user_details(request, user_id)

    if user_details.two_factor_enabled:
        two_factor_enabled = str2bool(two_factor_enabled)
    else:
        two_factor_enabled = False

    print user_details.two_factor_enabled
    print '%%%%%%%%%%%%%%%%%%%%%%%%%'
    print two_factor_enabled
    print('after tested')

    #Login case
    if two_factor_enabled:

        #Check whether 2factor page is shown. If else show it
        if not 'totp_shown' in request.session:
            LOG.info('totp_shown is not present in the session')
            #response = shortcuts.redirect('/dashboard/otp')
            LOG.info('redirecting to 2 factor form display page')
            response = shortcuts.redirect('/dashboard/twofactor')
        else:
            LOG.info('totp_shown value is present in session')
            if not request.session['totp_shown']:
                LOG.info(
                    'since totp_shown value is not present inside the request.session'
                )
                LOG.info('redirecting users to twofactor form display page')
                response = shortcuts.redirect('/dashboard/twofactor')
        LOG.info('default condition to redirect the users to two factor page')
        response = shortcuts.redirect('/dashboard/twofactor')
    else:
        print "Redirecting users to their home page/dashboard since 2FA isn't enabled"
        response = shortcuts.redirect(horizon.get_user_home(request.user))

    #Logout case
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')

    #Return the response corresponding to all above conditions
    return response
Exemple #4
0
def splash(request):
    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()

    response = shortcuts.redirect(horizon.get_user_home(request.user))
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
Exemple #5
0
def splash(request):
    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()

    response = shortcuts.redirect(horizon.get_user_home(request.user))
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
Exemple #6
0
def splash(request):
    if request.user.is_authenticated():
        response = shortcuts.redirect(horizon.get_user_home(request.user))
    else:
        form = forms.Login(request)
        response = shortcuts.render(request, 'auth/login.html', {'form': form})
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
Exemple #7
0
def user_home(request):
    """Reversible named view to direct a user to the appropriate homepage."""
    #return shortcuts.redirect(horizon.get_user_home(request.user))

    print('Entering user_home function')
    print('otp_valid check')
    # Allow only if otp validation is success
    if "otp_valid" in request.session:
        if request.session['otp_valid']:
            return shortcuts.redirect(horizon.get_user_home(request.user))

    # Allow only if otp validation is success
    if "totp_valid" in request.session:
        print "i am here in totp_valid check of user_home directory"
        if request.session['totp_valid']:
            return shortcuts.redirect(horizon.get_user_home(request.user))

    return shortcuts.redirect("/dashboard/otp")
Exemple #8
0
def splash(request):
    if request.user.is_authenticated():
        response = shortcuts.redirect(horizon.get_user_home(request.user))
    else:
        form = forms.Login(request)
        response = shortcuts.render(request, 'splash.html', {'form': form})
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
Exemple #9
0
def splash(request):
    if request.user.is_authenticated():
        response = shortcuts.redirect(horizon.get_user_home(request.user))
    else:
        form = forms.Login(request)
        request.session.clear()
        request.session.set_test_cookie()
        response = shortcuts.render(request, 'splash.html', {'form': form})
    response.delete_cookie('logout_reason')
    return response
Exemple #10
0
def splash(request, template_name=None):
    if request.user.is_authenticated():
        response = shortcuts.redirect(horizon.get_user_home(request.user))
    else:
        # form = forms.Login(request)
        form = fiware_auth_forms.LoginWithEmailForm()
        if not template_name:
            template_name = 'splash.html'
        response = shortcuts.render(request, template_name, {'form': form})
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
def splash(request, template_name=None):
    if request.user.is_authenticated():
        response = shortcuts.redirect(horizon.get_user_home(request.user))
    else:
        # form = forms.Login(request)
        form = fiware_auth_forms.LoginWithEmailForm()
        if not template_name:
            template_name = 'splash.html'
        response = shortcuts.render(request, template_name, {'form': form})
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    return response
Exemple #12
0
def splash(request):
    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()

    response = shortcuts.redirect(horizon.get_user_home(request.user))
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    # Display Message of the Day message from the message files
    # located in MESSAGES_PATH
    if MESSAGES_PATH:
        notifications.process_message_notification(request, MESSAGES_PATH)
    return response
Exemple #13
0
def splash(request):
    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()

    response = shortcuts.redirect(horizon.get_user_home(request.user))
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    # Display Message of the Day message from the message files
    # located in MESSAGES_PATH
    if MESSAGES_PATH:
        notifications.process_message_notification(request, MESSAGES_PATH)
    return response
Exemple #14
0
def splash(request):
    brand = request.GET.get('brand')
    if brand:
        # store brand id and reload splash page
        return set_brand(shortcuts.redirect('/'), brand)

    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()

    response = shortcuts.redirect(horizon.get_user_home(request.user))
    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    set_brand(response, get_brand(request))
    return response
Exemple #15
0
        def wrapped_function(view, *args, **kwargs):

            try:
                return function(view, *args, **kwargs)
            except Exception as error:
                LOG.error(error.message)
                namespace = "horizon:disaster_recovery:"
                r = reverse("{0}{1}".format(namespace, redirect))

                if view.request.path == r:
                    # To avoid an endless loop, we must not redirect to the
                    # same page on which the error happened
                    user_home = get_user_home(view.request.user)
                    exceptions.handle(view.request, _(message),
                                      redirect=user_home)
                else:
                    exceptions.handle(view.request, _(message), redirect=r)
Exemple #16
0
        def wrapped_function(view, *args, **kwargs):

            try:
                return function(view, *args, **kwargs)
            except Exception as error:
                LOG.error(error.message)
                namespace = "horizon:disaster_recovery:"
                r = reverse("{0}{1}".format(namespace, redirect))

                if view.request.path == r:
                    # To avoid an endless loop, we must not redirect to the
                    # same page on which the error happened
                    user_home = get_user_home(view.request.user)
                    exceptions.handle(view.request, _(error.message),
                                      redirect=user_home)
                else:
                    exceptions.handle(view.request, _(error.message),
                                      redirect=r)
def splash(request):
    #LOG.info("xxx enter splash!")
    #LOG.info("request is")
    #LOG.info(request)

    if not request.user.is_authenticated():
        raise exceptions.NotAuthenticated()
    '''url = "sunny"

    context = {
        'url': url,
    }'''
    '''if not request.user.is_authenticated():
    return shortcuts.render(request, 'index.html',
                        status=200)'''

    #LOG.info("request.user")
    #LOG.info(request.user)

    #LOG.info("horizon.get_user_home(request.user)")
    #LOG.info(horizon.get_user_home(request.user))

    response = shortcuts.redirect(horizon.get_user_home(request.user))

    #LOG.info("request.user")
    #LOG.info(request.user)

    #LOG.info("horizon.get_user_home(request.user)")
    #LOG.info(horizon.get_user_home(request.user))

    #LOG.info("response")
    #LOG.info(response)
    #LOG.info("after response")

    if 'logout_reason' in request.COOKIES:
        response.delete_cookie('logout_reason')
    if 'logout_status' in request.COOKIES:
        response.delete_cookie('logout_status')
    # Display Message of the Day message from the message files
    # located in MESSAGES_PATH
    if MESSAGES_PATH:
        notifications.process_message_notification(request, MESSAGES_PATH)
    return response
Exemple #18
0
def callKeystoneForTotp(request):
    """TOTP CHECK"""
    try:
        import urllib2
        totpVal = request.GET.get("totp", "")
        LOG.info('TOTP value is ')
        LOG.info(totpVal)

        username = '******'
        password = '******'

        data = '{ "auth": { "identity":{ "twofactor": {"totp_value": "' + str(
            totpVal
        ) + '"}, "methods": ["password","twofactor"],"password": {"user": {"name": "' + username + '","domain": { "id": "default" },"password": "******"}} } }  }'
        url = 'http://localhost:5000/v3/auth/tokens'
        req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
        LOG.info('req')
        try:
            LOG.info('Entering try')
            f = urllib2.urlopen(req)
            LOG.info('HERE IN F')
            for x in f:
                LOG.info('x section')
                request.session['totp_valid'] = True
                request.session['totp_invalid'] = False
                print "****"
                print(x)
            f.close()
        except Exception, e:
            #print e
            #request.session['otp_invalid'] = True
            #request.session['otp_valid'] = False
            LOG.info('exception section')
            LOG.info(e)
            return False

        LOG.info('session printing')
        LOG.info(request.session)
        response = shortcuts.redirect(horizon.get_user_home(request.user))
        return response
Exemple #19
0
def callKeystone(request):
    """
	Function to call keystone API for OTP authentication.
	This will call keystone API and do the current token authentication and will send the submitted OTP for validation.
	@param : request
	"""
    LOG.info('entering the function callKeystone')
    try:
        import urllib2
        otpVal = request.GET.get("otp", "")
        LOG.info('OTP value is ')
        LOG.info(otpVal)
        """
		data = {"auth":{"identity":{"otp":{"otp_value":+ otpVal+},"methods":["token","otp"],"token":{"id":+request.user.token.id}}}}
		#data = {"auth":{"identity":{"otp":{"otp_value":"123456"},"methods":["token","otp"],"token":{"id":"d7715c3389c94a0489447c4700936369"}}}}
                LOG.info(data)

		url = 'http://localhost:5000/v3/auth//tokens'
                #url = 'http://localhost:5000/v2.0/tokens'
		LOG.info('after url')
                values = {"auth":{"passwordCredentials":{"username":"******", "password": "******"}}}
                params = json.dumps(data)
                LOG.info('after params')
	        #headers = {"Content-type":"application/json","Accept": "application/json"}
	 	headers = {'Content-Type': 'application/json','X-Auth-Token':request.user.token.id}
                req = urllib2.Request(url, params, headers)
		LOG.info(req)
		LOG.info(req.__dict__)
                #response = urllib2.urlopen(req)

                #data = response.read()
                #text = json.loads(data)

                LOG.info(req)
		#req = urllib2.Request(url, data, {'Content-Type': 'application/json','X-Auth-Token':request.user.token.id})
		"""
        username = '******'
        password = '******'

        data = '{ "auth": { "identity":{ "otp": {"otp_value": "' + str(
            otpVal
        ) + '"}, "methods": ["password","otp"],"password": {"user": {"name": "' + username + '","domain": { "id": "default" },"password": "******"}} } }  }'
        url = 'http://localhost:5000/v3/auth/tokens'
        req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
        LOG.info('req')
        try:
            LOG.info('Entering try')
            f = urllib2.urlopen(req)
            LOG.info('HERE IN F')
            for x in f:
                LOG.info('x section')
                request.session['otp_valid'] = True
                request.session['otp_invalid'] = False
                print "****"
                print(x)
            f.close()
        except Exception, e:
            #print e
            #request.session['otp_invalid'] = True
            #request.session['otp_valid'] = False
            LOG.info('exception section')
            LOG.info(e)
            return False

        LOG.info('session printing')
        LOG.info(request.session)
        response = shortcuts.redirect(horizon.get_user_home(request.user))
        return response
Exemple #20
0
def user_home(request):
    """ Reversible named view to direct a user to the appropriate homepage. """
    return shortcuts.redirect(horizon.get_user_home(request.user))
def get_user_home_url(user):
    return horizon.get_user_home(user)
def user_home(request):
    LOG.info("xxx enter user_home of horizon/views.py")
    """Reversible named view to direct a user to the appropriate homepage."""
    return shortcuts.redirect(horizon.get_user_home(request.user))
Exemple #23
0
def user_home(request):
    """ Reversible named view to direct a user to the appropriate homepage. """
    return shortcuts.redirect(horizon.get_user_home(request.user))
Exemple #24
0
def splash(request):
    if request.user.is_authenticated():
        return shortcuts.redirect(horizon.get_user_home(request.user))
    form = forms.Login(request)
    return shortcuts.render(request, 'splash.html', {'form': form})