husong 7 years ago
commit
db5f0b24e2

+ 0 - 0
README.md


+ 0 - 0
content_manage/__init__.py


BIN
content_manage/__init__.pyc


+ 3 - 0
content_manage/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

BIN
content_manage/admin.pyc


+ 0 - 0
content_manage/migrations/__init__.py


BIN
content_manage/migrations/__init__.pyc


+ 3 - 0
content_manage/models.py

@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.

BIN
content_manage/models.pyc


+ 3 - 0
content_manage/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 3 - 0
content_manage/views.py

@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.

+ 10 - 0
manage.py

@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xdcjing.settings")
+
+    from django.core.management import execute_from_command_line
+
+    execute_from_command_line(sys.argv)

+ 0 - 0
users/__init__.py


BIN
users/__init__.pyc


+ 3 - 0
users/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

BIN
users/admin.pyc


+ 24 - 0
users/migrations/0001_initial.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Users',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('username', models.CharField(default=b'', max_length=32, verbose_name='\u7528\u6237\u540d', blank=True)),
+                ('password', models.CharField(max_length=128, verbose_name='\u5bc6\u7801')),
+                ('status', models.CharField(max_length=64, verbose_name='\u72b6\u6001')),
+                ('permission', models.CharField(max_length=64, verbose_name='\u6743\u9650')),
+                ('signup_time', models.CharField(max_length=64, verbose_name='\u6ce8\u518c\u65f6\u95f4')),
+            ],
+        ),
+    ]

BIN
users/migrations/0001_initial.pyc


+ 0 - 0
users/migrations/__init__.py


BIN
users/migrations/__init__.pyc


+ 13 - 0
users/models.py

@@ -0,0 +1,13 @@
+# -*-coding:utf-8 -*-
+from django.db import models
+
+# Create your models here.
+class Users(models.Model):
+    """
+    用户表
+    """
+    username = models.CharField(u"用户名", max_length=32, blank=True, default="")
+    password = models.CharField(u"密码", max_length=128)
+    status = models.CharField(u"状态", max_length=64)
+    permission = models.CharField(u"权限", max_length=64)
+    signup_time = models.CharField(u"注册时间", max_length=64)

BIN
users/models.pyc


+ 3 - 0
users/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 118 - 0
users/views.py

@@ -0,0 +1,118 @@
+# -*-coding:utf-8 -*-
+import json
+import time
+from django.shortcuts import render
+from django.http import HttpResponse
+from django.core.serializers.json import DjangoJSONEncoder
+from django.contrib.auth.hashers import make_password, check_password
+from django.views.decorators.csrf import csrf_exempt
+from models import *
+
+def JsonResponse(data):
+    response = HttpResponse(json.dumps(data, cls=DjangoJSONEncoder),
+                            content_type="application/json")
+    response['Access-Control-Allow-Origin'] = '*'
+    return response
+
+def params(func):
+    def _wrapper(*args, **kargs):
+        request = args[0]
+        if request.method == "GET":
+            request.PARAMS = request.GET
+        elif request.method == "POST" or request.method == "DELETE":
+            if request.META.get('CONTENT_TYPE') == "application/json":
+                request.PARAMS = json.loads(request.body) if request.body else {}
+            else:
+                request.PARAMS = request.POST
+        elif request.method == "OPTIONS":
+            return JsonResponse({"code": 0, "msg": "success"})
+        else:
+            request.PARAMS = {}
+        return func(*args, **kargs)
+
+    return _wrapper
+
+
+def user_manage(request):
+    user = request.session.get("user", None)
+
+
+@csrf_exempt
+@params
+def signup(request):
+    """
+    用户注册
+    :param request:
+    :return: user
+    """
+    req_params = request.PARAMS
+    if req_params:
+        try:
+            username = req_params.get("username")
+            password = make_password(req_params.get("password"), None,
+                                     "pbkdf2_sha256")
+            status = req_params.get("status")
+            permission = req_params.get("permission")
+
+            print(username,password,status,permission)
+
+            obj, created = Users.objects.get_or_create(username=username)
+            if not created:
+                return JsonResponse({"code": -1, "msg": u"该用户名已被注册"})
+            else:
+                # 保存其他信息
+                obj.username = username
+                obj.password = password
+                obj.status = status
+                obj.permission = permission
+
+                obj.signup_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
+                obj.save()
+
+                return JsonResponse({"code": 0, "msg": u"注册成功"})
+        except:
+            traceback.print_exc()
+    else:
+        return JsonResponse({"code": -1, "msg": u"缺少参数"})
+
+@csrf_exempt
+@params
+def login(request):
+    """
+    用户登录
+    :param request: username, password
+    :return: True / False
+    """
+    data = request.PARAMS
+    username = data.get("username", None)
+    passwd = data.get("password", None)
+
+
+    if not data:
+        return JsonResponse({"code": -1, "msg": u"参数不完整"})
+
+    # 获取user的password
+    try:
+        user = Users.objects.get(username=username)
+    except ObjectDoesNotExist:
+        return JsonResponse({"code": -1, "msg": u"该用户不存在"})
+
+    # 检查密码是否正确
+    check_res = check_password(passwd, user.password)
+    
+    print("***********")
+    print(passwd)
+    print(user.password)
+    print(check_res)
+    if check_res:
+        user_info = {"uid": user.id, "username": user.username,
+                     "status": user.status, "permission": user.permission,}
+
+        request.session["user"] = user_info
+        res = {"code": 0, "msg": "success", "user": user_info}
+    else:
+        res = {"code": -1, "msg": "password wrong!"}
+
+    print "set session: --> ", request.session.get("user", None)
+
+    return JsonResponse(res)

BIN
users/views.pyc


+ 0 - 0
xdcjing/__init__.py


BIN
xdcjing/__init__.pyc


+ 107 - 0
xdcjing/settings.py

@@ -0,0 +1,107 @@
+"""
+Django settings for xdcjing project.
+
+Generated by 'django-admin startproject' using Django 1.8.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.8/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/1.8/ref/settings/
+"""
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+import os
+
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = '@jsw0@n4r#2-+_&5ehr-m(5ux-ams1n4a9+_jm=-*un67%eafl'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'content_manage',
+    'users'
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'django.middleware.security.SecurityMiddleware',
+)
+
+ROOT_URLCONF = 'xdcjing.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = 'xdcjing.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'xdcjing_db',
+        'USER': 'root',
+        'PASSWORD': 'root',
+        'HOST': '127.0.0.1',
+        'PORT': 3306,
+    }
+}
+
+# Internationalization
+# https://docs.djangoproject.com/en/1.8/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/1.8/howto/static-files/
+
+STATIC_URL = '/static/'

BIN
xdcjing/settings.pyc


+ 14 - 0
xdcjing/urls.py

@@ -0,0 +1,14 @@
+from django.conf.urls import include, url
+from django.contrib import admin
+import users.views
+
+urlpatterns = [
+    # Examples:
+    # url(r'^$', 'xdcjing.views.home', name='home'),
+    # url(r'^blog/', include('blog.urls')),
+
+    url(r'^admin/', include(admin.site.urls)),
+    url(r'^login/', users.views.login),
+    url(r'^signup/', users.views.signup),
+
+]

BIN
xdcjing/urls.pyc


+ 16 - 0
xdcjing/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for xdcjing project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xdcjing.settings")
+
+application = get_wsgi_application()

BIN
xdcjing/wsgi.pyc