Giter Site home page Giter Site logo

demo-allauth-bootstrap's Introduction

demo-allauth-bootstrap

  • Simple, out-of-the-box Django all-auth demo app
  • A "brochure" or visitor (no login required) area
  • A members-only (login required) area.
  • Supports local email/password as well as easy oauth with Google, Facebook and others.

This is a simple, old-style HTML request/response website. No webpack, node, JavaScript framework. Objective is to get you a basic, visitor-and-member website operational quickly.

tl;dr

  1. Get your Facebook and/or Google app creds (see sections below for more info);
  2. Clone or download the repo; then
  3. Follow instructions below:
$ cd demo-allauth-bootstrap

## create and use a Python virtualenv:

$ python3 -m venv mypy          # doesn't have to be called "mypy"; it's just my convention.
$ . ./mypy/bin/active           # adjust this if you used a name other than "mypy"

## install all dependencies into this venv:

$ pip install -r requirements.txt

## run the handy configure script:

$ python ./configure.py

--------
Facebook
--------

Do you want to configure auth via Facebook?
You'll need the app secret and client. (y/n): y              # or enter 'n' to skip

Facebook App Secret? >                                       # Facebook secret here...

Facebook App ID (not client token)?                          # and app ID here.

------
Google
------

Do you want to configure auth via Google?
You'll need the app secret and client. (y/n): y              # or enter 'n' to skip

Google Secret? >                                             # Google secret here...

Google Client ID? >                                          # and Google client ID here.

----------
Next steps
----------

Run these commands:

    python manage.py makemigrations allauthdemo_auth
    python manage.py migrate
    python manage.py createsuperuser                         # optional; doesn't need real email address.

    # Facebook
    python manage.py set_auth_provider facebook --redacted-info-here--

    # Google
    python manage.py set_auth_provider google --redacted-info-here--

If you have other providers you can add them like:

    python manage.py set_auth_provider <name e.g. 'google'> <client id> <secret>

Finally:

    python manage.py runserver

Run the commands shown in "next steps" above.

Load http://127.0.0.1:8000/ in your browser.

Tips

Overall tip

Tinker with it out-of-the-box. If it does what you like, you can remove a few things and use the code as a basis for your own site.

Tips for Facebook

  • See "Configure Facebook Login" section below
  • You'll need the Facebook App ID (NOT any client ID) and the secret.
  • Repeat, the Facebook App ID and NOT any client ID is what should be entered for "client ID"
  • Create an app in the facebook-developer-settings area and then create a test app from that. The test app seems to be the only thing that will work with a localhost Django app.
  • Read the article by Sarah or see below for moe.

Tips for Google

  • See "Configure Google Login" section below
  • You'll need the Google client ID and secret from the Google Developer Console.

Pre-setup

If you want users to register and set passwords locally, i.e. never via a provider like Facebook or Google, run configure.py and answer 'n' to the questions.

If you want to use a provider like Facebook or Google, you'll need to do a little setup on those sites to get settings you'll need in Django.

Configure Facebook Login

Follow these instructions if you want to use Facebook as an authentication provider. Skip otherwise.

Sarah describes this nicely in her article

Aside from UI changes, the method she described worked well.

  1. Go to facebook-developer-settings.

  2. Add app

  3. Create a test app (under the above app)

  4. Go to Settings > Advanced

  5. Do not add any server to Server IP Whitelist (facebook-whitelist-ip-error)

  6. Add product "Facebook Login"

  7. Enable if not automatically selected: Client OAuth Login, Web OAuth Login

  8. Add OAuth redirect URL (in any order): http://127.0.0.1:8000/ http://127.0.0.1:8000/accounts/facebook/ http://127.0.0.1:8000/accounts/facebook/login/callback/

Note: If you're loading your site with localhost:8000 you should use "http://localhost:8000/..." above. Whichever you choose, do it consistently and you should be ok.

Note: The "app secret" and "client id" are a bit confusing with Facebook.
You want to record the "Facebook App Secret" and the "Facebook App ID". The latter "Facebook App ID" becomes the "client ID" from a Django Allauth perspective.

Configure Google Login

Follow these instructions if you want to use Google as an authentication provider. Skip this section otherwise.

To set up Google, follow the Google oauth instructions or [this help answer][4] which is basically:

  1. Go to https://console.developers.google.com/

  2. Create a new app

  3. Make sure that app is selected (next to the "Google APIs" Logo in the top-left)

  4. In the left navigation rail under "APIs and Services", click "Credentials"

  5. Create new oauth client ID

    You will need to specify some "consent screen details". You can skip most of the fields.

  6. For Authorized Javascript Origins, add: http://127.0.0.1:8000

  7. For Authorized Redirect URIs, add: http://127.0.0.1:8000/accounts/google/login/callback/

  8. Click "Create"

  9. Copy the "client ID" and "client secret" strings and keep each handy - you'll need them shortly.

