Exemplo n.º 1
0
    def post(self, request):
        # 获取数据
        data = request.POST
        head = request.FILES.get('logo')
        id = request.session.get('ID')
        form = MemberModelForm(data)
        if form.is_valid():
            cleaned_data = form.cleaned_data
            nickname = data.get('nickname')
            gender = data.get('gender')
            birthday = cleaned_data.get('birthday')
            school = data.get('school')
            hometown = data.get('hometown')

            phone = request.session.get('phone')

            # 保存到数据库
            Register.objects.filter(phone=phone).update(nickname=nickname,
                                                        gender=gender,
                                                        birthday=birthday,
                                                        school=school,
                                                        hometown=hometown)

            user = Register.objects.get(pk=id)
            if head is not None:
                user.logo = head
                user.save()
            login(request, user)
            return redirect('user:个人中心')

        else:
            context = {'errors': form.errors}
            return render(request, 'user/infor.html', context=context)
Exemplo n.º 2
0
    def post(self, request):
        # 接受参数
        data = request.POST
        # 验证表单合法
        form = LoginModelForm(data)
        if form.is_valid():

            user = form.cleaned_data['user']
            login(request, user)

            return redirect('user:个人中心')
        else:
            return render(request, 'user/login.html', context={'form': form})
Exemplo n.º 3
0
    def post(self, request):
        #获取数据
        data = request.POST
        #验证合法性
        #操作数据库
        login_form = LoginModelForm(data)
        if login_form.is_valid():
            user = login_form.cleaned_data['user']
            login(request, user)
            #合成响应
            # return redirect('user:个人中心')
            return HttpResponse("ko")

        else:
            return render(request, 'user/login.html', {'form': login_form})
Exemplo n.º 4
0
 def post(self, request):
     id = request.session.get('ID')
     # 接受参数
     data = request.POST
     head = request.FILES.get('head')
     user = Users.objects.get(pk=id)
     if head is not None:
         user.head = head
         user.save()
     login(request, user)
     # 表单验证合法
     form = InforModelForm(data, instance=user)
     if form.is_valid():
         form.save()
         return redirect('user:个人资料')
     else:
         # 提示错误
         context = {'form': form}
         return render(request, 'user/addinfor.html', context=context)
Exemplo n.º 5
0
    def post(self, request):
        data = request.POST
        head = request.FILES.get('head')
        item = UserTable.objects.get(pk=request.session.get('ID'))
        form = AlterInfoModelForm(data, instance=item)
        if form.is_valid():
            # 数据合法
            # 存储数据库
            form.save()
            user = UserTable.objects.get(pk=request.session.get('ID'))
            if head is not None:
                user.head = head
            user.save()
            login(request, user)

            return redirect('user:info')
        else:
            context = {'errors': form.errors, 'data': data}
            return render(request, 'user/infor.html', context=context)
Exemplo n.º 6
0
 def post(self, request):
     # 接收参数
     data = request.POST
     form = LoginModelForm(data)
     if form.is_valid():
         # 根据参数进行判断,通过跳转商品列表
         user = form.cleaned_data.get('user')
         login(request, user)
         referer = request.session.get('referer')
         if referer:
             # 跳转回去
             # 删除session
             del request.session['referer']
             return redirect(referer)
         else:
             # 合成响应, 跳转到个人中心
             return redirect('user:个人中心')
     else:
         # 判断不通过,报错
         return render(request, 'user/login.html', {'form': form})
Exemplo n.º 7
0
 def post(self, request):
     # 获取数据
     data = request.POST
     # 验证数据合法性
     login_form = LoginModelForm(data)
     if login_form.is_valid():
         # 操作数据库
         # 保存登录标识到session中
         user = login_form.cleaned_data['user']
         login(request, user)
         referer = request.session.get('referer')
         if referer:
             #     跳转回去
             del request.session['referer']
             return redirect(referer)
         else:
             # 合成响应, 跳转到个人中心
             return redirect('user:个人中心')
     else:
         context = {'errors': login_form.errors}
         return render(request, 'user/login.html', context=context)
Exemplo n.º 8
0
 def post(self, request):
     # 完成用户信息的更新
     # 接收参数
     # 渲染提交的数据
     data = request.POST
     head = request.FILES.get('head')
     user_id = request.session.get('ID')
     # 操作数据
     user = Users.objects.get(pk=user_id)
     user.my_name = data.get('my_name')
     user.sex = data.get('sex')
     user.birthday = data.get('birthday')
     user.school = data.get('school')
     user.my_home = data.get('my_home')
     user.address = data.get('address')
     if head is not None:
         user.head = head
     user.save()
     # 同时修改session
     login(request, user)
     # 合成响应
     return redirect('user:个人中心')
Exemplo n.º 9
0
 def post(self, request):
     data = request.POST
     # 数据进行合法性验证
     form = LoginModelForm(data)
     if form.is_valid():
         # 如果数据合法
         user = form.cleaned_data.get('user')
         # 设置session
         # request.session['ID'] = user.pk
         # request.session['user_name'] = user.user_name
         # request.session['head'] = user.head
         # request.session.set_expiry(9999)  # 9999秒后就消失
         login(request, user)
         referer = request.session.get('referer')
         if referer:
             del request.session['referer']
             return redirect(referer)
         else:
             return redirect('user:member')
     else:
         # 数据不合法 回显网页
         context = {'data': form.errors}
         return render(request, 'user/login.html', context=context)
Exemplo n.º 10
0
    def post(self, request):
        # 接收参数
        data = request.POST

        # 验证数据的合法性
        form = LoginModelForm(data)
        if form.is_valid():
            # 验证成功
            # 保存登录标识到session中,单独创建一个方法保存,更新个人资料
            user = form.cleaned_data.get('user')
            login(request, user)  # 保存session
            referer = request.session.get('referer')
            if referer:
                # 跳转回去
                # 删除session
                del request.session['referer']
                return redirect(referer)
            else:
            # 合成响应跳转到个体中心
                return redirect('user:个人中心')
        else:
            # 提示错误,重新登录
            return render(request, 'user/login.html', {'form': form})
Exemplo n.º 11
0
 def post(self, request):
     # 接受用户提交的数据
     data = request.POST
     # 判断数据的合法性
     # 创建一个form验证对象
     form = UserLoginModelForm(data)
     # 判断数据的合法性
     if form.is_valid():
         # 在数据合法的情况下
         # 1.<<< 将回传数据的用户信息, 保存在session中
         user = form.cleaned_data.get("user")
         # 2.<<< 将用户信息保存到数据session中
         login(request, user)
         # 判断用户发起要求登录的网址是否存在
         referer = request.session.get("referer")
         # 判断referer是否存在
         if referer:
             return redirect(referer)
         else:
             return redirect('blog:博客首页')
     else:
         # 在数据合法的情况下
         return render(request, 'user/login.html', {"form": form})