1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-25 01:38:08 +00:00

Add last login info for users.

This commit is contained in:
grossmj 2021-06-03 16:57:16 +09:30
parent 4e33d29af8
commit 6fb6a27859
4 changed files with 15 additions and 3 deletions

View File

@ -38,7 +38,7 @@ class Role(BaseTable):
__tablename__ = "roles" __tablename__ = "roles"
role_id = Column(GUID, primary_key=True, default=generate_uuid) role_id = Column(GUID, primary_key=True, default=generate_uuid)
name = Column(String) name = Column(String, unique=True)
description = Column(String) description = Column(String)
is_builtin = Column(Boolean, default=False) is_builtin = Column(Boolean, default=False)
permissions = relationship("Permission", secondary=permission_role_link, back_populates="roles") permissions = relationship("Permission", secondary=permission_role_link, back_populates="roles")

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Table, Boolean, Column, String, ForeignKey, event from sqlalchemy import Table, Boolean, Column, String, DateTime, ForeignKey, event
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from .base import Base, BaseTable, generate_uuid, GUID from .base import Base, BaseTable, generate_uuid, GUID
@ -45,6 +45,7 @@ class User(BaseTable):
email = Column(String, unique=True, index=True) email = Column(String, unique=True, index=True)
full_name = Column(String) full_name = Column(String)
hashed_password = Column(String) hashed_password = Column(String)
last_login = Column(DateTime)
is_active = Column(Boolean, default=True) is_active = Column(Boolean, default=True)
is_superadmin = Column(Boolean, default=False) is_superadmin = Column(Boolean, default=False)
groups = relationship("UserGroup", secondary=user_group_link, back_populates="users") groups = relationship("UserGroup", secondary=user_group_link, back_populates="users")

View File

@ -17,7 +17,7 @@
from uuid import UUID from uuid import UUID
from typing import Optional, List, Union from typing import Optional, List, Union
from sqlalchemy import select, update, delete from sqlalchemy import select, update, delete, func
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload from sqlalchemy.orm import selectinload
@ -140,6 +140,15 @@ class UsersRepository(BaseRepository):
return user return user
if not self._auth_service.verify_password(password, user.hashed_password): if not self._auth_service.verify_password(password, user.hashed_password):
return None return None
# Backup the updated_at value
updated_at = user.updated_at
user.last_login = func.current_timestamp()
await self._db_session.commit()
# Restore the original updated_at value
# so it is not affected by the last login update
user.updated_at = updated_at
await self._db_session.commit()
return user return user
async def get_user_memberships(self, user_id: UUID) -> List[models.UserGroup]: async def get_user_memberships(self, user_id: UUID) -> List[models.UserGroup]:

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from typing import Optional from typing import Optional
from pydantic import EmailStr, BaseModel, Field, SecretStr from pydantic import EmailStr, BaseModel, Field, SecretStr
from uuid import UUID from uuid import UUID
@ -51,6 +52,7 @@ class UserUpdate(UserBase):
class User(DateTimeModelMixin, UserBase): class User(DateTimeModelMixin, UserBase):
user_id: UUID user_id: UUID
last_login: Optional[datetime] = None
is_active: bool = True is_active: bool = True
is_superadmin: bool = False is_superadmin: bool = False