Django Admin: Allow email as a username? - django

I've recently inherited a django project and I'm facing a serious amount of bugs/issues and ...quirks that need to be fixed. As I'm coming from a php background (don't ask), I'm having a ...challenging time.
In terms of the Django admin, It will not accept any email address as a username. However, IN our front-end - the previous developer designed the system in such a way that the application used an email address as the username. This is fine in the frontend, but we can't save any changes we make to a user in the admin section ¬.¬
Is there any way to fix this WITHOUT updating our django installation to v1.2 (NOT an option) and WITHOUT modifiying any of the Django.contrib files?
I've heard good things about extending these classes/method, but I'm very unsure how to proceed.
Looking at websites online, they suggest writing a custom backend, etc...? Is the the right way to go about it? I'm not too confident a djanog programmer though, and considering this is to do with User Logins, I'd be VERY unconfident about any solution I could write.
Is there an easy way I can simply override the username validation method to accept an # and be over 30 chars?

This snippet might be helpful:
Use email addresses for user name

If you use django1.2.1 there is no problem: http://docs.djangoproject.com/en/1.2/topics/auth/#fields

Related

Wagtail SteamFields for community user generated content instead of editor, author workflow

I really like StreamFields, but I don't want the baggage of Wagtail's Publishing system.
For example, consider a Forum community site. Instead of using CK Editor or BBCode, Markdown etc form input. I want to give users the option of StreamField based input to construct posts or replies
Is this possible? If yes, what steps would I need to take or edits to Wagtail do I need to do?
I'm guessing using a permission system while keeping the user as a limited admin would be the thing to do, since removing the user from admin doesn't seem to be possible since Wagtail is heavily reliant on Django Admin.
I'm guessing using a permission system while keeping the user as a
limited admin would be the thing to do, since removing the user from
admin doesn't seem to be possible since Wagtail is heavily reliant on
Django Admin.
If you want to reuse StreamFields, you probably want to use the Wagtail admin interface; doing otherwise is likely to be quite a bit of work. So users will need to be able to log in and have the wagtail_admin permission so they can access the admin interface. If you tried to use Page models for your forum, you are going to end up crossways of the way Wagtail's page permissions cascade. You could probably write your own admin views for regular users to add certain kinds of content.
But honestly, unless you have quite a bit of experience with Wagtail in its normal content management mode, I wouldn't suggest you try using it for this use case.

Users for multiple sites in Django

I am trying to get multiple sites to use the same database and code but in a way which forces each user to have their own login to each site.
I have seen a few suggestions as to how to make this work but I'm not sure which way to go.
I am using the Sites Framework, using the subdomain to identify the current site so I'm not using SITE_ID at all.
Use the sites framework - This answer (https://stackoverflow.com/a/1405902/1180442) suggests using the sites framework to do it, but I'm having trouble with the get_user() method, as it doesn't have access to the request and that's where my site info is stored.
Use separate databases for users - I'm really not sure about this one but I think it might cause bigger problems down the line.
Change to using SITE_ID - I want to try and avoid this if possible as it will mean having to run many different instances of my app, one for each site, which uses it's own settings.py. This will quickly turn into a nightmare, I think.
Permissions - I'm wondering if this should be something that I get the permissions framework to use? So one set of users for all sites but each user can have permissions to see each site, as long as they've registered with that site?
Can anyone help with this?
I quite like the idea of number 1 but I just need to get the request in the get_user() method so I can do this
def get_user(self, user_id):
try:
# I can't do this because there is no request available here
return User.objects.get(pk=user_id, site=request.site)
except User.DoesNotExist:
return None
to prevent people logged in to one site being able to log into another using the same session.
How I actually do it, not for users but for common databases, Is to design a main, hidden app with a REST API architecture. My other apps, naturally have their own DB and exchange their data via batch or stream process depending on the need. I use django-rest-framework.
For your case what I would do is that whenever a user makes a Log In request I would send it via HTTPS to my main database and get it authenticated in my main app. Whenever I would need to validate the user status I would simply make a get request to the main app.
This architecture is not that different from the one that many mobile apps have.
I hope it helps.

Django 1.8: Password Protect Entire Project

I have built my first Django App! It is built to help my business track inventory. As such, I would not like it to be publicly available.
Maybe someday I will set up multiple user accounts, etc, but for now I really just need a basic password gate to get it up and running.
Does anyone have any middleware that works for this? All the solutions that I am finding are pretty old and they do not seem to work with the latest version of Django.
If you just need a single username/password couple, handling it directly via HTTP authentication in your webserver configuration will be the easiest way to achieve this. The benefits of this approach are:
You can set it up in 5 minutes: example with nginx, example with apache
You don't have to write code you'll delete later
It will protect all your website, including static files, third-party apps, admin, etc.
I found an answer that worked for me posted here:
#login_required for multiple views
Make sure the LOGIN_REQUIRED_URLS_EXCEPTIONS path is correctly set to your login page.

User management app for Django's auth

I am working on a small Django site where every user who leaves a comment on the site gets an email with a password (email is the user name) to change the comment later on.
The site should also support functions for users to retrieve or reset passwords. For this simple task I wanted to use the Django auth capabilities.
Is there a Django app which provides a simple package of user management (to reset or change a user's password) which I could incorporate in my site?
Would packages like Pinax or Drupal help for this simple task? They seem to be the overkill.
If you are looking for an advanced profile-/account-module you could take a look at django-userena
Some other options are listed in the profiles-grid on Django Packages.
Reset and change password are both included in the standard contrib.auth views.
I would have a look at django-user-accounts

what's the best django profile / user settings application around?

I'm looking for a good django app that brings to me basic features like
user profile editing
password changing
save settings / preferences specific to my app
save authentication keys to external apps (twitter, rtm, facebook, ...)
I know how to extend the normal user model (see docs http://www.djangobook.com/en/1.0/chapter12/#cn222)
and there are also these apps around:
django-profile/
idios (on github)
django-account/
however, none of them seems to be ideal for what I want.
Therefore, my question is, does anyone know a app that is better / more mature / more feature rich that I just didn't find?
Or do I have to roll my own app?
I use django-userena.
https://github.com/bread-and-pepper/django-userena
demo: http://www.django-userena.org
I am sorry to inform you that you will (for now) have to put together a custom solution using django-registration/django-profiles along with django-socialregistration.
Start here with and progress to Socialnetwork Authentication. On the up side, django is young so solid solutions are in the near future and you will be part of them. ;-)