Remove Mozilla Persona plugin [#5512].
Mozilla persona is RIP since 2016. Signed-off-by: Ben Sturmfels <ben@sturm.com.au>
This commit is contained in:
parent
63ab28795a
commit
ec74b6d032
@ -60,7 +60,6 @@ Part 2: Core plugin documentation
|
|||||||
plugindocs/flatpagesfile
|
plugindocs/flatpagesfile
|
||||||
plugindocs/ldap
|
plugindocs/ldap
|
||||||
plugindocs/openid
|
plugindocs/openid
|
||||||
plugindocs/persona
|
|
||||||
plugindocs/raven
|
plugindocs/raven
|
||||||
plugindocs/sampleplugin
|
plugindocs/sampleplugin
|
||||||
plugindocs/subtitles
|
plugindocs/subtitles
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
.. include:: ../../../mediagoblin/plugins/persona/README.rst
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
.. _persona-chapter:
|
|
||||||
|
|
||||||
================
|
|
||||||
persona plugin
|
|
||||||
================
|
|
||||||
|
|
||||||
The persona plugin allows users to login to you GNU MediaGoblin instance using
|
|
||||||
`Mozilla Persona`_.
|
|
||||||
|
|
||||||
This plugin can be enabled alongside :ref:`openid-chapter` and
|
|
||||||
:ref:`basic_auth-chapter`.
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
When :ref:`basic_auth-chapter` is enabled alongside this persona plugin, and
|
|
||||||
a user creates an account using their persona. If they would like to add a
|
|
||||||
password to their account, they can use the forgot password feature to do
|
|
||||||
so.
|
|
||||||
|
|
||||||
.. _Mozilla Persona: https://www.mozilla.org/en-US/persona/
|
|
||||||
|
|
||||||
Set up the persona plugin
|
|
||||||
=========================
|
|
||||||
|
|
||||||
1. Install the ``requests`` package.
|
|
||||||
|
|
||||||
2. Add the following to your MediaGoblin .ini file in the ``[plugins]`` section::
|
|
||||||
|
|
||||||
[[mediagoblin.plugins.persona]]
|
|
||||||
|
|
||||||
3. Run::
|
|
||||||
|
|
||||||
gmg dbupdate
|
|
||||||
|
|
||||||
in order to create and apply migrations to any database tables that the
|
|
||||||
plugin requires.
|
|
||||||
|
|
||||||
4. Run::
|
|
||||||
|
|
||||||
gmg assetlink
|
|
||||||
|
|
||||||
in order to persona's static assets.
|
|
@ -1,116 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
from pkg_resources import resource_filename
|
|
||||||
import os
|
|
||||||
|
|
||||||
from sqlalchemy import or_
|
|
||||||
|
|
||||||
from mediagoblin.auth.tools import create_basic_user
|
|
||||||
from mediagoblin.db.models import User, LocalUser
|
|
||||||
from mediagoblin.plugins.persona.models import PersonaUserEmails
|
|
||||||
from mediagoblin.tools import pluginapi
|
|
||||||
from mediagoblin.tools.staticdirect import PluginStatic
|
|
||||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
|
||||||
|
|
||||||
PLUGIN_DIR = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_plugin():
|
|
||||||
config = pluginapi.get_config('mediagoblin.plugins.persona')
|
|
||||||
|
|
||||||
routes = [
|
|
||||||
('mediagoblin.plugins.persona.login',
|
|
||||||
'/auth/persona/login/',
|
|
||||||
'mediagoblin.plugins.persona.views:login'),
|
|
||||||
('mediagoblin.plugins.persona.register',
|
|
||||||
'/auth/persona/register/',
|
|
||||||
'mediagoblin.plugins.persona.views:register'),
|
|
||||||
('mediagoblin.plugins.persona.edit',
|
|
||||||
'/edit/persona/',
|
|
||||||
'mediagoblin.plugins.persona.views:edit'),
|
|
||||||
('mediagoblin.plugins.persona.add',
|
|
||||||
'/edit/persona/add/',
|
|
||||||
'mediagoblin.plugins.persona.views:add')]
|
|
||||||
|
|
||||||
pluginapi.register_routes(routes)
|
|
||||||
pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
|
|
||||||
pluginapi.register_template_hooks(
|
|
||||||
{'persona_end': 'mediagoblin/plugins/persona/persona_js_end.html',
|
|
||||||
'persona_form': 'mediagoblin/plugins/persona/persona.html',
|
|
||||||
'edit_link': 'mediagoblin/plugins/persona/edit_link.html',
|
|
||||||
'login_link': 'mediagoblin/plugins/persona/login_link.html',
|
|
||||||
'register_link': 'mediagoblin/plugins/persona/register_link.html'})
|
|
||||||
|
|
||||||
|
|
||||||
def create_user(register_form):
|
|
||||||
if 'persona_email' in register_form:
|
|
||||||
username = register_form.username.data
|
|
||||||
user = User.query.filter(
|
|
||||||
or_(
|
|
||||||
LocalUser.username == username,
|
|
||||||
LocalUser.email == username,
|
|
||||||
)).first()
|
|
||||||
|
|
||||||
if not user:
|
|
||||||
user = create_basic_user(register_form)
|
|
||||||
|
|
||||||
new_entry = PersonaUserEmails()
|
|
||||||
new_entry.persona_email = register_form.persona_email.data
|
|
||||||
new_entry.user_id = user.id
|
|
||||||
new_entry.save()
|
|
||||||
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
def extra_validation(register_form):
|
|
||||||
persona_email = register_form.persona_email.data if 'persona_email' in \
|
|
||||||
register_form else None
|
|
||||||
if persona_email:
|
|
||||||
persona_email_exists = PersonaUserEmails.query.filter_by(
|
|
||||||
persona_email=persona_email
|
|
||||||
).count()
|
|
||||||
|
|
||||||
extra_validation_passes = True
|
|
||||||
|
|
||||||
if persona_email_exists:
|
|
||||||
register_form.persona_email.errors.append(
|
|
||||||
_('Sorry, an account is already registered to that Persona'
|
|
||||||
' email.'))
|
|
||||||
extra_validation_passes = False
|
|
||||||
|
|
||||||
return extra_validation_passes
|
|
||||||
|
|
||||||
|
|
||||||
def Auth():
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def add_to_global_context(context):
|
|
||||||
if len(pluginapi.hook_runall('authentication')) == 1:
|
|
||||||
context['persona_auth'] = True
|
|
||||||
context['persona'] = True
|
|
||||||
return context
|
|
||||||
|
|
||||||
hooks = {
|
|
||||||
'setup': setup_plugin,
|
|
||||||
'authentication': Auth,
|
|
||||||
'auth_extra_validation': extra_validation,
|
|
||||||
'auth_create_user': create_user,
|
|
||||||
'template_global_context': add_to_global_context,
|
|
||||||
'static_setup': lambda: PluginStatic(
|
|
||||||
'coreplugin_persona',
|
|
||||||
resource_filename('mediagoblin.plugins.persona', 'static'))
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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 wtforms
|
|
||||||
|
|
||||||
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
|
|
||||||
from mediagoblin.auth.tools import normalize_user_or_email_field
|
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(wtforms.Form):
|
|
||||||
username = wtforms.StringField(
|
|
||||||
_('Username'),
|
|
||||||
[wtforms.validators.InputRequired(),
|
|
||||||
normalize_user_or_email_field(allow_email=False)])
|
|
||||||
email = wtforms.StringField(
|
|
||||||
_('Email address'),
|
|
||||||
[wtforms.validators.InputRequired(),
|
|
||||||
normalize_user_or_email_field(allow_user=False)])
|
|
||||||
persona_email = wtforms.HiddenField(
|
|
||||||
'',
|
|
||||||
[wtforms.validators.InputRequired(),
|
|
||||||
normalize_user_or_email_field(allow_user=False)])
|
|
||||||
|
|
||||||
|
|
||||||
class EditForm(wtforms.Form):
|
|
||||||
email = wtforms.StringField(
|
|
||||||
_('Email address'),
|
|
||||||
[wtforms.validators.InputRequired(),
|
|
||||||
normalize_user_or_email_field(allow_user=False)])
|
|
@ -1,35 +0,0 @@
|
|||||||
"""Persona plugin initial migration
|
|
||||||
|
|
||||||
Revision ID: c7d4840a5592
|
|
||||||
Revises: 52bf0ccbedc1
|
|
||||||
Create Date: 2016-03-12 23:30:33.624390
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'c7d4840a5592'
|
|
||||||
down_revision = '52bf0ccbedc1'
|
|
||||||
branch_labels = ('persona_plugin',)
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
if op.get_bind().engine.has_table('persona__user_emails'):
|
|
||||||
# Skip; this has already been instantiated
|
|
||||||
# (probably via sqlalchemy-migrate)
|
|
||||||
return
|
|
||||||
|
|
||||||
op.create_table(
|
|
||||||
'persona__user_emails',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('persona_email', 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('persona__user_emails')
|
|
@ -1,36 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
from sqlalchemy import Column, Integer, Unicode, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, backref
|
|
||||||
|
|
||||||
from mediagoblin.db.models import User
|
|
||||||
from mediagoblin.db.base import Base
|
|
||||||
|
|
||||||
|
|
||||||
class PersonaUserEmails(Base):
|
|
||||||
__tablename__ = "persona__user_emails"
|
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
|
||||||
persona_email = Column(Unicode, nullable=False)
|
|
||||||
user_id = Column(Integer, ForeignKey(User.id), nullable=False)
|
|
||||||
|
|
||||||
# Persona's are owned by their user, so do the full thing.
|
|
||||||
user = relationship(User, backref=backref('persona_emails',
|
|
||||||
cascade='all, delete-orphan'))
|
|
||||||
|
|
||||||
MODELS = [
|
|
||||||
PersonaUserEmails
|
|
||||||
]
|
|
File diff suppressed because one or more lines are too long
@ -1,43 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
{% extends "mediagoblin/base.html" %}
|
|
||||||
|
|
||||||
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
|
|
||||||
|
|
||||||
{% block title -%}
|
|
||||||
{% trans %}Add an OpenID{% endtrans %} — {{ super() }}
|
|
||||||
{%- endblock %}
|
|
||||||
|
|
||||||
{% block mediagoblin_content %}
|
|
||||||
<form action="{{ request.urlgen('mediagoblin.plugins.persona.edit') }}"
|
|
||||||
method="POST" enctype="multipart/form-data">
|
|
||||||
{{ csrf_token }}
|
|
||||||
<div class="form_box">
|
|
||||||
<h1>{% trans %}Delete a Persona email address{% endtrans %}</h1>
|
|
||||||
<p>
|
|
||||||
<a href="javascript:;" id="persona_login">
|
|
||||||
{% trans %}Add a Persona email address{% endtrans %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{{ wtforms_util.render_divs(form, True) }}
|
|
||||||
<div class="form_submit_buttons">
|
|
||||||
<input type="submit" value="{% trans %}Delete{% endtrans %}" class="button_form"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
|
@ -1,24 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
|
|
||||||
{% block persona_edit_link %}
|
|
||||||
<a href="{{ request.urlgen('mediagoblin.plugins.persona.edit') }}">
|
|
||||||
{% trans %}Persona's{% endtrans %}
|
|
||||||
</a>
|
|
||||||
·
|
|
||||||
{% endblock %}
|
|
@ -1,25 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
|
|
||||||
{% block person_login_link %}
|
|
||||||
<p>
|
|
||||||
<a href="javascript:;" id="persona_login">
|
|
||||||
{% trans %}Or login with Persona!{% endtrans %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{% endblock %}
|
|
@ -1,38 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
{% block persona %}
|
|
||||||
<form id="_persona_login"
|
|
||||||
action=
|
|
||||||
{%- if edit_persona is defined -%}
|
|
||||||
"{{ request.urlgen('mediagoblin.plugins.persona.add') }}"
|
|
||||||
{%- else -%}
|
|
||||||
"{{ request.urlgen('mediagoblin.plugins.persona.login') }}"
|
|
||||||
{%- endif %}
|
|
||||||
method="POST">
|
|
||||||
{{ csrf_token }}
|
|
||||||
<input type="hidden" name="assertion" type="text" id="_assertion"/>
|
|
||||||
<input type="hidden" name="_logout_url" type="text" id="_logout_url"
|
|
||||||
value="{{ request.urlgen('mediagoblin.auth.logout') }}"/>
|
|
||||||
<input type="hidden" type="text" id="_persona_user"
|
|
||||||
{% if request.session.get('persona_login_email', False) %}
|
|
||||||
value="{{ request.session['persona_login_email'] }}"/>
|
|
||||||
{% else %}
|
|
||||||
value=""/>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
|
@ -1,21 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
|
|
||||||
<script src="https://login.persona.org/include.js"></script>
|
|
||||||
<script type="text/javascript"
|
|
||||||
src="{{ request.staticdirect('/js/persona.js', 'coreplugin_persona') }}"></script>
|
|
@ -1,25 +0,0 @@
|
|||||||
{#
|
|
||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#}
|
|
||||||
|
|
||||||
{% block persona_register_link %}
|
|
||||||
<p>
|
|
||||||
<a href="javascript:;" id="persona_login">
|
|
||||||
{% trans %}Or register with Persona!{% endtrans %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{% endblock %}
|
|
@ -1,194 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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 json
|
|
||||||
import logging
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from werkzeug.exceptions import BadRequest
|
|
||||||
|
|
||||||
from mediagoblin import messages, mg_globals
|
|
||||||
from mediagoblin.auth.tools import register_user
|
|
||||||
from mediagoblin.decorators import (auth_enabled, allow_registration,
|
|
||||||
require_active_login)
|
|
||||||
from mediagoblin.tools.response import render_to_response, redirect
|
|
||||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
|
||||||
from mediagoblin.plugins.persona import forms
|
|
||||||
from mediagoblin.plugins.persona.models import PersonaUserEmails
|
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_response(request):
|
|
||||||
if 'assertion' not in request.form:
|
|
||||||
_log.debug('assertion not in request.form')
|
|
||||||
raise BadRequest()
|
|
||||||
|
|
||||||
data = {'assertion': request.form['assertion'],
|
|
||||||
'audience': request.urlgen('index', qualified=True)}
|
|
||||||
resp = requests.post('https://verifier.login.persona.org/verify',
|
|
||||||
data=data, verify=True)
|
|
||||||
|
|
||||||
if resp.ok:
|
|
||||||
verification_data = json.loads(resp.content)
|
|
||||||
|
|
||||||
if verification_data['status'] == 'okay':
|
|
||||||
return verification_data['email']
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@auth_enabled
|
|
||||||
def login(request):
|
|
||||||
if request.method == 'GET':
|
|
||||||
return redirect(request, 'mediagoblin.auth.login')
|
|
||||||
|
|
||||||
email = _get_response(request)
|
|
||||||
if email:
|
|
||||||
query = PersonaUserEmails.query.filter_by(
|
|
||||||
persona_email=email
|
|
||||||
).first()
|
|
||||||
user = query.user if query else None
|
|
||||||
|
|
||||||
if user:
|
|
||||||
request.session['user_id'] = str(user.id)
|
|
||||||
request.session['persona_login_email'] = email
|
|
||||||
request.session.save()
|
|
||||||
|
|
||||||
return redirect(request, "index")
|
|
||||||
|
|
||||||
else:
|
|
||||||
if not mg_globals.app.auth:
|
|
||||||
messages.add_message(
|
|
||||||
request,
|
|
||||||
messages.WARNING,
|
|
||||||
_('Sorry, authentication is disabled on this instance.'))
|
|
||||||
|
|
||||||
return redirect(request, 'index')
|
|
||||||
|
|
||||||
register_form = forms.RegistrationForm(email=email,
|
|
||||||
persona_email=email)
|
|
||||||
return render_to_response(
|
|
||||||
request,
|
|
||||||
'mediagoblin/auth/register.html',
|
|
||||||
{'register_form': register_form,
|
|
||||||
'post_url': request.urlgen(
|
|
||||||
'mediagoblin.plugins.persona.register')})
|
|
||||||
|
|
||||||
return redirect(request, 'mediagoblin.auth.login')
|
|
||||||
|
|
||||||
|
|
||||||
@allow_registration
|
|
||||||
@auth_enabled
|
|
||||||
def register(request):
|
|
||||||
if request.method == 'GET':
|
|
||||||
# Need to connect to persona before registering a user. If method is
|
|
||||||
# 'GET', then this page was acessed without logging in first.
|
|
||||||
return redirect(request, 'mediagoblin.auth.login')
|
|
||||||
register_form = forms.RegistrationForm(request.form)
|
|
||||||
|
|
||||||
if register_form.validate():
|
|
||||||
user = register_user(request, register_form)
|
|
||||||
|
|
||||||
if user:
|
|
||||||
# redirect the user to their homepage... there will be a
|
|
||||||
# message waiting for them to verify their email
|
|
||||||
return redirect(
|
|
||||||
request, 'mediagoblin.user_pages.user_home',
|
|
||||||
user=user.username)
|
|
||||||
|
|
||||||
return render_to_response(
|
|
||||||
request,
|
|
||||||
'mediagoblin/auth/register.html',
|
|
||||||
{'register_form': register_form,
|
|
||||||
'post_url': request.urlgen('mediagoblin.plugins.persona.register')})
|
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
|
||||||
def edit(request):
|
|
||||||
form = forms.EditForm(request.form)
|
|
||||||
|
|
||||||
if request.method == 'POST' and form.validate():
|
|
||||||
query = PersonaUserEmails.query.filter_by(
|
|
||||||
persona_email=form.email.data)
|
|
||||||
user = query.first().user if query.first() else None
|
|
||||||
|
|
||||||
if user and user.id == int(request.user.id):
|
|
||||||
count = len(user.persona_emails)
|
|
||||||
|
|
||||||
if count > 1 or user.pw_hash:
|
|
||||||
# User has more then one Persona email or also has a password.
|
|
||||||
query.first().delete()
|
|
||||||
|
|
||||||
messages.add_message(
|
|
||||||
request,
|
|
||||||
messages.SUCCESS,
|
|
||||||
_('The Persona email address was successfully removed.'))
|
|
||||||
|
|
||||||
return redirect(request, 'mediagoblin.edit.account')
|
|
||||||
|
|
||||||
elif not count > 1:
|
|
||||||
form.email.errors.append(
|
|
||||||
_("You can't delete your only Persona email address unless"
|
|
||||||
" you have a password set."))
|
|
||||||
|
|
||||||
else:
|
|
||||||
form.email.errors.append(
|
|
||||||
_('That Persona email address is not registered to this'
|
|
||||||
' account.'))
|
|
||||||
|
|
||||||
return render_to_response(
|
|
||||||
request,
|
|
||||||
'mediagoblin/plugins/persona/edit.html',
|
|
||||||
{'form': form,
|
|
||||||
'edit_persona': True})
|
|
||||||
|
|
||||||
|
|
||||||
@require_active_login
|
|
||||||
def add(request):
|
|
||||||
if request.method == 'GET':
|
|
||||||
return redirect(request, 'mediagoblin.plugins.persona.edit')
|
|
||||||
|
|
||||||
email = _get_response(request)
|
|
||||||
|
|
||||||
if email:
|
|
||||||
query = PersonaUserEmails.query.filter_by(
|
|
||||||
persona_email=email
|
|
||||||
).first()
|
|
||||||
user_exists = query.user if query else None
|
|
||||||
|
|
||||||
if user_exists:
|
|
||||||
messages.add_message(
|
|
||||||
request,
|
|
||||||
messages.WARNING,
|
|
||||||
_('Sorry, an account is already registered with that Persona'
|
|
||||||
' email address.'))
|
|
||||||
return redirect(request, 'mediagoblin.plugins.persona.edit')
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Save the Persona Email to the user
|
|
||||||
new_entry = PersonaUserEmails()
|
|
||||||
new_entry.persona_email = email
|
|
||||||
new_entry.user_id = request.user.id
|
|
||||||
new_entry.save()
|
|
||||||
|
|
||||||
request.session['persona_login_email'] = email
|
|
||||||
|
|
||||||
messages.add_message(
|
|
||||||
request,
|
|
||||||
messages.SUCCESS,
|
|
||||||
_('Your Persona email address was saved successfully.'))
|
|
||||||
|
|
||||||
return redirect(request, 'mediagoblin.edit.account')
|
|
@ -1,42 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
[mediagoblin]
|
|
||||||
direct_remote_path = /test_static/
|
|
||||||
email_sender_address = "notice@mediagoblin.example.org"
|
|
||||||
email_debug_mode = true
|
|
||||||
|
|
||||||
# TODO: Switch to using an in-memory database
|
|
||||||
sql_engine = "sqlite:///%(here)s/user_dev/mediagoblin.db"
|
|
||||||
|
|
||||||
# Celery shouldn't be set up by the application as it's setup via
|
|
||||||
# mediagoblin.init.celery.from_celery
|
|
||||||
celery_setup_elsewhere = true
|
|
||||||
|
|
||||||
[storage:publicstore]
|
|
||||||
base_dir = %(here)s/user_dev/media/public
|
|
||||||
base_url = /mgoblin_media/
|
|
||||||
|
|
||||||
[storage:queuestore]
|
|
||||||
base_dir = %(here)s/user_dev/media/queue
|
|
||||||
|
|
||||||
[celery]
|
|
||||||
CELERY_ALWAYS_EAGER = true
|
|
||||||
CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
|
|
||||||
BROKER_HOST = "sqlite:///%(here)s/user_dev/kombu.db"
|
|
||||||
|
|
||||||
[plugins]
|
|
||||||
[[mediagoblin.plugins.persona]]
|
|
||||||
|
|
@ -1,221 +0,0 @@
|
|||||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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 pkg_resources
|
|
||||||
import pytest
|
|
||||||
try:
|
|
||||||
from unittest import mock
|
|
||||||
except ImportError:
|
|
||||||
import unittest.mock as mock
|
|
||||||
|
|
||||||
import urllib.parse as urlparse
|
|
||||||
|
|
||||||
pytest.importorskip("requests")
|
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
|
||||||
from mediagoblin.db.base import Session
|
|
||||||
from mediagoblin.db.models import Privilege, LocalUser
|
|
||||||
from mediagoblin.tests.tools import get_app
|
|
||||||
from mediagoblin.tools import template
|
|
||||||
|
|
||||||
|
|
||||||
# App with plugin enabled
|
|
||||||
@pytest.fixture()
|
|
||||||
def persona_plugin_app(request):
|
|
||||||
return get_app(
|
|
||||||
request,
|
|
||||||
mgoblin_config=pkg_resources.resource_filename(
|
|
||||||
'mediagoblin.tests.auth_configs',
|
|
||||||
'persona_appconfig.ini'))
|
|
||||||
|
|
||||||
|
|
||||||
class TestPersonaPlugin:
|
|
||||||
def test_authentication_views(self, persona_plugin_app):
|
|
||||||
res = persona_plugin_app.get('/auth/login/')
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/'
|
|
||||||
|
|
||||||
res = persona_plugin_app.get('/auth/register/')
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/'
|
|
||||||
|
|
||||||
res = persona_plugin_app.get('/auth/persona/login/')
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/auth/login/'
|
|
||||||
|
|
||||||
res = persona_plugin_app.get('/auth/persona/register/')
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/auth/login/'
|
|
||||||
|
|
||||||
@mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='test@example.com'))
|
|
||||||
def _test_registration():
|
|
||||||
# No register users
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/auth/persona/login/', {})
|
|
||||||
|
|
||||||
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
|
|
||||||
register_form = context['register_form']
|
|
||||||
|
|
||||||
assert register_form.email.data == 'test@example.com'
|
|
||||||
assert register_form.persona_email.data == 'test@example.com'
|
|
||||||
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/auth/persona/register/', {})
|
|
||||||
|
|
||||||
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
|
|
||||||
register_form = context['register_form']
|
|
||||||
|
|
||||||
assert register_form.username.errors == ['This field is required.']
|
|
||||||
assert register_form.email.errors == ['This field is required.']
|
|
||||||
assert register_form.persona_email.errors == ['This field is required.']
|
|
||||||
|
|
||||||
# Successful register
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/auth/persona/register/',
|
|
||||||
{'username': 'chris',
|
|
||||||
'email': 'chris@example.com',
|
|
||||||
'persona_email': 'test@example.com'})
|
|
||||||
res.follow()
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
|
|
||||||
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
|
|
||||||
# Try to register same Persona email address
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/auth/persona/register/',
|
|
||||||
{'username': 'chris1',
|
|
||||||
'email': 'chris1@example.com',
|
|
||||||
'persona_email': 'test@example.com'})
|
|
||||||
|
|
||||||
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
|
|
||||||
register_form = context['register_form']
|
|
||||||
|
|
||||||
assert register_form.persona_email.errors == ['Sorry, an account is already registered to that Persona email.']
|
|
||||||
|
|
||||||
# Logout
|
|
||||||
persona_plugin_app.get('/auth/logout/')
|
|
||||||
|
|
||||||
# Get user and detach from session
|
|
||||||
test_user = mg_globals.database.LocalUser.query.filter(
|
|
||||||
LocalUser.username=='chris'
|
|
||||||
).first()
|
|
||||||
active_privilege = Privilege.query.filter(
|
|
||||||
Privilege.privilege_name=='active').first()
|
|
||||||
test_user.all_privileges.append(active_privilege)
|
|
||||||
test_user.save()
|
|
||||||
test_user = mg_globals.database.LocalUser.query.filter(
|
|
||||||
LocalUser.username=='chris'
|
|
||||||
).first()
|
|
||||||
Session.expunge(test_user)
|
|
||||||
|
|
||||||
# Add another user for _test_edit_persona
|
|
||||||
persona_plugin_app.post(
|
|
||||||
'/auth/persona/register/',
|
|
||||||
{'username': 'chris1',
|
|
||||||
'email': 'chris1@example.com',
|
|
||||||
'persona_email': 'test1@example.com'})
|
|
||||||
|
|
||||||
# Log back in
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/auth/persona/login/')
|
|
||||||
res.follow()
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/'
|
|
||||||
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
|
|
||||||
# Make sure user is in the session
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
|
||||||
session = context['request'].session
|
|
||||||
assert session['user_id'] == str(test_user.id)
|
|
||||||
|
|
||||||
_test_registration()
|
|
||||||
|
|
||||||
@mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='new@example.com'))
|
|
||||||
def _test_edit_persona():
|
|
||||||
# Try and delete only Persona email address
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/',
|
|
||||||
{'email': 'test@example.com'})
|
|
||||||
|
|
||||||
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
|
|
||||||
form = context['form']
|
|
||||||
|
|
||||||
assert form.email.errors == ["You can't delete your only Persona email address unless you have a password set."]
|
|
||||||
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/', {})
|
|
||||||
|
|
||||||
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
|
|
||||||
form = context['form']
|
|
||||||
|
|
||||||
assert form.email.errors == ['This field is required.']
|
|
||||||
|
|
||||||
# Try and delete Persona not owned by the user
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/',
|
|
||||||
{'email': 'test1@example.com'})
|
|
||||||
|
|
||||||
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
|
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
|
|
||||||
form = context['form']
|
|
||||||
|
|
||||||
assert form.email.errors == ['That Persona email address is not registered to this account.']
|
|
||||||
|
|
||||||
res = persona_plugin_app.get('/edit/persona/add/')
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/edit/persona/'
|
|
||||||
|
|
||||||
# Add Persona email address
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/add/')
|
|
||||||
res.follow()
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
|
|
||||||
|
|
||||||
# Delete a Persona
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/',
|
|
||||||
{'email': 'test@example.com'})
|
|
||||||
res.follow()
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
|
|
||||||
|
|
||||||
_test_edit_persona()
|
|
||||||
|
|
||||||
@mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='test1@example.com'))
|
|
||||||
def _test_add_existing():
|
|
||||||
template.clear_test_template_context()
|
|
||||||
res = persona_plugin_app.post(
|
|
||||||
'/edit/persona/add/')
|
|
||||||
res.follow()
|
|
||||||
|
|
||||||
assert urlparse.urlsplit(res.location)[2] == '/edit/persona/'
|
|
||||||
|
|
||||||
_test_add_existing()
|
|
Loading…
x
Reference in New Issue
Block a user