Started building out user model and SQLAlchemy modules.
This commit is contained in:
parent
c487d873f0
commit
f1d1e1a8e6
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# Copyright (c) 2013 Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
||||
#
|
||||
# Rookeries is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# Rookeries is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public
|
||||
# License along with Rookeries. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Please share and enjoy!
|
||||
#
|
||||
|
||||
"""
|
||||
Core module that handles database connections in Rookeri.es
|
||||
|
||||
@author: Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
||||
@version: 0.0.2
|
||||
"""
|
||||
|
||||
# TODO Work this up.
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
engine = create_engine("sqlite:////tmp/test.db", convert_unicode=True)
|
||||
|
||||
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))
|
||||
Base = declarative_base()
|
||||
Base.query = db_session.query_property()
|
||||
|
||||
|
||||
def init_db():
|
||||
# import all modules here that might define models so that
|
||||
# they will be registered properly on the metadata. Otherwise
|
||||
# you will have to import them first before calling init_db()
|
||||
import models
|
||||
Base.metadata.create_all(bind=engine)
|
|
@ -17,28 +17,49 @@
|
|||
# Please share and enjoy!
|
||||
#
|
||||
|
||||
# TODO Look into adding in user-login-credentials from Flask-Login?
|
||||
|
||||
"""
|
||||
Models for the core of the Rookeries platform.
|
||||
|
||||
@author: Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
||||
@version: 0.0.1
|
||||
@version: 0.0.2
|
||||
"""
|
||||
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import Column, Integer, String, DateTime
|
||||
from datetime import datetime
|
||||
|
||||
class User(object):
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""
|
||||
User of the Rookeries application.
|
||||
"""
|
||||
|
||||
def __init__(self, username=None, first_name=None, last_name=None, email=None):
|
||||
__tablename__ = "user"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
username = Column(String(48))
|
||||
full_name = Column(String(256))
|
||||
email = Column(String(128))
|
||||
|
||||
password = Column(String)
|
||||
security_update_date = Column(DateTime)
|
||||
|
||||
def __init__(self, username=None, full_name=None, email=None):
|
||||
self.username = username
|
||||
self.first_name = first_name
|
||||
self.last_name = last_name
|
||||
self.full_name = full_name
|
||||
self.email = email
|
||||
|
||||
# TODO Add in user types and permissions?
|
||||
def __repr__(self):
|
||||
return "<User('%s', '%s', '%s')>" % self.username, self.email, self.full_name
|
||||
|
||||
def update_password(self, password_hash=None):
|
||||
self.password = password_hash
|
||||
# TODO Add in check to see the password is some hash?
|
||||
# TODO Use some particular timezone across app in case servers located in different parts of the world?
|
||||
# TODO Consider keeping all security based methods in the security module?
|
||||
self.security_update_date = datetime.now()
|
||||
|
||||
|
||||
class Group(object):
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#
|
||||
|
||||
"""
|
||||
Models for the core of the Rookeries platform.
|
||||
Core module that handles security in Rookeri.es
|
||||
|
||||
@author: Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
||||
@version: 0.0.2
|
||||
|
@ -45,3 +45,4 @@ def generate_user_security_hash(user, site_secret):
|
|||
|
||||
return hasher.hexdigest()
|
||||
|
||||
# TODO Add in user types and permissions?
|
Loading…
Reference in New Issue