Exemple #1
0
def register(request):
    if not 'user' in request.session:
        return render(request, 'index.html', {
            'page': 'index',
            'message': 'Please login first'
        })
    elif request.method == 'GET':
        return render(request, 'register.html', {
            'page': 'register',
            'message': ''
        })
    else:
        name = request.POST['username']
        users = User.objects.filter(username__exact=name)
        if users.count() > 0:
            return render(request, 'register.html', {
                'page': 'register',
                'message': 'Username is not available'
            })
        else:
            b = User(username=name,
                     fullname=request.POST['fullname'],
                     password=request.POST['password'])
            b.save()
            return render(
                request, 'content.html', {
                    'page': 'content',
                    'message':
                    'New user registered: ' + request.POST['fullname']
                })
Exemple #2
0
def register(request):
	try:
		# register a new user
		sys_time = str(datetime.datetime.now())
		hash_md5 = hashlib.md5(sys_time)		
		hash_pwd = hashlib.md5(request.POST['password'])

		user_id = hash_md5.hexdigest()
		username = request.POST['username']
		email = request.POST['email']		
		encoded_pwd = hash_pwd.hexdigest()
		
		user = User(user_id = user_id, name = username, email = email, password = encoded_pwd)
		user.save()
		cust_id = user.id		
		print "auto customer id: %d" % cust_id

	except KeyError:
		render(request, 'demo/user.html', {
			'error_message': "Username has already existed!"
			})

	# redirect back to businesses page
	else:
		# reverse to business page 1
		return HttpResponseRedirect(reverse('demo:business', args = (1, cust_id,)))
def store(request):
    data = {
        'name': request.POST.get('name'),
        'email': request.POST.get('email')
    }
    p = User(name=request.POST.get('name'), email=request.POST.get('email'))
    p.save()
    return render(request, "show.html", data)
Exemple #4
0
    def save(self, user=None):
        if not user:
            user = User()
        user.name = self.name.data

        user.save()
        db.session.commit()
        user = User.get(user.id)
        return user
Exemple #5
0
def registerdone(request):
        user = User(
            username=request.POST.get( 'ID', False ),
            last_name=request.POST.get( 'NAME', False ),
            email=request.POST.get( 'EMAIL', False )
        )
        user.set_password(request.POST.get('PWD',False))
        user.save()
        return render(request,'demo/registerdone.html')
Exemple #6
0
def register_page(request):
    result = '请输入用户名、密码'
    register_username = request.POST.get('register_username')
    register_password = request.POST.get('register_password')
    register_email = request.POST.get('register_email')
    exist_user = User.objects.filter(username=register_username)
    if exist_user:
        result = '用户名已存在'
        return render(request, 'register.html', {'result': result})

    if register_username != '':
        if 6 <= len(str(register_username)) <= 16 and 6 <= len(
                str(register_username)) <= 16:
            for i in register_username:
                if 48 <= ord(i) <= 57 or 65 <= ord(i) <= 90 or ord(
                        i) == 95 or 97 <= ord(i) <= 122:
                    pass
                else:
                    result = "存在不合法字符"
            for i in register_password:
                if 48 <= ord(i) <= 57 or 65 <= ord(i) <= 90 or ord(
                        i) == 95 or 97 <= ord(i) <= 122:
                    pass
                else:
                    result = "存在不合法字符"
            if result != "存在不合法字符":
                u = User()
                u.username = register_username
                u.password = register_password
                u.email = register_email
                u.gendle = request.POST.get('gendle')
                u.birth_place = request.POST.get('birth_place')
                u.university = request.POST.get('university')
                u.age = request.POST.get('age')
                u.weigth = request.POST.get('weigth')
                u.heigth = request.POST.get('heigth')
                u.language = request.POST.get('language')
                u.birthday = request.POST.get('birthday')
                u.question1 = request.POST.get('question1')
                u.answer1 = request.POST.get('answer1')
                u.question2 = request.POST.get('question2')
                u.answer2 = request.POST.get('answer2')
                u.question3 = request.POST.get('question3')
                u.answer3 = request.POST.get('answer3')
                u.save()
                result = '注册成功'
                return redirect('demo:demo_login')
        else:
            result = '请输入6-16位用户名、密码'
    else:
        result = '请输入用户名、密码'
    return render(request, 'register.html', {'result': result})
