-
- 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 field validation
Now that we have taken care of validation and two password field, the next question is how to make sure our information can be saved and show this by making our fields green when they can be saved and red if we have a conflict. To do this we will create a helper page that can be called using ajax to check for valid email and user. We want all our users to have a unique user name and email since these can be used for logging on DG3. The plan than is to call the server when username or email is changed and return valid or not valid for email and a username that is for the username. This is advanced coding and an error in this code may make your server not start if done wrong, so use and change with care.
The valid user page
I chose to add this page in the authentication folder with the rest of authentication related pages. Since this will be used by registration, no user login can be added. We will let the page take two paramters field and makeunique. The field parameter will take email og username as parameter and makeunique will make a new unique username by adding numbers to the suggested one if set to any true value (none blank or not 0 means true).
gdict = request.GET gdict = viewtools.splitgdict(gdict) field = gdict.get('field','') value = gdict.get('value','') makeunique=gdict.get('makeunique') result = {'result' : 'error', 'field' : field, 'value' : value,'makeunique' : makeunique} if field: from django.contrib.auth import get_user_model table=get_user_model() try: if field=='username': rec = table.objects.get(username=value) elif field=='email': rec = table.objects.get(email=value) if makeunique: idx = 0 isunique = False while not isunique: try: idx += 1 nval = "%s%d" % (value,idx) if field=='username': rec = table.objects.get(username=nval) elif field=='email': rec = table.objects.get(email=nval) else: break except: isunique=True result['result']='ok' result['value']=nval except: result['result']= 'ok' return HttpResponse(json.dumps(result), content_type="application/json")
The custom code
Using the valid user page from registration
To use this page, we will borrow a method from our datasource library. Since we are manipulating fields, this will already be loaded and active to use by the javascript name datasource.