Now that you have done the user registration and validation of fields, the next question is how to automatically login when the user has done the registration and created a valid user. This can be done by adding a few extra lines of custom code to the registration form that then are added to the end of the view code. To do this you have to switch to code editor and locate the "show generated view code" button at the top. Click this button and you enters view code editor. Here you can write your own code that is run when a page is loaded from the server. Since you want to do the login after you have stored the data, you add the new code to the bottom view cdoe before rendering page part in the editor.

if request.method == 'POST' and result.get('result')=='ok':
    import django.contrib.auth as auth
    user = auth.authenticate(username=un,password=pw)
    auth.login(request, user)

auto login example

This code checks if we are done registering the user by checking request.method. DG3 has two main types of requests, the GET and the POST. The GET is reading information and presenting data and the POST is storing and processing data. All DG3 pages that has user fields for editing adds a section for taking care of the incoming data by post. We just tap into this after the user is stored to the database. To see if the data is stored without error, we check the result dict to see if we have a 'result' : 'ok' there. This means that the user was stored to the server (aka. a valid user without errors). Then we loads the django authentication modules that we use for authentication in DG3. We find the username and password set by the user by reprocessing the indata using the build in viewtools. These methods are the same that is used by the builtin data engine. Then we fetch the username and password entered by the user. If you not are registering username and only email, you can just change the get('username') with a get('email') as DG3 supports both values as username for authentication . The next two lines just do the internal login and store the user the the session. That's it, you now are logged in.