0

I am creating a login process from iphone to django server.

I made Session class using class method, httprequest wrapper using json.

but I don't know. How can I get session information and matching server session?

if I get session information, (just example pseudo code)

def function(username, password)
    if is_authenticate(username, password) == true
        login(username, password)
        #What send value to iphone 
        return returnValue(session_id)

How can I send session_id?

This is Login Function

    def sign_in(request):
     if request.method=='POST':
         username = requset.POST['username']
         password = request.POST['password']
         user = authenticate(username=username, password=password)
         list = []
         if user is not None:
             if user.is_activate:
                 try:
                     login(request,user)
                     list.append( {'fields':
                                        {'login_status':'login success'},})
                 except:
                     list.append( {'fields':
                                        {'login_status':'login fail'},})



returnValues = json.dumps(list,cls=DjangoJSONEncoder)
return HttpResponse(returnValues)
rantanplan
  • 7,283
  • 1
  • 24
  • 45
Haibane
  • 67
  • 5

1 Answers1

1

Typically the session identifier will get set as a cookie, automatically if you use the default NSURLCONNECTION and NSURLRequest, as for session data, that lives on the server and if you want access to it on your iPhone you will have to develop some sort of API, be it rest based or soap or less formally defined.

So the workflow may be something like

iPhone sends login request: sever responds ok... Set cookie some session data.

iPhone sends userData request: sever responds with Json structure of user data.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • Thx @Grady Player. I try something. make a cookie from iphone, to django server and return cookie in response. but can't return value 'set-cookie' but vary: cookie; any have solution? – Haibane Oct 16 '12 at 06:34
  • not sure what you mean, in django, with sessions turned on it should send the header automatically to set the cookie, this will then basically be persisted by your NSURLConnection... you generally don't have to worry about it, but if you do need to keep it, you can opt to manage the cookies yourself, in which case you will see the set-cookie header... see http://stackoverflow.com/questions/2053568/managing-http-cookies-on-iphone – Grady Player Oct 16 '12 at 21:44