예제 #1
0
def authkey_handler(key, user, **kwargs):
    extra = key.extra
    action = extra.get('action')

    if 'activation' == action:
        if not user.is_active:
            user.is_active = True
            user.save()
            email_template(user.email, 'account/mail/welcome',
                user=user, domain=Site.objects.get_current().domain)

    if user.is_active:
        if 'new_email' == action:
            if 'email' in extra:
                user.email = extra['email']
                user.save()
예제 #2
0
def registration(request, form_class=RegistrationForm):
    if not REGISTRATION_ENABLED:
        return message(request, _('Sorry. Registration is disabled.'))
    if request.user.is_authenticated():
        return message(request, _('You have to logout before registration'))

    if 'POST' == request.method:
        form = form_class(request.POST, request.FILES)
    else:
        form = form_class()

    if form.is_valid():
        user = form.save()

        signals.account_created.send(None, user=user, request=request)
        password = form.cleaned_data['password']

        if ACTIVATION_REQUIRED:
            url = 'http://%s%s' % (hostname, reverse('registration_complete'))
            url = wrap_url(url, uid=user.id, action='activation')
            params = {'domain': hostname, 'login': user.username, 'url': url, 'password': password}
            if email_template(user.email, 'account/mail/activation_required',
                **params):
                return HttpResponseRedirect(reverse('activation_required'))
            else:
                user.delete()
                return message(request, _('''The error was occuried while
                    sending email with activation code. Account was not
                    created. Please, try later.'''))
        else:
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            args = {'domain': hostname, 'user': user, 'password': password}
            email_template(user.email, 'account/mail/registration_complete',
                **args)
            return redirect(reverse(REGISTRATION_REDIRECT_URLNAME))

    return {'form': form,}
예제 #3
0
def email_change(request):
    if 'POST' == request.method:
        form = EmailChangeForm(request.POST)
    else:
        form = EmailChangeForm()

    if form.is_valid():
        email = form.cleaned_data['email']
        url = 'http://%s%s' % (hostname, reverse('auth_email_change_done'))
        url = wrap_url(url, uid=request.user.id, action='new_email', email=email)
        args = {'domain': hostname, 'url': url, 'email': email,}
        if email_template(email, 'account/mail/email_change', **args):
            return message(request, _('Check the mail please'))
        else:
            return message(request, _('Unfortunately we could not send you email in current time. Please, try later'))
    return {'form': form,}
예제 #4
0
def password_reset(request, form_class=PasswordResetForm):
    if 'POST' == request.method:
        form = form_class(request.POST)
    else:
        form = form_class()

    if form.is_valid():
        user = UserModel.objects.get(email=form.cleaned_data['email'])
        url = 'http://%s%s' % (hostname, reverse('auth_password_change'))
        url = wrap_url(url, uid=user.id, onetime=False,
            action='password_change')
        args = {'domain': hostname, 'url': url, 'user': user}
        if email_template(user.email, 'account/mail/password_reset', **args):
            return message(request, _('Check the mail please'))
        else:
            return message(request, _('''Unfortunately we could not send you
                email in current time. Please, try later'''))

    return {'form': form,}