Skip to content
Snippets Groups Projects
Commit 7bae429f authored by Martin Mareš's avatar Martin Mareš
Browse files

DB: Tabulka registračních tokenů

Chceme umět limitovat četnost registrací a invalidovat už použité
tokeny, takže si všechny dosud neexpirované registrace pamatujeme v DB.
parent 2a429238
No related branches found
No related tags found
1 merge request!86Registrace
......@@ -322,3 +322,24 @@ CREATE TABLE messages (
markdown text NOT NULL,
html text NOT NULL
);
-- Požadavky na registraci a změny vlastností účtu
CREATE TYPE reg_req_type AS ENUM (
'register',
'change',
'reset'
);
CREATE TABLE reg_requests (
reg_id serial PRIMARY KEY,
type reg_req_type NOT NULL,
created_at timestamp with time zone NOT NULL,
expires_at timestamp with time zone NOT NULL,
used_at timestamp with time zone DEFAULT NULL,
email varchar(255) DEFAULT NULL, -- adresa, kterou potvrzujeme
captcha_token varchar(255) DEFAULT NULL, -- token pro fázi 1 registrace
email_token varchar(255) UNIQUE NOT NULL, -- token pro fázi 2 registrace
user_id int DEFAULT NULL REFERENCES users(user_id) ON DELETE CASCADE,
client varchar(255) NOT NULL -- kdo si registraci vyžádal
);
......@@ -14,3 +14,22 @@ ALTER TYPE part_state ADD VALUE 'active' AFTER 'invited';
ALTER TABLE participants ADD COLUMN registered_on timestamp with time zone DEFAULT NULL;
UPDATE participations SET state='active' WHERE state IN ('registered', 'invited');
CREATE TYPE reg_req_type AS ENUM (
'register',
'change',
'reset'
);
CREATE TABLE reg_requests (
reg_id serial PRIMARY KEY,
type reg_req_type NOT NULL,
created_at timestamp with time zone NOT NULL,
expires_at timestamp with time zone NOT NULL,
used_at timestamp with time zone DEFAULT NULL,
email varchar(255) DEFAULT NULL,
captcha_token varchar(255) DEFAULT NULL,
email_token varchar(255) UNIQUE NOT NULL,
user_id int DEFAULT NULL REFERENCES users(user_id) ON DELETE CASCADE,
client varchar(255) NOT NULL
);
......@@ -661,6 +661,29 @@ class Message(Base):
created_by_user = relationship('User')
class RegReqType(MOEnum):
register = auto()
change = auto()
reset = auto()
class RegRequest(Base):
__tablename__ = 'reg_requests'
reg_id = Column(Integer, primary_key=True, server_default=text("nextval('reg_requests_reg_id_seq'::regclass)"))
type = Column(Enum(RegReqType, name='reg_req_type'), nullable=False)
created_at = Column(DateTime(True), nullable=False)
expires_at = Column(DateTime(True), nullable=False)
used_at = Column(DateTime(True))
captcha_token = Column(Text)
email = Column(Text)
email_token = Column(Text, nullable=False, unique=True)
user_id = Column(Integer, ForeignKey('users.user_id'))
client = Column(Text, nullable=False)
user = relationship('User')
_engine: Optional[Engine] = None
_session: Optional[Session] = None
flask_db: Any = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment