Logins seem to work.
[mediagoblin.git] / mediagoblin / models.py
1 # GNU Mediagoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
3 #
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.
8 #
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.
13 #
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/>.
16
17 import datetime
18
19 from mongokit import Document, Set
20
21 from mediagoblin.auth import lib as auth_lib
22
23
24 class MediaEntry(Document):
25 __collection__ = 'media_entries'
26
27 structure = {
28 'title': unicode,
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],
36 'tags': [unicode]}
37
38 required_fields = [
39 'title', 'created',
40 'media_type', 'file_store']
41
42 default_values = {
43 'created': datetime.datetime.utcnow}
44
45 def main_mediafile(self):
46 pass
47
48 class User(Document):
49 __collection__ = 'users'
50
51 structure = {
52 'username': unicode,
53 'email': unicode,
54 'created': datetime.datetime,
55 'plugin_data': dict, # plugins can dump stuff here.
56 'pw_hash': unicode,
57 'email_verified': bool,
58 }
59
60 required_fields = ['username', 'created', 'pw_hash', 'email']
61
62 default_values = {
63 'created': datetime.datetime.utcnow,
64 'email_verified': False}
65
66 def check_login(self, password):
67 """
68 See if a user can login with this password
69 """
70 return auth_lib.bcrypt_check_password(
71 password, self['pw_hash'])
72
73
74 REGISTER_MODELS = [MediaEntry, User]
75
76
77 def register_models(connection):
78 """
79 Register all models in REGISTER_MODELS with this connection.
80 """
81 connection.register(REGISTER_MODELS)
82