コード例 #1
0
ファイル: valsession.py プロジェクト: matrix-org/sydent
    def getOrCreateTokenSession(
            self, medium: str, address: str,
            clientSecret: str) -> Tuple[ValidationSession, TokenInfo]:
        """
        Retrieves the validation session for a given medium, address and client secret,
        or creates one if none was found.

        :param medium: The medium to use when looking up or creating the session.
        :param address: The address to use when looking up or creating the session.
        :param clientSecret: The client secret to use when looking up or creating the
            session.

        :return: The session that was retrieved or created.
        """
        cur = self.sydent.db.cursor()

        cur.execute(
            "select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
            "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
            "where s.medium = ? and s.address = ? and s.clientSecret = ? and t.validationSession = s.id",
            (medium, address, clientSecret),
        )
        row: Optional[Tuple[int, str, str, str, Optional[int], int, str,
                            int]] = cur.fetchone()

        if row:
            session = ValidationSession(row[0], row[1], row[2], row[3],
                                        bool(row[4]), row[5])
            token_info = TokenInfo(row[6], row[7])
            return session, token_info

        sid = self.addValSession(medium,
                                 address,
                                 clientSecret,
                                 time_msec(),
                                 commit=False)

        tokenString = sydent.util.tokenutils.generateTokenForMedium(medium)

        cur.execute(
            "insert into threepid_token_auths (validationSession, token, sendAttemptNumber) values (?, ?, ?)",
            (sid, tokenString, -1),
        )
        self.sydent.db.commit()

        session = ValidationSession(
            sid,
            medium,
            address,
            clientSecret,
            False,
            time_msec(),
        )
        token_info = TokenInfo(tokenString, -1)
        return session, token_info
コード例 #2
0
ファイル: valsession.py プロジェクト: xcesiv/sydent
    def getOrCreateTokenSession(self, medium, address, clientSecret):
        cur = self.sydent.db.cursor()

        cur.execute(
            "select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
            "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
            "where s.medium = ? and s.address = ? and s.clientSecret = ? and t.validationSession = s.id",
            (medium, address, clientSecret))
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], row[4],
                                  row[5])
            s.token = row[6]
            s.sendAttemptNumber = row[7]
            return s

        sid = self.addValSession(medium,
                                 address,
                                 clientSecret,
                                 time_msec(),
                                 commit=False)

        tokenString = sydent.util.tokenutils.generateTokenForMedium(medium)

        cur.execute(
            "insert into threepid_token_auths (validationSession, token, sendAttemptNumber) values (?, ?, ?)",
            (sid, tokenString, -1))
        self.sydent.db.commit()

        s = ValidationSession(sid, medium, address, clientSecret, False,
                              time_msec())
        s.token = tokenString
        s.sendAttemptNumber = -1
        return s
コード例 #3
0
ファイル: valsession.py プロジェクト: pombredanne/sydent
    def getTokenSessionById(self, sid):
        cur = self.sydent.db.cursor()

        cur.execute("select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
                    "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
                    "where s.id = ? and t.validationSession = s.id", (sid,))
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], row[4], row[5])
            s.token = row[6]
            s.sendAttemptNumber = row[7]
            return s

        return None
コード例 #4
0
ファイル: valsession.py プロジェクト: matrix-org/sydent
    def getTokenSessionById(
            self, sid: int) -> Optional[Tuple[ValidationSession, TokenInfo]]:
        """
        Retrieves a validation session using the session's ID.

        :param sid: The ID of the session to retrieve.

        :return: The validation session, or None if no session was found with that ID.
        """
        cur = self.sydent.db.cursor()

        cur.execute(
            "select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
            "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
            "where s.id = ? and t.validationSession = s.id",
            (sid, ),
        )
        row: Optional[Tuple[int, str, str, str, Optional[int], int, str, int]]
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], bool(row[4]),
                                  row[5])
            t = TokenInfo(row[6], row[7])
            return s, t

        return None
