Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register & login to django backend from iphone app and mobile browser

We are building a Django backend with an iphone app and also would like to allow login through web/mobile browsers. The requirement is to be able to register and logon from the website/mobile browser and also through the iphone app. I have also integrated django-registration for registration, login, logout etc.

What would be the preferred approach so that register, login, logout can be doen through the iphone app as well as mobile browser?

The most discussed approach seem to be the following:

  1. Use tastypie for a RESTful API(or any other framework for REST) ( In this case, I assume that means create an api for register and login)
  2. For iphone, use RESTKIT to call and authenticate the backend to perform login, registration etc.

Security and ability to only see relevant data for the user is important in our case as the data is highly sensitive.

Any advice is much appreciated and surely will help others too.

Thanks in advance. Neo

like image 842
Neo_32 Avatar asked Nov 03 '22 18:11

Neo_32


1 Answers

If you have already integrated django-registration on your website, then you don't necessarily need to add tastypie just for login,logout etc.

Check out the documentation for django-registration at https://django-registration.readthedocs.org/en/latest/quickstart.html#setting-up-urls. If you follow the steps for the default setup, that should provide you with URLs for login, logout etc. If the section on "Required Templates" doesn't make sense to you here, read more about django at http://www.djangobook.com/en/2.0/chapter04.html

Once you have these URLs, you can simply make use of the AFNetworking library on iOS to create HTTP requests to login / logout etc.

Typically, a django view for registration will serve GET and POST requests differently. If you make a GET request, it will format the registration form and display the HTML page. If you make a POST request, it will first extract the information required for registration from the request and create a new user. This will happen automatically for the web.

Making use of AFNetworking, you can create a view that shows the form locally and then makes the corresponding POST request once the user wants to register. The same procedure applies for login.

like image 172
e7mac Avatar answered Nov 11 '22 21:11

e7mac