SHARE
TWEET

Gateway.py

Jerrian Jun 2nd, 2011 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import the required pyamf and django modules
  2. from pyamf.remoting.gateway.django import DjangoGateway
  3. import pyamf
  4. from django.contrib import auth
  5. from django.contrib.auth import authenticate, login, logout
  6.  
  7. # import model
  8. from django.contrib.auth.models import User
  9.  
  10.  
  11. # need to register your django models to provide alias (mapping)
  12. # to Flex models
  13. pyamf.register_class(User, 'com.jfawcett.models.UserVO')
  14.      
  15. def logout_user(http_request):
  16.     logout(http_request)
  17.  
  18. def login_user(http_request, username, password):
  19.     user = authenticate(username=username, password=password)
  20.     if user is not None:
  21.         login(http_request, user)
  22.         user_obj = User.objects.select_related().get(username=username)
  23.         return user_obj
  24.     return None
  25.    
  26. # Finally to expose django views use DjangoGateway
  27. gw = DjangoGateway({
  28.      "AuthService.login": login_user,
  29.      "AuthService.logout": logout_user,
  30.  })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top