示例#1
0
    def post(self, request):
        pwd1 = request.POST.get('pwd1')
        print(pwd1)
        if pwd1:
            user = request.user
            print(user)
            if user:
                user.set_password(pwd1)
                user.save()
                return restful.ok()
            else:
                return restful.params_error(message='请输入新密码!')

        else:
            return restful.params_error(message='请输入新密码!')
示例#2
0
def new_order(request):
    form = NewOrderForms(request.POST)
    if form.is_valid():
        which_time = form.cleaned_data.get("which_time")
        which_date = form.cleaned_data.get("which_date")
        person_nums = form.cleaned_data.get("person_nums")
        order_tel = form.cleaned_data.get("order_tel")
        order_info = form.cleaned_data.get("order_info")
        goods_pk = form.cleaned_data.get("goods_pk")

        if which_time == "time-am":
            which_time = "上午场"
        else:
            which_time = "下午场"

        if order_tel == '0':
            order_tel = request.user.telephone

        goods = Goods.objects.get(pk=int(goods_pk))
        prices = goods.prices.strip("¥")
        amount = int(prices) * int(person_nums)

        goods_order = GoodsOrder.objects.create(goods=goods, buyer=request.user, which_time=which_time,
                                                which_date=which_date, person_nums=person_nums, amount=amount,
                                                order_info=order_info, order_tel=order_tel, isdeal=1)

        return restful.result(data={"order_id": goods_order.pk})
    else:
        print("fail")
        return restful.params_error(message=form.errors)
示例#3
0
    def post(self, request):
        form = EditGoodsForms(request.POST)
        if form.is_valid():
            title = form.cleaned_data.get('title')
            sales = form.cleaned_data.get('sales')
            prices = form.cleaned_data.get('prices')
            goods_info = form.cleaned_data.get('goods_info')
            feature_info = form.cleaned_data.get('feature_info')
            schedule_goods = form.cleaned_data.get('schedule_goods')
            attention_goods = form.cleaned_data.get('attention_goods')
            thumbnail = form.cleaned_data.get('thumbnail')
            goods_video = form.cleaned_data.get('goods_video')
            pk = form.cleaned_data.get('pk')

            Goods.objects.filter(pk=pk).update(title=title,
                                               sales=sales,
                                               prices=prices,
                                               goods_info=goods_info,
                                               feature_info=feature_info,
                                               schedule_goods=schedule_goods,
                                               attention_goods=attention_goods,
                                               thumbnail=thumbnail,
                                               goods_video=goods_video,
                                               author=request.user)
            return restful.ok()
        else:
            print("fail")
            return restful.params_error(message=form.get_errors())
示例#4
0
def login_view(request):
    """
    表单验证-用户验证-is_active验证-remember
    :param request:
    :return: restful api:json:{"code": 200, "message": "", "data": {}}
    """
    form = LoginForm(request.POST)
    if form.is_valid():
        telephone = form.cleaned_data.get('telephone')
        password = form.cleaned_data.get('password')
        remember = form.cleaned_data.get('remember')
        user = authenticate(telephone=telephone, password=password)  # user验证
        if user:
            login(request, user)  # user登陆
            if remember:
                request.session.set_expiry(None)  # default 2周
                return restful.ok(data='缓存时间为2周')
            else:
                request.session.set_expiry(0)  # 设置存留时间为0,退出就清除
                return restful.ok(data='不保留缓存')

        else:
            return restful.un_auth(message='用户不存在,请确认好重新输入!')
    else:
        errors = form.get_errors()
        return restful.params_error(message=errors)
示例#5
0
    def post(self, request):
        form = WriteScenesForms(request.POST)
        if form.is_valid():
            title = form.cleaned_data.get('title')
            ranking = form.cleaned_data.get('ranking')
            prices = form.cleaned_data.get('prices')
            grade = form.cleaned_data.get('grade')
            scene_info = form.cleaned_data.get('scene_info')
            danger_info = form.cleaned_data.get('danger_info')
            thumbnail = form.cleaned_data.get('thumbnail')
            bigimage = form.cleaned_data.get('bigimage')
            moreimage = form.cleaned_data.get('moreimage')
            scene_video = form.cleaned_data.get('scene_video')

            Scenes.objects.create(title=title,
                                  ranking=ranking,
                                  prices=prices,
                                  grade=grade,
                                  scene_info=scene_info,
                                  danger_info=danger_info,
                                  thumbnail=thumbnail,
                                  bigimage=bigimage,
                                  moreimage=moreimage,
                                  scene_video=scene_video,
                                  author=request.user)
            return restful.ok()
        else:
            print("fail")
            return restful.params_error(message=form.get_errors())
示例#6
0
    def get(self, request):
        email = request.GET.get('email')

        if UserProfile.objects.filter(email=email).first():
            return restful.params_error(message='邮箱已经存在!')

        send_regist_email(email, 6, 'update_email')
        return restful.ok()
示例#7
0
 def post(self, request):
     # 实例form 时,传入instance参数,可绑定对象
     # 此列中绑定了request.user 对象
     form = UpdateUserInfoForm(request.POST, instance=request.user)
     if form.is_valid():
         form.save()
         return restful.ok()
     else:
         print(form.get_error())
         return restful.params_error(message=form.get_error())
