Skip to content

Commit

Permalink
增加管理员初始化脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
时雨 committed May 13, 2015
1 parent 1496804 commit 3acffc9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions bin/initdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python
#coding=utf-8
__author__ = 'phithon'
import pymongo, yaml, sys, time, bcrypt
try:
input = raw_input
except NameError:
pass

def createAdmin(db, config):
username = input("input admin name: ")
password = input("input admin password: ")
password = bcrypt.hashpw(password, bcrypt.gensalt())
user = {
"username": username,
"password": password,
"power": 20,
"money": config["global"]["init_money"],
"time": time.time(),
"bookmark": [],
"email": "",
"qq": "",
"website": "",
"address": "",
"signal": u"太懒,没有留下任何个人说明",
"openwebsite": 1,
"openqq": 1,
"openemail": 1,
"allowemail": 1,
"logintime": None,
"loginip": None
}
member = db.member
member.insert(user)

def create_index(db):
db.member.create_index("username", unique = True)
db.invite.create_index("code", unique = True)

if __name__ == "__main__":
try:
with open("config.yaml", "r") as fin:
config = yaml.load(fin)
except:
print "cannot find config file"
sys.exit(0)

dbset = config["database"]
client = pymongo.MongoClient(dbset["config"])
db = client[dbset["db"]]
isdo = input("create a admin user(Y/n): ")
if isdo not in ("N", "n"):
createAdmin(db, config)
create_index(db)
2 changes: 2 additions & 0 deletions controller/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def article_action(self, *args, **kwargs):
"open": open
}
})
yield self.message(fromuser=None, touser=post["user"], jump="/post/%s" % id,
content=u"你的文章《%s》被管理员%s了" % (post["title"], u"公开" if open else u"取消公开"))
elif method in ("top", "notop"):
top = True if method == "top" else False
post = yield self.db.article.find_and_modify({
Expand Down

0 comments on commit 3acffc9

Please sign in to comment.