diff options
-rw-r--r-- | app/backend/rcal/model.py | 29 | ||||
-rw-r--r-- | app/frontend/model/User.php | 3 | ||||
-rw-r--r-- | app/frontend/model/UserAuthKey.php | 33 |
3 files changed, 64 insertions, 1 deletions
diff --git a/app/backend/rcal/model.py b/app/backend/rcal/model.py index 50f9f94..4715657 100644 --- a/app/backend/rcal/model.py +++ b/app/backend/rcal/model.py @@ -5,6 +5,8 @@ from sqlalchemy.orm import relationship from sqlalchemy.types import (TIMESTAMP, Boolean, DateTime, Integer, String, TypeDecorator) +from sqlalchemy_utils import types + from dateutil.tz import tzutc @@ -149,7 +151,34 @@ class User(BASE): grouped_view = Column(Boolean) last_login = Column(UTCDateTime) + auth_keys = relationship( + 'UserAuthKey', + back_populates='user', + cascade="all", + passive_deletes=True, + order_by='UserAuthKey.id') + calendars = relationship('Calendar', secondary=user_selections) + +class UserAuthKey(BASE): + __tablename__ = 'user_auth_keys' + + id = Column(Integer, primary_key=True) + auth_key = Column(String(255), unique=True, index=True) + ip_address = Column(types.IPAddressType) + + _user = Column( + Integer, + ForeignKey( + 'users.id', + onupdate='CASCADE', + ondelete='CASCADE')) + user = relationship( + 'User', + back_populates='auth_keys', + order_by='UserAuthKey.id') + + __all__ = ('Calendar', 'Entry', 'Category', 'User') diff --git a/app/frontend/model/User.php b/app/frontend/model/User.php index 5a20582..043269a 100644 --- a/app/frontend/model/User.php +++ b/app/frontend/model/User.php @@ -28,7 +28,8 @@ class User extends ActiveRecord { ]; public static $RELATIONS = [ - 'Calendars' => [self::MANY_TO_MANY, 'Calendar', 'user_selections'] + 'Calendars' => [self::MANY_TO_MANY, 'Calendar', 'user_selections'], + 'AuthKeys' => [self::HAS_MANY, 'UserAuthKey', '_user'] ]; public static function finder($className=__CLASS__) { diff --git a/app/frontend/model/UserAuthKey.php b/app/frontend/model/UserAuthKey.php new file mode 100644 index 0000000..64d9e65 --- /dev/null +++ b/app/frontend/model/UserAuthKey.php @@ -0,0 +1,33 @@ +<?php + +Prado::using('Application.db.ActiveRecord'); +Prado::using('Application.model.User'); + +class UserAuthKey extends ActiveRecord { + + const TABLE = 'user_auth_keys'; + + public $ID; + public $AuthKey; + public $IPAddress; + + public $UserID; + + public static $COLUMN_MAPPING = [ + 'id' => 'ID', + 'auth_key' => 'AuthKey', + 'ip_address' => 'IPAddress', + '_user' => 'UserID' + ]; + + public static $RELATIONS = [ + 'User' => [self::BELONGS_TO, 'User', '_user'] + ]; + + public static function finder($className=__CLASS__) { + return parent::finder($className); + } + +} + +?> |