-
- What is DG3
- The different components
- Requirements for running DG3
- Installation of DG3
- Additional installation steps
- Select which web server to use
- Hello World application
- Intro to CMS
- Setting up DG3 as a CMS
- Editing pages
- More about pages and urls
- Structuring a page using the grid
- Adding menu to pages
- Add images to the application
- More formating
- Sending email from contact us
- Adding menu to template
- Deploy the web site
- Storing the pages in database
- Create record
- Auto fill field
- Field validation
- Enable save button validator
- Add new button to template
- View document
- List documents
- Fix selection in menus in template
- CRUD Create Read Update Delete
- Intro to blogs
- Add user authentication
- Bootstrap authentication
- Let user change their passords
- Add reset password
- Login dialog box
- Extending the CMS to a blog
- Extend table for blogging
- Edit blog entry
- View blog entry
- User registration
- User password validation
- User field validation
- User auto login
- User extra registration fields
User auto login
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 recorddata=viewtools.getrecorddata(indata) un=recorddata.get('username') pw=recorddata.get('password') user = auth.authenticate(username=un,password=pw) auth.login(request, user)
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.