def login(request): """OpenID Login View""" login_form = auth_forms.LoginForm(request.form) allow_registration = mg_globals.app_config["allow_registration"] # Can't store next in request.GET because of redirects to OpenID provider # Store it in the session next = request.GET.get('next') request.session['next'] = next login_failed = False if request.method == 'POST' and login_form.validate(): return_to = request.urlgen('mediagoblin.plugins.openid.finish_login') success = _start_verification(request, login_form, return_to) if success: return success login_failed = True return render_to_response( request, 'mediagoblin/plugins/openid/login.html', { 'login_form': login_form, 'next': request.session.get('next'), 'login_failed': login_failed, 'post_url': request.urlgen('mediagoblin.plugins.openid.login'), 'allow_registration': allow_registration })
def start_edit(request): """Starts the process of adding an openid url to a users account""" form = auth_forms.LoginForm(request.form) if request.method == 'POST' and form.validate(): query = OpenIDUserURL.query.filter_by( openid_url=form.openid.data).first() user = query.user if query else None if not user: return_to = request.urlgen( 'mediagoblin.plugins.openid.finish_edit') success = _start_verification(request, form, return_to, False) if success: return success else: form.openid.errors.append( _('Sorry, an account is already registered to that OpenID.')) return render_to_response( request, 'mediagoblin/plugins/openid/add.html', { 'form': form, 'post_url': request.urlgen('mediagoblin.plugins.openid.edit') })
def delete_openid(request): """View to remove an openid from a users account""" form = auth_forms.LoginForm(request.form) if request.method == 'POST' and form.validate(): # Check if a user has this openid query = OpenIDUserURL.query.filter_by( openid_url=form.openid.data ) user = query.first().user if query.first() else None if user and user.id == int(request.session['user_id']): count = len(user.openid_urls) if not count > 1 and not user.pw_hash: # Make sure the user has a pw or another OpenID messages.add_message( request, messages.WARNING, _("You can't delete your only OpenID URL unless you" " have a password set")) elif user: # There is a user, but not the same user who is logged in form.openid.errors.append( _('That OpenID is not registered to this account.')) if not form.errors and not request.session.get('messages'): # Okay to continue with deleting openid return_to = request.urlgen( 'mediagoblin.plugins.openid.finish_delete') success = _start_verification(request, form, return_to, False) if success: return success return render_to_response( request, 'mediagoblin/plugins/openid/delete.html', {'form': form, 'post_url': request.urlgen('mediagoblin.plugins.openid.delete')})