示例#8
0
 def post(self, request, *args, **kwargs):
     login_form = LoginForm(request.POST)
     if login_form.is_valid():
         username = login_form.cleaned_data.get('username')
         password = login_form.cleaned_data.get('password')
         remember = login_form.cleaned_data.get('remember')
         user = authenticate(username=username, password=password)
         if user:
             if user.is_active:
                 login(request, user)
                 if remember:
                     request.session.set_expiry(0)
                 return restful.ok()
             else:
                 return restful.unauth(message="您的账户已被冻结!")
         else:
             return restful.params_error(message="用户名或密码错误")
     else:
         return restful.params_error(message=login_form.get_errors())
示例#9
0
 def post(self, request):
     form = UploadAvatarForm(request.POST, request.FILES)
     if form.is_valid():
         avatar = form.cleaned_data.get('avatar_img')
         print(avatar)
         request.user.avatar_img = avatar
         request.user.save()
         return restful.ok()
     else:
         print(form.get_error())
         return restful.params_error(message=form.get_error())
示例#10
0
    def post(self, request):
        form = PublicCommentForm(request.POST)
        if form.is_valid():
            content = form.cleaned_data.get('content')
            content = re.sub(r'(<|&lt;)script.*script(>|&gt;)?', '', content)

            Comment.objects.create(content=content, author=request.user)
            return restful.ok()
        else:
            print("fail")
            return restful.params_error(message=form.get_errors())
示例#11
0
def edit_banner(request):
    form = EditBannerForm(request.POST)
    if form.is_valid():
        pk = form.cleaned_data.get('pk')
        image_url = form.cleaned_data.get('image_url')
        priority = form.cleaned_data.get('priority')
        link_to = form.cleaned_data.get('link_to')

        Banner.objects.filter(pk=pk).update(priority=priority,
                                            image_url=image_url,
                                            link_to=link_to)
        return restful.ok()
    else:
        return restful.params_error(message=form.get_errors())
示例#12
0
def add_banner(request):
    form = AddBannerForm(request.POST)
    if form.is_valid():
        priority = form.cleaned_data.get('priority')
        image_url = form.cleaned_data.get('image_url')
        link_to = form.cleaned_data.get('link_to')
        banner = Banner.objects.create(priority=priority,
                                       image_url=image_url,
                                       link_to=link_to)

        return restful.result(data={"banner_id": banner.pk})
    else:
        print("创建轮播图模型错误")
        return restful.params_error(message=form.get_errors())
示例#13
0
    def post(self, request):
        # form = LoginForm(request.POST)
        # if form.is_valid():
        #     username = form.cleaned_data.get('username')
        #     password = form.cleaned_data.get('password')
        #     print("username:"******"password:"******"user")
        #             return restful.params_error('该用户暂未激活,请前往注册邮箱激活')
        #     else:
        #         return restful.params_error('用户名或密码错误')
        # else:
        #     print(form.errors)
        #     return render(request, 'auth/login.html', {'login_form':form})
        username = request.POST.get('username')
        password = request.POST.get('password')
        # 获取极验,滑动验证码相关参数
        gt = GeetestLib(pc_geetest_id, pc_geetest_key)
        challenge = request.POST.get(gt.FN_CHALLENGE, '')
        validate = request.POST.get(gt.FN_VALIDATE, '')
        seccode = request.POST.get(gt.FN_SECCODE, '')
        status = request.session[gt.GT_STATUS_SESSION_KEY]
        user_id = request.session['user_id']

        if status:
            result = gt.success_validate(challenge, validate, seccode, user_id)
            # print('success result:',result)
        else:
            result = gt.failback_validate(challenge, validate, seccode)
            # print('fail result:',result)

        if result == 1:
            # 验证码正确
            # 利用authenticate()做用户名和密码的校验
            user = authenticate(request, username=username, password=password)
            if user:
                login(request, user)
                return restful.ok()
            else:
                return restful.params_error(message='用户名或密码错误')
        else:
            return restful.noauth(message='请点击验证码进行验证!')
示例#14
0
def register_view(request):
    form = RegisterForm(request.POST)
    if form.is_valid():
        telephone = form.cleaned_data.get('telephone')
        username = form.cleaned_data.get('username')
        email = form.cleaned_data.get('email')
        password = form.cleaned_data.get('password')
        User.objects.create_user(telephone=telephone,
                                 username=username,
                                 email=email,
                                 password=password)
        return restful.ok(data='注册成功!')
    else:
        errors = form.get_errors()
        # return redirect(reverse('bank:register'))
        return restful.params_error(message=errors)
示例#15
0
 def post(self, request, *args, **kwargs):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         username = register_form.cleaned_data.get('username')
         email = register_form.cleaned_data.get('email')
         password1 = register_form.cleaned_data.get('password1')
         password2 = register_form.cleaned_data.get('password2')
         user = User()
         user.username = username
         user.email = email
         user.is_staff = True
         user.password = make_password(password2)
         user.save()
         return restful.ok()
     else:
         return restful.params_error(message=register_form.get_errors())
示例#16
0
 def wrapper(self, *args, **kwargs):
     try:
         return func(self, *args, **kwargs)
     except Exception as e:
         if e.args[0] == 1062:
             return restful.params_error(message='对象已存在!')