コード例 #5
0
ファイル: valsession.py プロジェクト: xcesiv/sydent
    def getTokenSessionById(self, sid):
        cur = self.sydent.db.cursor()

        cur.execute(
            "select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
            "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
            "where s.id = ? and t.validationSession = s.id", (sid, ))
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], row[4],
                                  row[5])
            s.token = row[6]
            s.sendAttemptNumber = row[7]
            return s

        return None
コード例 #6
0
ファイル: valsession.py プロジェクト: pombredanne/sydent
    def getOrCreateTokenSession(self, medium, address, clientSecret):
        cur = self.sydent.db.cursor()

        cur.execute("select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
                    "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
                    "where s.medium = ? and s.address = ? and s.clientSecret = ? and t.validationSession = s.id",
                    (medium, address, clientSecret))
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], row[4], row[5])
            s.token = row[6]
            s.sendAttemptNumber = row[7]
            return s

        sid = self.addValSession(medium, address, clientSecret, time_msec(), commit=False)

        tokenString = sydent.util.tokenutils.generateNumericTokenOfLength(
            int(self.sydent.cfg.get('email', 'token.length')))

        cur.execute("insert into threepid_token_auths (validationSession, token, sendAttemptNumber) values (?, ?, ?)",
                    (sid, tokenString, -1))
        self.sydent.db.commit()

        s = ValidationSession(sid, medium, address, clientSecret, False, time_msec())
        s.token = tokenString
        s.sendAttemptNumber = -1
        return s
コード例 #7
0
ファイル: valsession.py プロジェクト: xcesiv/sydent
    def getSessionById(self, sid):
        cur = self.sydent.db.cursor()

        cur.execute(
            "select id, medium, address, clientSecret, validated, mtime from "
            + "threepid_validation_sessions where id = ?", (sid, ))
        row = cur.fetchone()

        if not row:
            return None

        return ValidationSession(row[0], row[1], row[2], row[3], row[4],
                                 row[5])
コード例 #8
0
    def getSessionById(self, sid):
        """
        Retrieves the session matching the given sid.

        :param sid: The ID of the session to retrieve.
        :type sid: unicode

        :return: The retrieved session, or None if no session could be found with that
            sid.
        :rtype: ValidationSession or None
        """
        cur = self.sydent.db.cursor()

        cur.execute("select id, medium, address, clientSecret, validated, mtime from "+
            "threepid_validation_sessions where id = ?", (sid,))
        row = cur.fetchone()

        if not row:
            return None

        return ValidationSession(row[0], row[1], row[2], row[3], row[4], row[5], None, None)
コード例 #9
0
    def getTokenSessionById(self, sid):
        """
        Retrieves a validation session using the session's ID.

        :param sid: The ID of the session to retrieve.
        :type sid: unicode

        :return: The validation session, or None if no session was found with that ID.
        :rtype: ValidationSession or None
        """
        cur = self.sydent.db.cursor()

        cur.execute("select s.id, s.medium, s.address, s.clientSecret, s.validated, s.mtime, "
                    "t.token, t.sendAttemptNumber from threepid_validation_sessions s,threepid_token_auths t "
                    "where s.id = ? and t.validationSession = s.id", (sid,))
        row = cur.fetchone()

        if row:
            s = ValidationSession(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7])
            return s

        return None
コード例 #10
0
ファイル: valsession.py プロジェクト: matrix-org/sydent
    def getSessionById(self, sid: int) -> Optional[ValidationSession]:
        """
        Retrieves the session matching the given sid.

        :param sid: The ID of the session to retrieve.

        :return: The retrieved session, or None if no session could be found with that
            sid.
        """
        cur = self.sydent.db.cursor()

        cur.execute(
            "select id, medium, address, clientSecret, validated, mtime from "
            + "threepid_validation_sessions where id = ?",
            (sid, ),
        )
        row: Optional[Tuple[int, str, str, str, Optional[int],
                            int]] = cur.fetchone()

        if not row:
            return None

        return ValidationSession(row[0], row[1], row[2], row[3], bool(row[4]),
                                 row[5])