forked from whtsky/Gather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
57 lines (47 loc) · 1.78 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# coding=utf-8
from __future__ import print_function
import time
import settings
from handlers.utils import username_validator
import hashlib
import pymongo
db = pymongo.Connection(host=settings.mongodb_host,
port=settings.mongodb_port)[settings.database_name]
db.members.create_index([('created', -1)])
db.topics.create_index([('last_reply_time', -1), ('node', 1)])
db.replies.create_index([('topic', 1), ('index', 1)])
db.notifications.create_index([('to', 1), ('created', 1)])
db.links.create_index([('priority', -1)])
if __name__ == '__main__':
username = email = ''
while True:
username = raw_input('username:')
if not username_validator.match(username):
print("Invalid username")
continue
if not db.members.find_one({'name_lower': username.lower()}):
break
else:
print("This username is already registered")
while True:
email = raw_input('email:').lower()
if not db.members.find_one({'email': email}):
break
print("This email is already registered")
password = raw_input('password:')
password = hashlib.sha1(password + username.lower()).hexdigest()
db.members.insert({
'name': username,
'name_lower': username.lower(),
'password': password,
'email': email,
'website': '',
'description': '',
'created': time.time(),
'role': 3,
'language': settings.default_locale,
'like': [], # topics
'follow': [], # users
'favorite': [] # nodes
})