Skip to content
Snippets Groups Projects
views.py 1.92 KiB
#
# Copyright (c) 2015 NIBIO <http://www.nibio.no/>. 
# 
# This file is part of VIPSWeb.
# VIPSWeb is free software: you can redistribute it and/or modify
# it under the terms of the NIBIO Open Source License as published by 
# NIBIO, either version 1 of the License, or (at your option) any
# later version.
# 
# VIPSWeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# NIBIO Open Source License for more details.
#
# You should have received a copy of the NIBIO Open Source License
# along with VIPSWeb.  If not, see <http://www.nibio.no/licenses/>.
# 

#from django.shortcuts import render
from django.http import JsonResponse, HttpResponseRedirect
from django.shortcuts import render
from django.conf import settings
from models import VipsLogicUser
import requests

# Create your views here.
# VIPSLogic login handling
# Direct login with a user UUID
# Deprecated. See check_login_middleware for handling
def login_user_uuid(request, user_uuid):
    found_user = VipsLogicUser.find_by_uuid(user_uuid)
    if found_user != None:
        request.session["vips_logic_user"] = found_user
        request.session["user_uuid"] = user_uuid
        request.session.set_expiry(2592000) # 30 days lasting
        return JsonResponse({"success":"true"})
    else:
        return JsonResponse({"success":"false"})

# Deprecated
def login_form(request):
    return render(request, "security/login_form.html")

def logout(request):
    response = HttpResponseRedirect("/")
    if request.session["vips_logic_user"] != None:
        user_uuid = request.session["vips_logic_user"]["userUuid"]
        # Delete session info
        request.session["vips_logic_user"] = None
        # Delete user UUID
        requests.delete("http://%s/rest/user/uuid/%s" % (settings.VIPSLOGIC_SERVER_NAME,user_uuid))

    # Return to index page
    return response