X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fhomeview.py;h=b5e47fe63965885bd14225c2dfbb26ba599a6502;hb=e662708d2f2f1ba05daefe1db50ee08c5439aadc;hp=a66cd36dff7b709f4c27e08d972d01ff790a96fb;hpb=1aea42c3668602aacfe22bc762ee939672129f53;p=myslice.git diff --git a/portal/homeview.py b/portal/homeview.py index a66cd36d..b5e47fe6 100644 --- a/portal/homeview.py +++ b/portal/homeview.py @@ -6,11 +6,13 @@ from django.contrib.auth import authenticate, login, logout from django.template import RequestContext from django.shortcuts import render_to_response -from myslice.viewutils import topmenu_items, the_user +from manifold.manifoldresult import ManifoldResult +from ui.topmenu import topmenu_items, the_user from myslice.config import Config class HomeView (View): + # expose this so we can mention the backend URL on the welcome page def default_env (self): return { 'manifold_url':Config.manifold_url, @@ -24,8 +26,20 @@ class HomeView (View): # pass request within the token, so manifold session key can be attached to the request session. token = {'username': username, 'password': password, 'request': request} - user = authenticate(token=token) - if user is not None: + # our authenticate function returns either + # . a ManifoldResult - when something has gone wrong, like e.g. backend is unreachable + # . a django User in case of success + # . or None if the backend could be reached but the authentication failed + auth_result = authenticate(token=token) + # high-level errors, like connection refused or the like + if isinstance (auth_result, ManifoldResult): + manifoldresult = auth_result + # let's use ManifoldResult.__repr__ + env['state']="%s"%manifoldresult + return render_to_response('home-view.html',env, context_instance=RequestContext(request)) + # user was authenticated at the backend + elif auth_result is not None: + user=auth_result if user.is_active: print "LOGGING IN" login(request, user) @@ -33,6 +47,7 @@ class HomeView (View): else: env['state'] = "Your account is not active, please contact the site admin." return render_to_response('home-view.html',env, context_instance=RequestContext(request)) + # otherwise else: env['state'] = "Your username and/or password were incorrect." return render_to_response('home-view.html',env, context_instance=RequestContext(request))