def create(self,validated_data):
       user = User.objects.create(
           email=validated_data['email'],
           first_name=validated_data['first_name'],
           last_name=validated_data['last_name'],
           password=validated_data['password'],
           mobile=validated_data['mobile'],
           address=validated_data['address']
 
           )
       user.save()
       subject = "G-strore User Registration Confirmation"
       mail.sendmail(message.text_message(user.first_name,crypto.decrypt(user.password)),subject,[user.email])
       return user
Beispiel #2
0
def before_request():
    request.is_admin = False
    auth = request.cookies.get('auth')
    # print(auth)
    if auth is not None:
        plain = decrypt(auth).decode()
        print(plain)
        if plain == 0:
            raise AuthExcp(500, "invalid auth")

        try:
            j = json.loads(plain)
        except Exception as e:
            print(e)
            raise AuthExcp(500, "invalid json")
        request.is_admin = j["admin"]
        if not j["admin"]:
            raise AuthExcp(500, "Are you the manager?")
    else:
        j = {"uid": 100, "admin": False}
        resp = redirect('/')
        resp.set_cookie("auth", encrypt(json.dumps(j)))
        return resp
Beispiel #3
0
    def process_request(self, request):
        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        path = request.path

        if path.startswith('/api/'):
            return None

        data = request.body

        num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        data = data[4:]

        for i in range(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                # TODO Check Version
                pass
            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session
                decrypted_session = ""
                if msg_id not in MSG_TYPE_EMPTY_SESSION:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)

                request._proto = p
                request._session = decrypted_session

                splited_session = decrypted_session.split(':')
                len_of_splited_session = len(splited_session)
                if len_of_splited_session == 1:
                    request._account_id = None
                    request._server_id = None
                    request._char_id = None
                elif len_of_splited_session == 2:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = None
                else:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = int(splited_session[2])
                    print "CHAR ID =", request._char_id
Beispiel #4
0
    def process_request(self, request):
        path = request.path

        if path.startswith('/api/') or path.startswith(
                '/system/') or path.startswith('/callback/'):
            return None

        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        data = request.body

        try:
            num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        except:
            print "==== ERROR ===="
            traceback.print_exc()
            return HttpResponse(status=403)

        if num_of_msgs > MAX_NUM_FIELD_AMOUNT:
            print "==== ERROR ===="
            print "NUM_OF_MSGS TOO BIG! {0} > {1}".format(
                num_of_msgs, MAX_NUM_FIELD_AMOUNT)
            return HttpResponse(status=403)

        data = data[4:]

        for i in xrange(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                proto = protomsg.VersionCheckRequest()
                try:
                    proto.ParseFromString(msg)
                except:
                    print "PARSE VERSION_CHECK_REQUEST ERROR"
                    return HttpResponse(status=403)

                if not version.is_valid(proto.version):
                    print "==== VERSION CHECK FAILURE ===="
                    print "==== client: {0} ====".format(proto.version)
                    print "==== server: {0} ====".format(version.version)

                    raise VersionCheckFailure()

            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session

                if msg_id in MSG_TYPE_EMPTY_SESSION:
                    decrypted_session = EmptyGameSession
                else:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)
                    decrypted_session = session_loads(decrypted_session)

                request._proto = p
                request._game_session = decrypted_session

                request._account_id = request._game_session.account_id
                request._server_id = request._game_session.server_id
                request._char_id = request._game_session.char_id

                print "CHAR ID =", request._char_id

        if getattr(request, '_proto', None) is None:
            print "==== ERROR ===="
            print "requests has no proto"
            return HttpResponse(status=403)
Beispiel #5
0
    def process_request(self, request):
        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        path = request.path

        if path.startswith('/api/'):
            return None

        data = request.body

        num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        data = data[4:]

        for i in range(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                # TODO Check Version
                pass
            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session
                decrypted_session = ""
                if msg_id not in MSG_TYPE_EMPTY_SESSION:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)

                request._proto = p
                request._session = decrypted_session

                splited_session = decrypted_session.split(':')
                len_of_splited_session = len(splited_session)
                if len_of_splited_session == 1:
                    request._account_id = None
                    request._server_id = None
                    request._char_id = None
                elif len_of_splited_session == 2:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = None
                else:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = int(splited_session[2])
                    print "CHAR ID =", request._char_id
Beispiel #6
0
    def process_request(self, request):
        path = request.path

        if path.startswith('/api/') or path.startswith('/system/') or path.startswith('/callback/'):
            return None

        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        data = request.body

        try:
            num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        except:
            print "==== ERROR ===="
            traceback.print_exc()
            return HttpResponse(status=403)

        if num_of_msgs > MAX_NUM_FIELD_AMOUNT:
            print "==== ERROR ===="
            print "NUM_OF_MSGS TOO BIG! {0} > {1}".format(num_of_msgs, MAX_NUM_FIELD_AMOUNT)
            return HttpResponse(status=403)

        data = data[4:]

        for i in xrange(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                proto = protomsg.VersionCheckRequest()
                try:
                    proto.ParseFromString(msg)
                except:
                    print "PARSE VERSION_CHECK_REQUEST ERROR"
                    return HttpResponse(status=403)

                if not version.is_valid(proto.version):
                    print "==== VERSION CHECK FAILURE ===="
                    print "==== client: {0} ====".format(proto.version)
                    print "==== server: {0} ====".format(version.version)

                    raise VersionCheckFailure()

            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session

                if msg_id in MSG_TYPE_EMPTY_SESSION:
                    decrypted_session = EmptyGameSession
                else:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)
                    decrypted_session = session_loads(decrypted_session)

                request._proto = p
                request._game_session = decrypted_session

                request._account_id = request._game_session.account_id
                request._server_id = request._game_session.server_id
                request._char_id = request._game_session.char_id

                print "CHAR ID =", request._char_id

        if getattr(request, '_proto', None) is None:
            print "==== ERROR ===="
            print "requests has no proto"
            return HttpResponse(status=403)