Esempio n. 1
0
def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, 'email')
    else:
        form = form_class()

    backends = load_backends(BACKENDS).keys()

    # Redirect if there is only one backend
    if len(backends) == 1 and backends[0] != 'email':
        return redirect('social:begin', backends[0])

    backends = set(backends)

    return render(
        request,
        'accounts/register.html',
        {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        }
    )
Esempio n. 2
0
def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, 'email')
    else:
        form = form_class()

    backends = load_backends(BACKENDS).keys()

    # Redirect if there is only one backend
    if len(backends) == 1 and backends[0] != 'email':
        return redirect('social:begin', backends[0])

    backends = set(backends)

    return render(
        request, 'accounts/register.html', {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        })
Esempio n. 3
0
def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    return render(
        request,
        "accounts/register.html",
        {
            "registration_email": "email" in backends,
            "registration_backends": backends - set(["email"]),
            "title": _("User registration"),
            "form": form,
        },
    )
Esempio n. 4
0
def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    backends = load_backends(BACKENDS).keys()

    # Redirect if there is only one backend
    if len(backends) == 1 and backends[0] != "email":
        return redirect("social:begin", backends[0])

    backends = set(backends)

    return render(
        request,
        "accounts/register.html",
        {
            "registration_email": "email" in backends,
            "registration_backends": backends - set(["email"]),
            "title": _("User registration"),
            "form": form,
        },
    )
Esempio n. 5
0
def reset_password(request):
    '''
    Password reset handling.
    '''
    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['email']
            user.set_unusable_password()
            user.save()
            if not request.session.session_key:
                request.session.create()
            request.session['password_reset'] = True
            return complete(request, 'email')
    else:
        form = ResetForm()

    return render(
        request,
        'accounts/reset.html',
        {
            'title': _('Password reset'),
            'form': form,
        }
    )
Esempio n. 6
0
def reset_password(request):
    '''
    Password reset handling.
    '''
    if 'email' not in load_backends(BACKENDS).keys():
        messages.error(
            request,
            _('Can not reset password, email authentication is disabled!')
        )
        return redirect('login')

    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['email']
            user.set_unusable_password()
            user.save()
            if not request.session.session_key:
                request.session.create()
            request.session['password_reset'] = True
            return complete(request, 'email')
    else:
        form = ResetForm()

    return render(
        request,
        'accounts/reset.html',
        {
            'title': _('Password reset'),
            'form': form,
        }
    )
Esempio n. 7
0
 def get(self, request, *args, **kwargs):
     backend = kwargs.pop('backend')
     try:
         return complete(request, backend, *args, **kwargs)
     except AuthFailed:
         messages.error(request, "Your domain isn't authorized")
         return HttpResponseRedirect(reverse('login'))
Esempio n. 8
0
def reset_password(request):
    """
    Password reset handling.
    """
    if "email" not in load_backends(BACKENDS).keys():
        messages.error(request, _("Can not reset password, email authentication is disabled!"))
        return redirect("login")

    if request.method == "POST":
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["email"]
            user.set_unusable_password()
            user.save()

            # Force creating new session
            request.session.create()
            if request.user.is_authenticated():
                logout(request)

            request.session["password_reset"] = True
            return complete(request, "email")
    else:
        form = ResetForm()

    return render(request, "accounts/reset.html", {"title": _("Password reset"), "form": form})
Esempio n. 9
0
def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    return render_to_response(
        "accounts/register.html",
        RequestContext(
            request,
            {
                "registration_backends": [x for x in load_backends(BACKENDS).keys() if x != "email"],
                "title": _("User registration"),
                "form": form,
            },
        ),
    )
Esempio n. 10
0
def reset_password(request):
    '''
    Password reset handling.
    '''
    if 'email' not in load_backends(BACKENDS).keys():
        messages.error(
            request,
            _('Can not reset password, email authentication is disabled!'))
        return redirect('login')

    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            # Force creating new session
            request.session.create()
            if request.user.is_authenticated():
                logout(request)

            request.session['password_reset'] = True
            return complete(request, 'email')
    else:
        form = ResetForm()

    return render(request, 'accounts/reset.html', {
        'title': _('Password reset'),
        'form': form,
    })
Esempio n. 11
0
def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, 'email')
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    return render(
        request,
        'accounts/register.html',
        {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        }
    )
Esempio n. 12
0
 def get(self, request, *args, **kwargs):
     backend = kwargs.pop('backend')
     try:
         return complete(request, backend, *args, **kwargs)
     except AuthFailed:
         messages.error(request, "Your domain isn't authorized")
         return HttpResponseRedirect(reverse('login'))
Esempio n. 13
0
def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            # Ensure we do registration in separate session
            # not sent to client
            request.session.create()
            result = complete(request, 'email')
            request.session.save()
            request.session = None
            return result
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    # Redirect if there is only one backend
    if len(backends) == 1 and 'email' not in backends:
        return redirect('social:begin', backends.pop())

    return render(
        request, 'accounts/register.html', {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        })