Reminder: if you're loading your site at localhost:8000 then you'll need to set the URIs above to ``http://localhost:8000/..." etc. I recommend not doing that. Instead, just load your local site as http://127.0.0.1:8000/

Configure authentication with other providers

The django-allauth library covers many others providers

First-time setup

  1. Make sure you have Python 3.x installed. I used Python 3.6.

    Python 2.7.x used to work but Django 2.0 dropped support for Python 2.x, and is dropping support for Python 3.4.

  2. Create a virtualenv and requirements.

    For example:

     $ cd demo-allauth-bootstrap
     $ python3 -m venv mypy       # you can call it anything, not just "mypy"
     $ . mypy/bin/activate
     $ pip install -r requirements.txt
    
  3. Generate the initial settings:

     $ python configure.py
    

    Follow the prompts. This will generate the initial config/settings.py

  4. Set up the initial migrations:

    A specific makemigrations is needed for the auth_user table:

     $ python manage.py makemigrations allauthdemo_auth
    
  5. Build the database schema:

     $ python manage.py migrate
    
  6. Create the superuser:

     $ python manage.py createsuperuser
    

    Tip: do not enter the same email address that you'll connect via Google/Facebook with. In development I use a made up address like "[email protected]".

  7. Add the social providers:

    Run this for each provider you want to include.

     $ python manage.py set_auth_provider google GOOGLE_CLIENT_ID GOOGLE_SECRET_ID
     saved: Google (...)
     
     $ python manage.py set_auth_provider facebook FACEBOOK_CLIENT_ID FACEBOOK_SECRET_ID
     saved: Facebook (...)
    

    This essentially runs SQL like:

     DELETE FROM socialaccount_socialapp WHERE provider='google';
     INSERT INTO socialaccount_socialapp (provider, name, secret, client_id, `key`)
     VALUES ("google", "Google", "SECRET", "CLIENT", '');
     INSERT INTO socialaccount_socialapp_sites (socialapp_id, site_id) VALUES (
       (SELECT id FROM socialaccount_socialapp WHERE provider='google'),1);
    
  8. Check it's working:

     $ python manage.py runserver
    

    Load the site at http://127.0.0.1:8000

    You should see a landing page. Click "Join" or "Login".

  9. Log into admin and change the default site:

    Go to http://127.0.0.1:8000/admin/sites/site/ - you may need to log out, then log back in as the superuser you created above.

    You don't technically have to rename the site but the default "example.com" isn't very useful. In development I change the domain to "127.0.0.1" and the name to " (Dev)".

Doing it over

When you're getting oriented you may find you want to start over for any reason.

If you're using sqlite as the database (the default), just remove the file and start the sequence again:

rm db.sqlite3
python configure
python manage.py makemigrations allauthdemo_auth
python manage.py migrate
python manage.py set_auth_provider google ...
python manage.py runserver

If you're using Postgres or similar, remove and recreate the database.

Notes

Make the repo yours

If you've got the site up and want to use it as the basis for your own real site, here's what I do:

  • Remove all the git history:

      rm -rf .git/
    

    and start a new history:

      git init
    
  • Remove unnecessary files:

      rm LICENSE README.md config/settings.template.py configure.py
    
  • Rename the "allauthdemo" directory to something more appropriate

  • Optionally rename the class auth.models.User to something more specific. You'll need to rebuild the database (I suggest you do this after you've built the initial app and renamed things anyway). Don't leave this too late as trying to migrate the User class to a new name doesn't work nicely when you've got real data.

  • Check the auth.models.UserProfile class. The draft one includes date-of-birth (dob), which you might want to remove.

  • Change settings so Postgres or another full database is used, not sqlite (which is awesome, but not right for a real project!)

How I built this

The best resources:

I first worked with Sarah's example to understand how the components worked together. Then I cloned the github repo and worked with the example directory, customising it to what made sense to me. I moved it to use Bootstrap only and added some basic standard stuff like a landing page and stubs for terms and contact.

I moved the bootstrap forms to use the bootstrap4 library. At the very least that made handling Django "messages" better (though see my notes in "Rough Edges" below). Read about bootstrap4 here: http://django-bootstrap4.readthedocs.org/en/latest/

Why I built this