Exemple #7
0
def reg(request):
    if request.method == "POST":
        uf = UserForm(request.POST, request.FILES)
        if uf.is_valid():
            username = uf.cleaned_data["username"]
            uploadImg = uf.cleaned_data["uploadImg"]
            user = User()
            user.username = username
            user.uploadImg = uploadImg
            user.save()
            return HttpResponse("upload ok!")
    else:
        uf = UserForm()
    return render_to_response("reg.html", {"uf": uf})
Exemple #8
0
def user_list(request, db=0):
    """
    List all users under db, or create a new user.
    """
    if request.method == 'GET':
        users = User.objects.using(db).all()
        serializer = UserSerializer(users, many=True)
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        print("post....")
        data = JSONParser().parse(request)
        serializer = UserSerializer(data=data)
        if serializer.is_valid():
            user = User(name=data['name'])
            user.save()
            # serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
    def post(self, request, *args, **kwargs):
        name = request.POST.get('name')
        imei = request.POST.get('imei')
        enabled = request.POST.get('enabled')
        administrator = request.POST.get('administrator')

        auth = 0
        admin = 0
        if enabled:
            auth = 1

        if administrator:
            admin = 1
            mydevice = MyDevice(name=name, dev_id=imei)
            mydevice.save()

        insert = User(name=name, imei=imei, auth=auth, admin=admin)
        insert.save()
        return redirect('/demo/users')
    def post(self, request, *args, **kwargs):
        name = request.POST.get('name')
        imei = request.POST.get('imei')
        enabled = request.POST.get('enabled')
        administrator = request.POST.get('administrator')

        auth = 0
        admin = 0
        if enabled:
            auth = 1

        if administrator:
            admin = 1
            mydevice = MyDevice(name=name, dev_id=imei)
            mydevice.save()

        insert = User(name=name, imei=imei, auth=auth, admin=admin)
        insert.save()
        return redirect('/demo/users')
 def post(self, request, format=None):
     # delete mappings
     all_mappings = Mapping.objects.all().delete()
     # re-initialize mapping
     sharded_model.init_mapping()
     # delete all objects
     customized_models = importlib.import_module(settings.CUSTOMIZED_MODEL_MODULE)
     shardable_models = settings.SHARDABLE_MODELS.split(',')
     for model in shardable_models:
         for db in settings.DATABASES.keys():
             model_to_del = getattr(customized_models, model)
             model_to_del.objects.using(db).all().delete()
     for i in ['Jack', 'Mengyang', 'Ziyao', 'Shelly', 'Bob', 'Alice']:
         u = User(name=i)
         u.save()
         comment_list = ['Yeah!', 'Sure.', 'OK', 'Wow!', 'Hey!', 'Now?', 'What?', 'Apple', 'Banana', 'Orange', 'Peach', 'No!', 'Yooooo']
         for i in range(5):
             p = Post(shard_key=u, content=random.choice(comment_list))
             p.save()
     return Response(status=status.HTTP_202_ACCEPTED)
Exemple #12
0
def post_list(request, fk):
    """
    List all posts for a user, or create a new post.
    """
    if request.method == 'GET':
        # TODO: need Shelly to debug post get method
        user = User(name=fk)
        posts = Post.objects.get(shard_key=user)
        serializer = PostSerializer(posts, many=True)
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        try:
            print("post post....")
            data = JSONParser().parse(request)
            print(data)
            user = User.objects.get(name=data['shard_key'])
            user.save()
            post = Post(shard_key=user, content=data['content'])
            post.save()
            return JsonResponse(data, status=201)
        except:
            return JsonResponse('Error when creating post', status=400)
Exemple #13
0
def test():
    user = User()
    user.time = datetime.datetime.now()
    user.save()
    print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
Exemple #14
0
 def create(self, validated_data):
     user = User(email=validated_data['email'])
     user.set_password(validated_data['password'])
     user.save()
     return user