예제 #1
0
파일: api.py 프로젝트: cp1059/server
    def register(self, request):

        """
        普通玩家注册
        :param request:
        :return:
        """

        if Users.objects.filter(loginname=request.data_format.get('loginname')).count():
            raise PubErrorCustom("该账号已存在!")

        user = Users.objects.create(**{
            "userid":idGenerator.userid("2001"),
            "name": request.data_format.get("loginname",""),
            "loginname":request.data_format.get("loginname",""),
            "passwd": request.data_format.get("password", ""),
            "mobile": request.data_format.get("mobile", ""),
            "code": request.data_format.get("code", ""),
            "rolecode":"2001"
        })
        token = get_token()
        res = UserModelSerializerToRedis(user, many=False).data
        RedisTokenHandler(key=token).redis_dict_set(res)

        return {"data": {
            "token": token,
            "userinfo": {
                "rolecode": user.rolecode
            }
        }}
예제 #2
0
파일: api.py 프로젝트: cp1059/server
    def login2(self, request):
        """
        试玩玩家
        :param request:
        :return:
        """
        user = Users.objects.create(**{
            "userid": idGenerator.userid("2002"),
            "rolecode": "2002",
            "bal":1000.0
        })
        user.name = user.userid
        user.loginname = user.userid
        user.save()

        token = get_token()
        res = UserModelSerializerToRedis(user, many=False).data
        RedisTokenHandler(key=token).redis_dict_set(res)

        return {"data": {
            "token": token,
            "userinfo":{
                "rolecode":user.rolecode
            }
        }}
예제 #3
0
    def wechatlogin(self, request):

        session_key = request.data_format.get("session_key")
        appId = WECHAT_APPID
        sessionKey = session_key
        encryptedData = request.data_format.get("encryptedData")
        iv = request.data_format.get("iv")

        pc = WXBizDataCrypt(appId, sessionKey)

        res = pc.decrypt(encryptedData, iv)

        try:
            user = UserModelSerializerToRedis(Users.objects.get(uuid=res.get('openId') if 'unionId' not in res else res['unionId']),many=False).data
        except Users.DoesNotExist:
            user = Users.objects.create(**{
                "userid": idGenerator.userid('4001'),
                "uuid": res.get('openId') if 'unionId' not in res else res['unionId'],
                "mobile": res.get('openId') if 'unionId' not in res else res['unionId'],
                "rolecode": '4001',
                "name": res.get("nickName"),
                "sex": res.get("sex"),
                "addr": "{}-{}-{}".format(res.get("country"), res.get("city"), res.get("province")),
                "pic": res.get("avatarUrl"),
                "appid": res.get("watermark")['appid']
            })
        token = get_token()
        res = UserModelSerializerToRedis(user, many=False).data
        RedisTokenHandler(key=token).redis_dict_set(res)
        print(token)
        return {"data": {
            "user": UsersSerializers(user, many=False).data,
            "token": token
        }}
예제 #4
0
파일: api.py 프로젝트: gzshop/server
    def login1(self, request):

        try:
            user = Users.objects.get(uuid=request.data_format.get("mobile",""))
        except Users.DoesNotExist:
            user = Users.objects.create(**{
                "userid": idGenerator.userid('4001'),
                "uuid": request.data_format.get("mobile",""),
                "rolecode": '4001',
                "mobile": request.data_format.get("mobile",""),
                "name": request.data_format.get("mobile",""),
                "sex": "",
                "addr": "",
                "pic": "",
                "appid": ""
            })

        if not request.data_format.get('vercode',None):
            raise PubErrorCustom("验证码不能为空!")

        rRes = RedisVercodeHandler().get(user.uuid)
        if rRes and not len(rRes) or not rRes:
            raise PubErrorCustom("请先获取验证码!")

        if request.data_format.get('vercode',None) != rRes:
            raise PubErrorCustom("验证码错误!")

        token = get_token()
        res = UserModelSerializerToRedis(user, many=False).data
        RedisTokenHandler(key=token).redis_dict_set(res)

        res=Address.objects.filter(userid=user.userid,moren='0')
        address = AddressModelSerializer(res, many=True).data[0] if res.count() else {}

        return {"data": {
            "token": token,
            "userinfo":UsersSerializers(user, many=False).data,
            "address":address
        }}