Exemple #1
0
    def post(self, request):
        # 接收用户填写的数据,进行绑定
        # 接收
        token = request.POST.get('access_token')
        mobile = request.POST.get('mobile')
        pwd = request.POST.get('pwd')
        sms_code = request.POST.get('sms_code')

        next_url = request.GET.get('state')

        # 验证:非空,格式,短信验证码,与注册相同,不再重复
        # 解密openid
        json = meiduo_signature.loads(token, constants.OPENID_EXPIRES)
        if json is None:
            return http.HttpResponseBadRequest('授权信息已经过期')
        openid = json.get('openid')

        # 处理
        # 1.根据手机号查询用户对象
        try:
            user = User.objects.get(mobile=mobile)
        except:
            # 2.如果未查询到对象,则新建用户对象
            user = User.objects.create_user(username=mobile,
                                            password=pwd,
                                            mobile=mobile)
        else:
            # 3.如果查询到用户对象,则判断密码
            if not user.check_password(pwd):
                # 3.1如果密码错误,则提示
                return http.HttpResponseBadRequest('账号信息无效')
                # 3.2如果密码正确则得到用户对象

        # 4.绑定:创建OAuthQQUser对象
        OAuthQQUser.objects.create(user=user, openid=openid)

        # 5.状态保持
        login(request, user)
        response = redirect(next_url)
        response.set_cookie('username',
                            user.username,
                            max_age=60 * 60 * 24 * 14)

        # 合并购物车
        response = merge_cart_cookie_to_redis(request, response)

        # 响应
        return response
Exemple #2
0
    def get(self, request):
        # 接收
        token = request.GET.get('token')

        # 验证
        if not all([token]):
            return http.HttpResponseBadRequest('参数不完整')
        json = meiduo_signature.loads(token, contants.EMAIL_ACTIVE_EXPIRES)
        if json is None:
            return http.HttpResponseBadRequest('激活链接无效')
        user_id = json.get('user_id')
        # 处理
        try:
            user = User.objects.get(pk=user_id)
        except:
            return http.HttpResponseBadRequest('激活链接无效')
        else:
            user.email_active = True
            user.save()
        # 响应
        return redirect('/info/')
Exemple #3
0
    def post(self, request):
        # 接收:openid,mobile,password,sms_code
        access_token = request.POST.get('access_token')
        mobile = request.POST.get('mobile')
        pwd = request.POST.get('pwd')
        sms_code = request.POST.get('sms_code')
        state = request.GET.get('state', '/')

        # 验证:参考注册的验证
        openid_dict = meiduo_signature.loads(access_token,
                                             constants.OPENID_EXPIRES)
        if openid_dict is None:
            return http.HttpResponseForbidden('授权信息无效,请重新授权')
        openid = openid_dict.get('openid')

        # 处理:初次授权,完成openid与user的绑定
        # 1.判断手机号是否已经使用
        try:
            user = User.objects.get(mobile=mobile)
        except:
            # 2.如果未使用,则新建用户
            user = User.objects.create_user(mobile,
                                            password=pwd,
                                            mobile=mobile)
        else:
            # 3.如果已使用,则验证密码
            # 3.1密码正确,则继续执行
            if not user.check_password(pwd):
                # 3.2密码错误,则提示
                return http.HttpResponseForbidden('手机号已经使用,或密码错误')

        # 4.绑定:新建OAuthQQUser对象
        qquser = OAuthQQUser.objects.create(user=user, openid=openid)
        # 状态保持
        login(request, user)
        response = redirect(state)
        response.set_cookie('username', user.username)

        # 响应
        return response
Exemple #4
0
    def get(self, request):
        # 接收
        token = request.GET.get('token')

        # 验证
        if not all([token]):
            return http.HttpResponseForbidden('参数无效')
        # 解密,获取用户编号
        json_dict = meiduo_signature.loads(token, constants.EMAIL_ACTIVE_EXPIRES)
        if json_dict is None:
            return http.HttpResponseForbidden('激活信息无效')
        user_id = json_dict.get('user_id')

        # 处理
        try:
            user = User.objects.get(pk=user_id)
        except:
            return http.HttpResponseForbidden('用户无效')
        user.email_active = True
        user.save()

        # 响应
        return redirect('/info/')