aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/openid
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/plugins/openid')
-rw-r--r--mediagoblin/plugins/openid/README.rst12
-rw-r--r--mediagoblin/plugins/openid/__init__.py6
-rw-r--r--mediagoblin/plugins/openid/forms.py6
-rw-r--r--mediagoblin/plugins/openid/migrations/071abb33d1da_openid_plugin_initial_migration.py54
-rw-r--r--mediagoblin/plugins/openid/store.py6
-rw-r--r--mediagoblin/plugins/openid/views.py5
6 files changed, 74 insertions, 15 deletions
diff --git a/mediagoblin/plugins/openid/README.rst b/mediagoblin/plugins/openid/README.rst
index 870a2b58..1a777336 100644
--- a/mediagoblin/plugins/openid/README.rst
+++ b/mediagoblin/plugins/openid/README.rst
@@ -1,23 +1,23 @@
.. _openid-chapter:
===================
- openid plugin
+ OpenID plugin
===================
-The openid plugin allows user to login to your GNU Mediagoblin instance using
-their openid url.
+The OpenID plugin allows user to login to your GNU MediaGoblin instance using
+their OpenID URL.
This plugin can be enabled alongside :ref:`basic_auth-chapter` and
:ref:`persona-chapter`.
.. note::
- When :ref:`basic_auth-chapter` is enabled alongside this openid plugin, and
- a user creates an account using their openid. If they would like to add a
+ When :ref:`basic_auth-chapter` is enabled alongside this OpenID plugin, and
+ a user creates an account using their OpenID. If they would like to add a
password to their account, they can use the forgot password feature to do
so.
-Set up the openid plugin
+Set up the OpenID plugin
============================
1. Install the ``python-openid`` package.
diff --git a/mediagoblin/plugins/openid/__init__.py b/mediagoblin/plugins/openid/__init__.py
index ca17a7e8..b26087a2 100644
--- a/mediagoblin/plugins/openid/__init__.py
+++ b/mediagoblin/plugins/openid/__init__.py
@@ -19,7 +19,7 @@ import uuid
from sqlalchemy import or_
from mediagoblin.auth.tools import create_basic_user
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, LocalUser
from mediagoblin.plugins.openid.models import OpenIDUserURL
from mediagoblin.tools import pluginapi
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
@@ -67,8 +67,8 @@ def create_user(register_form):
username = register_form.username.data
user = User.query.filter(
or_(
- User.username == username,
- User.email == username,
+ LocalUser.username == username,
+ LocalUser.email == username,
)).first()
if not user:
diff --git a/mediagoblin/plugins/openid/forms.py b/mediagoblin/plugins/openid/forms.py
index d47369dc..6dfde0c8 100644
--- a/mediagoblin/plugins/openid/forms.py
+++ b/mediagoblin/plugins/openid/forms.py
@@ -23,18 +23,18 @@ class RegistrationForm(wtforms.Form):
openid = wtforms.HiddenField(
'',
[wtforms.validators.InputRequired()])
- username = wtforms.TextField(
+ username = wtforms.StringField(
_('Username'),
[wtforms.validators.InputRequired(),
normalize_user_or_email_field(allow_email=False)])
- email = wtforms.TextField(
+ email = wtforms.StringField(
_('Email address'),
[wtforms.validators.InputRequired(),
normalize_user_or_email_field(allow_user=False)])
class LoginForm(wtforms.Form):
- openid = wtforms.TextField(
+ openid = wtforms.StringField(
_('OpenID'),
[wtforms.validators.InputRequired(),
# Can openid's only be urls?
diff --git a/mediagoblin/plugins/openid/migrations/071abb33d1da_openid_plugin_initial_migration.py b/mediagoblin/plugins/openid/migrations/071abb33d1da_openid_plugin_initial_migration.py
new file mode 100644
index 00000000..b6b97da9
--- /dev/null
+++ b/mediagoblin/plugins/openid/migrations/071abb33d1da_openid_plugin_initial_migration.py
@@ -0,0 +1,54 @@
+"""OpenID plugin initial migration
+
+Revision ID: 071abb33d1da
+Revises: 52bf0ccbedc1
+Create Date: 2016-03-12 23:32:58.191980
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '071abb33d1da'
+down_revision = '52bf0ccbedc1'
+branch_labels = ('openid_plugin',)
+depends_on = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ if op.get_bind().engine.has_table('openid__association'):
+ # Skip; this has already been instantiated
+ # (probably via sqlalchemy-migrate)
+ return
+
+ op.create_table(
+ 'openid__association',
+ sa.Column('server_url', sa.Unicode(), nullable=False),
+ sa.Column('handle', sa.Unicode(), nullable=False),
+ sa.Column('secret', sa.Unicode(), nullable=True),
+ sa.Column('issued', sa.Integer(), nullable=True),
+ sa.Column('lifetime', sa.Integer(), nullable=True),
+ sa.Column('assoc_type', sa.Unicode(), nullable=True),
+ sa.PrimaryKeyConstraint('server_url', 'handle'))
+
+ op.create_table(
+ 'openid__nonce',
+ sa.Column('server_url', sa.Unicode(), nullable=False),
+ sa.Column('timestamp', sa.Integer(), nullable=False),
+ sa.Column('salt', sa.Unicode(), nullable=False),
+ sa.PrimaryKeyConstraint('server_url', 'timestamp', 'salt'))
+
+ op.create_table(
+ 'openid__user_urls',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('openid_url', sa.Unicode(), nullable=False),
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.ForeignKeyConstraint(['user_id'], ['core__users.id'], ),
+ sa.PrimaryKeyConstraint('id'))
+
+
+def downgrade():
+ op.drop_table('openid__user_urls')
+ op.drop_table('openid__nonce')
+ op.drop_table('openid__association')
diff --git a/mediagoblin/plugins/openid/store.py b/mediagoblin/plugins/openid/store.py
index 8f9a7012..24726814 100644
--- a/mediagoblin/plugins/openid/store.py
+++ b/mediagoblin/plugins/openid/store.py
@@ -16,6 +16,8 @@
import base64
import time
+import six
+
from openid.association import Association as OIDAssociation
from openid.store.interface import OpenIDStore
from openid.store import nonce
@@ -34,12 +36,12 @@ class SQLAlchemyOpenIDStore(OpenIDStore):
if not assoc:
assoc = Association()
- assoc.server_url = unicode(server_url)
+ assoc.server_url = six.text_type(server_url)
assoc.handle = association.handle
# django uses base64 encoding, python-openid uses a blob field for
# secret
- assoc.secret = unicode(base64.encodestring(association.secret))
+ assoc.secret = six.text_type(base64.encodestring(association.secret))
assoc.issued = association.issued
assoc.lifetime = association.lifetime
assoc.assoc_type = association.assoc_type
diff --git a/mediagoblin/plugins/openid/views.py b/mediagoblin/plugins/openid/views.py
index bb2de7ab..71f444fa 100644
--- a/mediagoblin/plugins/openid/views.py
+++ b/mediagoblin/plugins/openid/views.py
@@ -13,6 +13,9 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import six
+
from openid.consumer import consumer
from openid.consumer.discover import DiscoveryFailure
from openid.extensions.sreg import SRegRequest, SRegResponse
@@ -186,7 +189,7 @@ def finish_login(request):
if user:
# Set up login in session
- request.session['user_id'] = unicode(user.id)
+ request.session['user_id'] = six.text_type(user.id)
request.session.save()
if request.session.get('next'):