Esempio n. 14
0
def lti_login_and_complete_view(request, backend, *args, **kwargs):
    """This is a combination login/complete due to LTI being a one step login"""

    if request.method != 'POST':
        return HttpResponseNotAllowed('POST')

    request.backend.start()
    return complete(request, backend, *args, **kwargs)
Esempio n. 15
0
def lti_login_and_complete_view(request, backend, *args, **kwargs):
    """This is a combination login/complete due to LTI being a one step login"""

    if request.method != 'POST':
        return HttpResponseNotAllowed('POST')

    request.backend.start()
    return complete(request, backend, *args, **kwargs)
Esempio n. 16
0
 def get(request, *args, **kwargs):
     backend = kwargs.pop('backend')
     try:
         return complete(request, backend, *args, **kwargs)
     except AuthFailed:
         return HttpResponseRedirect(reverse('login'))
     except AuthAlreadyAssociated:
         return HttpResponseRedirect(reverse('login'))
Esempio n. 17
0
 def get(request, *args, **kwargs):
     backend = kwargs.pop('backend')
     try:
         return complete(request, backend, *args, **kwargs)
     except AuthFailed:
         return HttpResponseRedirect(reverse('login'))
     except AuthAlreadyAssociated:
         return HttpResponseRedirect(reverse('login'))
Esempio n. 18
0
def email_login(request):
    """
    Connect email.
    """
    if request.method == "POST":
        form = EmailForm(request.POST)
        if form.is_valid():
            return complete(request, "email")
    else:
        form = EmailForm()

    return render(request, "accounts/email.html", {"title": _("Register email"), "form": form})
Esempio n. 19
0
    def complete(self, **kwargs):
        # Before we proceed the auth, clear the session to ensure that no
        # half-backed registrations are left over (this would result in a
        # redirect to extradata after login even if the logged in user has a
        # complete profile.
        self.request.session.clear()

        # Load social strategy to ensure this request looks like a social auth
        # request.
        self.request.social_strategy = load_strategy(backend='username')

        return complete(self.request, 'username', **kwargs)
Esempio n. 20
0
def email_login(request):
    '''
    Connect email.
    '''
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            return complete(request, 'email')
    else:
        form = EmailForm()

    return render(request, 'accounts/email.html', {
        'title': _('Register email'),
        'form': form,
    })
Esempio n. 21
0
def reset_password(request):
    """
    Password reset handling.
    """
    if request.method == "POST":
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["email"]
            user.set_unusable_password()
            user.save()
            return complete(request, "email")
    else:
        form = ResetForm()

    return render_to_response(
        "accounts/reset.html", RequestContext(request, {"title": _("Password reset"), "form": form})
    )
Esempio n. 22
0
def reset_password(request):
    """
    Password reset handling.
    """
    if request.method == "POST":
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["email"]
            user.set_unusable_password()
            user.save()
            if not request.session.session_key:
                request.session.create()
            request.session["password_reset"] = True
            return complete(request, "email")
    else:
        form = ResetForm()

    return render(request, "accounts/reset.html", {"title": _("Password reset"), "form": form})
Esempio n. 23
0
def email_login(request):
    '''
    Connect email.
    '''
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            return complete(request, 'email')
    else:
        form = EmailForm()

    return render(
        request,
        'accounts/email.html',
        {
            'title': _('Register email'),
            'form': form,
        }
    )
Esempio n. 24
0
def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            # Ensure we do registration in separate session
            # not sent to client
            request.session.create()
            result = complete(request, "email")
            request.session.save()
            request.session = None
            return result
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    # Redirect if there is only one backend
    if len(backends) == 1 and "email" not in backends:
        return redirect("social:begin", backends.pop())

    return render(
        request,
        "accounts/register.html",
        {
            "registration_email": "email" in backends,
            "registration_backends": backends - set(["email"]),
            "title": _("User registration"),
            "form": form,
        },
    )
Esempio n. 25
0
def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            # Ensure we do registration in separate session
            # not sent to client
            request.session.create()
            result = complete(request, 'email')
            request.session.save()
            request.session = None
            return result
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    # Redirect if there is only one backend
    if len(backends) == 1 and 'email' not in backends:
        return redirect('social:begin', backends.pop())

    return render(
        request,
        'accounts/register.html',
        {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        }
    )
Esempio n. 26
0
def reset_password(request):
    '''
    Password reset handling.
    '''
    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['email']
            user.set_unusable_password()
            user.save()
            return complete(request, 'email')
    else:
        form = ResetForm()

    return render_to_response(
        'accounts/reset.html',
        RequestContext(
            request,
            {
                'title': _('Password reset'),
                'form': form,
            }
        )
    )
Esempio n. 27
0
 def get(self, request, backend, *args, **kwargs):
     return complete(request, backend, *args, **kwargs)
Esempio n. 28
0
 def get(self, request, backend, *args, **kwargs):
     return complete(request, backend, *args, **kwargs)