Beispiel #1
0
def auth_login(request, *args, **kwargs):
    me = 'people'
    nextfield = 'next'

    nexthop = request.GET.get(nextfield, '/')
    if request.method == 'POST':
        nexthop = request.POST.get(nextfield, '/')
        # 1
        if not request.user.is_authenticated():
            username = asciify(
                smart_text(request.POST['username'], errors='ignore').strip())
            password = request.POST['password'].strip()
            # 2
            if username and password:
                _LOG.debug('Form valid')
                try:
                    user = get_user_model().objects.get(username=username)
                    profile = user.profile
                except get_user_model().DoesNotExist:
                    try:
                        userslug = uslugify(username)
                        profile = Profile.objects.get(slug=userslug)
                        user = profile.user
                    except Profile.DoesNotExist:
                        error = "User '%s' does not exist! Typo?" % username
                        messages.error(request, error)
                        _LOG.warn(error)
                        return HttpResponseRedirect(nexthop)
                except Profile.DoesNotExist:
                    error = "User %s is incomplete, lacks profile" % username
                    messages.error(request, error)
                    _LOG.warn(error)
                user = auth.authenticate(username=user.username,
                                         password=password)
                _LOG.info("User: %s", pformat(user))
                if user is not None:
                    auth.login(request, user)

                    check_for_ipv6(request, profile)

                else:
                    _LOG.warn("Invalid user for some reason")
                    error = "Couldn't log you in: Your username and/or password does not match with what is stored here."
                    messages.error(request, error)
                _LOG.info('Redirecting back to %s', nexthop)
                return HttpResponseRedirect(nexthop)
            # /2
        else:
            messages.info(request, 'You are already logged in')
            nexthop = request.user.profile.get_absolute_url()
            return HttpResponseRedirect(nexthop)
        # /1
    data = {'me': me, nextfield: nexthop}
    return render(request, 'login.html', data)
Beispiel #2
0
def auth_login(request, *args, **kwargs):
    me = 'people'
    nextfield = 'next'

    nexthop = request.GET.get(nextfield, '/')
    if request.method == 'POST':
        nexthop = request.POST.get(nextfield, '/')
        # 1
        if not request.user.is_authenticated():
            username = asciify(smart_text(request.POST['username'], errors='ignore').strip())
            password = request.POST['password'].strip()
            # 2
            if username and password:
                _LOG.debug('Form valid')
                try:
                    user = get_user_model().objects.get(username=username)
                    profile = user.profile
                except get_user_model().DoesNotExist:
                    try:
                        userslug = uslugify(username)
                        profile = Profile.objects.get(slug=userslug)
                        user = profile.user
                    except Profile.DoesNotExist:
                        error = "User '%s' does not exist! Typo?" % username
                        messages.error(request, error)
                        _LOG.warn(error)
                        return HttpResponseRedirect(nexthop)
                except Profile.DoesNotExist:
                    error = "User %s is incomplete, lacks profile" % username
                    messages.error(request, error)
                    _LOG.warn(error)
                user = auth.authenticate(username=user.username, password=password)
                _LOG.info("User: %s", pformat(user))
                if user is not None:
                    auth.login(request, user)

                    check_for_ipv6(request, profile)

                else:
                    _LOG.warn("Invalid user for some reason")
                    error = "Couldn't log you in: Your username and/or password does not match with what is stored here."
                    messages.error(request, error)
                _LOG.info('Redirecting back to %s', nexthop)
                return HttpResponseRedirect(nexthop)
            # /2
        else:
            messages.info(request, 'You are already logged in')
            nexthop = request.user.profile.get_absolute_url()
            return HttpResponseRedirect(nexthop)
        # /1
    data = {'me': me, nextfield: nexthop}
    return render(request, 'login.html', data)
Beispiel #3
0
    def save(self, user=None, solo=True, *args, **kwargs):
        now = tznow()
        # New lang
        if not self.id and user:
            self.added_by = user
            self.manager = user
        if solo:
            self.last_modified = now
            if user:
                self.last_modified_by = user
            else:
                self.last_modified_by = self.manager
        if not self.internal_name:
            self.internal_name = self.name
            self.name = asciify(self.name)
        self.slug = self.get_slug()

        if not self.manager:
            self.manager = self.added_by or user
        # XXX Cannot set average score here as there would be an
        # import-loop
        super(Language, self).save(*args, **kwargs)

        self.save_langnames(now=now)
Beispiel #4
0
    def save(self, user=None, solo=True, *args, **kwargs):
        now = tznow()
        # New lang
        if not self.id and user:
            self.added_by = user
            self.manager = user
        if solo:
            self.last_modified = now
            if user:
                self.last_modified_by = user
            else:
                self.last_modified_by = self.manager
        if not self.internal_name:
            self.internal_name = self.name
            self.name = asciify(self.name)
        self.slug = self.get_slug()

        if not self.manager:
            self.manager = self.added_by or user
        # XXX Cannot set average score here as there would be an
        # import-loop
        super(Language, self).save(*args, **kwargs)

        self.save_langnames(now=now)