I'd struggled with outdated Django registration modules before and was pleasantly surprised to find django-allauth. Sarah's tutorial is superb but I wanted something more full to use as a basis for future work, and figured it might help others.

Credits

Thanks to Raymond for django-allauth and Sarah for her tutorial.

Rough Edges

In no order:

  • I don't like the handling of Django "messages". The messages accumulate in the cookie, which is weird on its own, and clear only when displayed. I don't get why it was done that way. I'm sure there are better ways to handle it; I just haven't looked into it yet.

  • The default allauth rendering for profile (email, social accounts etc) is adequate but could do with some work.

demo-allauth-bootstrap's People

Contributors

aellerton avatar bitcity avatar dependabot[bot] avatar derek-adair avatar ellers avatar gsong avatar lucas03 avatar singuliere avatar zachliugis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

demo-allauth-bootstrap's Issues

Abstract User relation Error on make rebuild

Here's what happens:

~/c/demo-allauth-bootstrap (master) $ make rebuild
rm -f db.sqlite3
python manage.py syncdb --noinput
CommandError: One or more models did not validate:
account.emailaddress: 'user' has a relation with model allauthdemo_auth.DemoUser, which has either not been installed or is abstract.
admin.logentry: 'user' has a relation with model allauthdemo_auth.DemoUser, which has either not been installed or is abstract.
auth.user: Model has been swapped out for 'allauthdemo_auth.DemoUser' which has not been installed or is abstract.
socialaccount.socialaccount: 'user' has a relation with model allauthdemo_auth.DemoUser, which has either not been installed or is abstract.

make: *** [syncdb] Error 1

I'm using Django 1.6.5.

no such table: main.socialaccount_socialapp__old

Hey! First of all thanks for this repository.I did all steps successfully but I got an error when I run
python manage.py set_auth_provider google GOOGLE_CLIENT_ID GOOGLE_SECRET_ID
and the error is

django.db.utils.OperationalError: no such table: main.socialaccount_socialapp__old

Database created successfully with 'manage.py migrate'

Whats make configure? Can't run this??

$ make configure # Builds a seed.sql that can be used in make rebuild
$ make rebuild # A bit better than python manage.py syncdb
$ make run # The same as python manage.py runserver

Im using windows

Not working in Django==1.8.1

I followed the installing instructions, but I am getting an:
ImportError at/ No module named context_processors

I thought it was because the new TEMPLATE settings in Django 1.8, but even after updating settings_generated.py the error persists.

I also tried to run using Django 1.7, but got the same..

screen shot 2015-07-24 at 3 30 46 pm

Any ideas of how can I make it work?

Thanks!

Error creating super user

When trying to create a superuser using the createsuperuser command I receive the error:

self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) TypeError: create_superuser() takes exactly 4 arguments (2 given)

I'm quite far through a project so can't be 100% sure it's down demo-allauth-bootstrap without testing a fresh project. However I see you inject the superuser using the make file so it could explain why this error wouldn't of occurred.

Anyway just incase a problem with demo-allauth-bootstrap I solved it by creating a custom user manager:

'class CustomUserManager(BaseUserManager):

def _create_user(self, email, password,
                 is_staff, is_superuser, **extra_fields):
    """
    Creates and saves a User with the given email and password.
    """
    now = timezone.now()
    if not email:
        raise ValueError('The given email must be set')
    email = self.normalize_email(email)
    user = self.model(email=email,
                      is_staff=is_staff, is_active=True,
                      is_superuser=is_superuser, last_login=now,
                      date_joined=now, **extra_fields)
    user.set_password(password)
    user.save(using=self._db)
    return user

def create_user(self, email, password=None, **extra_fields):
    return self._create_user(email, password, False, False,
                             **extra_fields)

def create_superuser(self, email, password, **extra_fields):
    return self._create_user(email, password, True, True,
                             **extra_fields)'

redirect_uri_mismatch

Hi,
I really appreciate the idea and the work you guys are doing with this project! Seriously, your project here is why I now officially love Django.

But, I ran into a problem today. Installed everything from scratch will the beautiful and easy install make files and all. But I can't seem to get my google callback URI to work:

Error: redirect_uri_mismatch

The redirect URI in the request, http://localhost:8000/accounts/google/login/callback/, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/

Am I doing anything wrong? Have looked through your walkhrough over and over again. Almost seems like a bug, since I haven't changed anything in the demo.

make rebuild error: " LookupError: App 'auth' doesn't have a 'demouser' model."

