コード例 #1
0
 def clean_passcode(self):
     """ check the passcode
     """
     passcode = self.cleaned_data.get('passcode', '')
     site = Utils.get_site(self.request)
     if site and site.get('site_code'):
         if site.get('site_code') != passcode:
             raise forms.ValidationError("Invalid Password.")
     return passcode
コード例 #2
0
ファイル: node.py プロジェクト: jackyu-it/dj_node
 def wrap_inner(*args, **kwargs):
     request = args[1]
     site = Utils.get_site(request)
     if (kwargs.get('ssl')
             and site['site_has_ssl']) and (not request.is_secure()):
         url = request.build_absolute_uri(request.get_full_path())
         url_split = urlsplit(url)
         scheme = 'https' if url_split.scheme == 'http' else url_split.scheme
         ssl_port = 443
         url_secure_split = (
             scheme, "%s:%d" %
             (url_split.hostname or '', ssl_port)) + url_split[2:]
         secure_url = urlunsplit(url_secure_split)
         return HttpResponseRedirect(secure_url)
     else:
         return func(*args, **kwargs)
コード例 #3
0
ファイル: node.py プロジェクト: jackyu-it/dj_node
    def fallback_template(request, filename):
        site = Utils.get_site(request)
        if filename:
            try:
                path = site['site_folder'] + "/themes/" + site[
                    'site_theme'] + "/" + filename
                loader.get_template(path)
                return path
            except (TemplateDoesNotExist, AttributeError), e:
                pass

            try:
                path = "dj_node/" + "themes/" + site[
                    'dj_theme'] + "/" + filename
                loader.get_template(path)
                return path
            except (TemplateDoesNotExist, AttributeError), e:
                pass
コード例 #4
0
ファイル: middlewares.py プロジェクト: jackyu-it/dj_node
    def process_request(self, request):
        if not request.is_secure():
            # get secure url
            site = Utils.get_site(request)
            url = request.build_absolute_uri(request.get_full_path())
            url_split = urlsplit(url)
            scheme = 'https' if url_split.scheme == 'http' else url_split.scheme
            ssl_port = 443
            url_secure_split = (scheme, "%s:%d" % (url_split.hostname or '', ssl_port)) + url_split[2:]
            secure_url = urlunsplit(url_secure_split)

            # enforce url for site
            if (site['site_https'] and site['site_has_ssl']):
                return HttpResponseRedirect(secure_url)

            # enforce https for /admin
            if (request.get_full_path().lower().startswith('/admin') and site['site_has_ssl']):
                return HttpResponseRedirect(secure_url)
コード例 #5
0
    def _process(self, request):
        # create the token
        raw_email = self.cleaned_data.get('email', '')
        t = Token(
            domain=Utils.get_domain(request),
            email=raw_email,
            token=Token.generate_token(),
            type='reset_password',
            used=False,
            expired=datetime.datetime.now() + datetime.timedelta(days=3),
        )
        t.save()

        # create the email
        site = Utils.get_site(self.request)
        if site and site.get('email_manager'):
            from_email = site.get('email_manager')
        else:
            raise Exception("No account email set.")  # pragma: no cover
        domain = Utils.get_domain(request)
        link = reverse('reset-password', kwargs={'code': t.token})
        subject = "Reset your password"
        msg_plain = "Click there link to reset your password: <a href=\"%s\">%s</a>" % (
            link, link)

        t.url = link
        t.save()

        # send email
        try:
            EmailUtils.send_email(from_email, raw_email, subject, msg_plain)
        except Exception, e:  # pragma: no cover
            return {
                'return': 302,  # pragma: no cover
                'msg': 'Oop, we are having diffculty to send you email',
                'redirect_url': reverse('login')
            }