Commit 29095a86 authored by ibuler's avatar ibuler

[Demo] update demo mode code

parent cda22a6f
This diff is collapsed.
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# Copyright (C) 2014-2017 Beijing DuiZhan Technology Co.,Ltd. All Rights Reserved.
#
# Licensed under the GNU General Public License v2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.gnu.org/licenses/gpl-2.0.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from rest_framework import viewsets, generics, mixins from rest_framework import viewsets, generics, mixins
......
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
import os import os
import re
import pytz import pytz
from django.utils import timezone from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin from django.utils.deprecation import MiddlewareMixin
...@@ -8,7 +9,7 @@ from django.shortcuts import HttpResponse ...@@ -8,7 +9,7 @@ from django.shortcuts import HttpResponse
DEMO_MODE = os.environ.get("DEMO_MODE", "") DEMO_MODE = os.environ.get("DEMO_MODE", "")
SAFE_URL = ["/users/login",] SAFE_URL = r'^/users/login|^/api/applications/v1/.*'
class TimezoneMiddleware(MiddlewareMixin): class TimezoneMiddleware(MiddlewareMixin):
...@@ -22,5 +23,5 @@ class TimezoneMiddleware(MiddlewareMixin): ...@@ -22,5 +23,5 @@ class TimezoneMiddleware(MiddlewareMixin):
class DemoMiddleware(MiddlewareMixin): class DemoMiddleware(MiddlewareMixin):
def process_request(self, request): def process_request(self, request):
if DEMO_MODE and request.method not in ["GET", "HEAD"] and request.path not in SAFE_URL: if DEMO_MODE and request.method not in ["GET", "HEAD"] and not re.match(SAFE_URL, request.path):
return HttpResponse("Demo mode, only get request accept", 403) return HttpResponse("Demo mode, only get request accept", 403)
...@@ -123,6 +123,7 @@ if CONFIG.DB_ENGINE == 'sqlite': ...@@ -123,6 +123,7 @@ if CONFIG.DB_ENGINE == 'sqlite':
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': CONFIG.DB_NAME or os.path.join(BASE_DIR, 'data', 'db.sqlite3'), 'NAME': CONFIG.DB_NAME or os.path.join(BASE_DIR, 'data', 'db.sqlite3'),
'ATOMIC_REQUESTS': True,
} }
} }
else: else:
...@@ -134,6 +135,7 @@ else: ...@@ -134,6 +135,7 @@ else:
'PORT': CONFIG.DB_PORT, 'PORT': CONFIG.DB_PORT,
'USER': CONFIG.DB_USER, 'USER': CONFIG.DB_USER,
'PASSWORD': CONFIG.DB_PASSWORD, 'PASSWORD': CONFIG.DB_PASSWORD,
'ATOMIC_REQUESTS': True,
} }
} }
......
...@@ -189,7 +189,7 @@ class User(AbstractUser): ...@@ -189,7 +189,7 @@ class User(AbstractUser):
return 'https://www.gravatar.com/avatar/c6812ab450230979465d7bf288eadce2a?s=120&d=identicon' return 'https://www.gravatar.com/avatar/c6812ab450230979465d7bf288eadce2a?s=120&d=identicon'
def generate_reset_token(self): def generate_reset_token(self):
return signer.sign_t({'reset': self.id, 'email': self.email}, expires_in=3600).decode('utf-8') return signer.sign_t({'reset': self.id, 'email': self.email}, expires_in=3600)
def to_json(self): def to_json(self):
return OrderedDict({ return OrderedDict({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment