-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanage.py
55 lines (49 loc) · 1.77 KB
/
manage.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
import os
from app import create_app, db
from app.models import User, Role, Post, Comment, tag, Category
from flask.ext.script import Manager, Shell, Command
from flask.ext.migrate import Migrate, MigrateCommand
#app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app = create_app('production')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User, Role=Role, Post=Post, Comment=Comment, tag=tag)
@manager.command
def register():
import getpass
print "-"*64 + "\n" + "** please input your email" + "\n" + "-"*64
email = raw_input().decode("utf-8")
print "-"*64 + "\n" + "** please input your name" + "\n" + "-"*64
name = raw_input().decode("utf-8")
while True:
print "please input your password" + "\n" + "*"*64
password = getpass.getpass().decode("utf-8")
print "please input your password again" + "\n" + "*"*64
password2 = getpass.getpass().decode("utf-8")
if password == password2:
break
print "your email is %s, your name is %s" % (email, name)
print "Reagister? [yes/no]"
selection = raw_input()
if selection == 'no':
exit()
else:
query = User.query.filter_by(email=email).first()
if query:
print "User already exists!!"
else:
user = User(email=email, username=name, password=password)
db.session.add(user)
db.session.commit()
print "Register success!!"
exit()
@manager.command
def blog_init():
db.create_all()
db.session.add(Category(type='default'))
db.session.commit()
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command("db", MigrateCommand)
if __name__ == "__main__":
manager.run()