-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
43 lines (34 loc) · 1.18 KB
/
server.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
from datetime import datetime
from app import create_app
from app.modules.utils import generate_password
from flask_wtf.csrf import CSRFError
from flask import jsonify
import os
app = create_app(os.environ.get('FLASK_ENV','development'))
from app.db import db, quiz
@app.before_first_request
def seed_data():
""""
if there was no user with admin role, add new one
login with
* username : admin
* password : admin1
you can change the email, username, password in dashboard
"""
cek = db.users.find_one({})
if not cek:
data = {}
data['full_name'] = 'Admin Web'
data['username'] = 'admin'
data['password'] = generate_password('admin1')
data['joined_at'] = datetime.utcnow()
data['email'] = 'yourmail@gmail.com'
data['type'] = 1
insert_data = db.users.insert_one(data)
if insert_data.inserted_id:
app.logger.info('new user added')
@app.errorhandler(CSRFError)
def error_csrf(e):
return jsonify(status='fail', errors='CSRF Error, please refresh the page')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=os.environ.get('PORT', 5000))