1 # GNU Mediagoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from mongokit
import Document
, Set
21 from mediagoblin
.auth
import lib
as auth_lib
24 class MediaEntry(Document
):
25 __collection__
= 'media_entries'
29 'created': datetime
.datetime
,
30 'description': unicode,
31 'media_type': unicode,
32 'media_data': dict, # extra data relevant to this media_type
33 'plugin_data': dict, # plugins can dump stuff here.
34 'file_store': unicode,
35 'attachments': [dict],
40 'media_type', 'file_store']
43 'created': datetime
.datetime
.utcnow
}
45 def main_mediafile(self
):
49 __collection__
= 'users'
54 'created': datetime
.datetime
,
55 'plugin_data': dict, # plugins can dump stuff here.
57 'email_verified': bool,
60 required_fields
= ['username', 'created', 'pw_hash', 'email']
63 'created': datetime
.datetime
.utcnow
,
64 'email_verified': False}
66 def check_login(self
, password
):
68 See if a user can login with this password
70 return auth_lib
.bcrypt_check_password(
71 password
, self
['pw_hash'])
74 REGISTER_MODELS
= [MediaEntry
, User
]
77 def register_models(connection
):
79 Register all models in REGISTER_MODELS with this connection.
81 connection
.register(REGISTER_MODELS
)