Help !
I am trying to simply the project throuh a Django 1.8 environment using Python 3.4 . I tried with 1.7 too
I tried firstly on a Mac, then on a linux computer with the same output.

The "make configure" is going fine but the "make rebuild" is giving my a terrible output. (copied/pasted here after a blank setup with no facebook setup nor google )

-----------------------------------------------------------
/1.8-projects/demo-allauth-bootstrap$ make rebuild
rm -f db.sqlite3
python manage.py syncdb --noinput
Traceback (most recent call last):
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/apps/config.py", line 159, in get_model
return self.models[model_name.lower()]
KeyError: 'demouser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/management/init.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run$from_argv
self.execute(_args, *cmd_options)
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/management/base.py", line 440, in exe$ute
self.check()
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/management/base.py", line 478, in che$k
include_deployment_checks=include_deployment_checks,
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/core/checks/registry.py", line 72, in run
$hecks
new_errors = check(app_configs=app_configs)
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/contrib/auth/checks.py", line 12, in check$user_model
cls = apps.get_model(settings.AUTH_USER_MODEL)
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/apps/registry.py", line 202, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "/home/jcda/django/1.8-projects/lib/python3.4/site-packages/django/apps/config.py", line 162, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'auth' doesn't have a 'demouser' model.
make: *** [syncdb] Error 1
-----------------------------------------------------------

Has anyone had the same error ?
How did you solve it ?
Am I missing something ?
Thanks in advance for any help/pointer .
JC

Running "python configure.py" fails

I have been following the instructions in your README but have hit a dead end when trying to configure the project.

Running python configure.py throws the following error:

Traceback (most recent call last):
File "/home/devops/Desktop/demo-allauth-bootstrap-master/configure.py", line 63, in
settings_template = get_template("settings.template.py")
File "/home/devops/Desktop/demo-allauth-bootstrap-master/env/lib/python3.10/site-packages/django/template/loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: settings.template.py

Login view mixup

I have really enjoyed this template, but i'm having some issues with the view on the Login page. I'm very new to python and Django, so i'm a little confused as to how I could fix this. I traced the url back into the allauth directory inside the virtual environment and found where the login field order was referenced, but changing this had no effect at all. I've never tried to change anything close to this file location so i'm not sure what I would do exactly. The good news is that it still works perfectly!

I am on Linux Ubuntu 14.04 using
Django==1.8.1
django-allauth==0.22.0
django-bootstrap3==7.0.1

djangologin

change syncdb to makemigrations

When databases are initialized using syncdb, changes to the models are not captured when running make migrations / migrate. I changed the makefile's contents to

rebuild:
deldb migratedb initdb

and defined migratedb as

migratedb:
python manage.py makemigrations
python manage.py migrate

Typos

You could fix the following two typos:

allauthdemo/templates/visitor/landing-about.html: "Bootstrap 3" -> "Bootstrap 4"

README.md: "no login reuired" -> "no login required"

Thanks a lot,

Florian La Roche

LookupError: App 'auth' doesn't have a 'demouser' model

When i change the requirements.txt to use django 1.7 or 1.8 with python3
the make rebuild (especially the python manage.py syncdb --noinput
) fails with the following Exception:

LookupError: App 'auth' doesn't have a 'demouser' model

Traceback (most recent call last):
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/apps/config.py", line 163, in get_model
return self.models[model_name.lower()]
KeyError: 'demouser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/management/init.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(_args, *_options.dict)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/management/base.py", line 337, in execute
self.check()
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/management/base.py", line 371, in check
all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/core/checks/registry.py", line 59, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/contrib/auth/checks.py", line 12, in check_user_model
cls = apps.get_model(settings.AUTH_USER_MODEL)
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/apps/registry.py", line 202, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "/home/marcman/git/demo-allauth-bootstrap/allauth/lib/python3.4/site-packages/django/apps/config.py", line 166, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'auth' doesn't have a 'demouser' model.
make: *** [syncdb] Fehler 1

openid_connect example missing

The provider openid_connect is different from the other social auth providers. It is some kind of container for custom OpenID Connect compatible providers. So openid_connect will not be listed as a provider on the provider selection site. Instead the APPS listed in the openid_connect configuration in SOCIALACCOUNT_PROVIDERS should be listed. But this doesn't work in this example. Please provide an example and a guide to add OpenID Connect providers.

Running configure.py doesn't work out of the box

For me, I needed to indicate manually where settings.py is residing (subdir) by the following command:

DJANGO_SETTINGS_MODULE=allauthdemo.settings  python configure.py

I use the same version of Python (2.7.5) as the author and did the same pip install.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.