From 8fabd54ff29ca06d6f46d70552caeece8cf82644 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 30 Jul 2010 12:53:11 +0200 Subject: [PATCH] add login/logout views (those will be moved to djextdirect sooner or later) --- pyweb/mumble/views.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 66f5585..090ba2b 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -37,9 +37,26 @@ from djextdirect import Provider EXT_DIRECT_PROVIDER = Provider() -@EXT_DIRECT_PROVIDER.register_method( "omgfu" ) -def ohai( request ): - return "plzkthx" +@EXT_DIRECT_PROVIDER.register_method( "Accounts" ) +def login( request, username, passwd ): + from django.contrib.auth import authenticate, login as djlogin + if request.user.is_authenticated(): + return { 'success': True } + user = authenticate( username=username, password=passwd ) + if user: + if user.is_active: + djlogin( request, user ) + return { 'success': True } + else: + return { 'success': False, 'error': 'account disabled' } + else: + return { 'success': False, 'error': 'invalid credentials' } + +@EXT_DIRECT_PROVIDER.register_method( "Accounts" ) +def logout( request ): + from django.contrib.auth import logout as djlogout + djlogout( request ) + return { 'success': True } def redir( request ): """ Redirect to the servers list. """