minor code style change

This commit is contained in:
timfeirg 2016-08-13 00:49:53 +08:00
parent 186aedcfc7
commit 683f633d7d
3 changed files with 31 additions and 34 deletions

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ logfile.log
db_repository/* db_repository/*
upload/avatar/* upload/avatar/*
tmp/* tmp/*
.ropeproject

View File

@ -1,25 +1,23 @@
import os
import json
import jinja2
import traceback
import pyqrcode
import base64 import base64
import random import json
import string import os
import traceback
from functools import wraps
from flask_login import login_user, logout_user, current_user, login_required
from flask import Flask, g, request, make_response, jsonify, render_template, session, redirect, url_for, send_from_directory, abort
from werkzeug import secure_filename
from lib import utils
from app import app, login_manager, github
from .models import User, Role, Domain, DomainUser, Record, Server, History, Anonymous, Setting, DomainSetting
from io import BytesIO
from distutils.util import strtobool from distutils.util import strtobool
from distutils.version import StrictVersion from distutils.version import StrictVersion
from optparse import Values from functools import wraps
from io import BytesIO
import jinja2
import pyqrcode
from flask import g, request, make_response, jsonify, render_template, session, redirect, url_for, send_from_directory, abort
from flask_login import login_user, logout_user, current_user, login_required
from werkzeug import secure_filename
from werkzeug.security import gen_salt
from .models import User, Domain, Record, Server, History, Anonymous, Setting, DomainSetting
from app import app, login_manager, github
from lib import utils
jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name
jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name
@ -34,9 +32,6 @@ if StrictVersion(PDNS_VERSION) >= StrictVersion('4.0.0'):
else: else:
NEW_SCHEMA = False NEW_SCHEMA = False
def random_password(n):
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(n))
@app.context_processor @app.context_processor
def inject_fullscreen_layout_setting(): def inject_fullscreen_layout_setting():
fullscreen_layout_setting = Setting.query.filter(Setting.name == 'fullscreen_layout').first() fullscreen_layout_setting = Setting.query.filter(Setting.name == 'fullscreen_layout').first()
@ -184,7 +179,7 @@ def login():
if not user: if not user:
# create user # create user
user = User(username=user_info['name'], user = User(username=user_info['name'],
plain_text_password=random_password(7), plain_text_password=gen_salt(7),
email=user_info['email']) email=user_info['email'])
user.create_local_user() user.create_local_user()
@ -201,14 +196,14 @@ def login():
# process login # process login
username = request.form['username'] username = request.form['username']
password = request.form['password'] password = request.form['password']
otp_token = request.form['otptoken'] if 'otptoken' in request.form else None otp_token = request.form.get('otptoken')
auth_method = request.form['auth_method'] if 'auth_method' in request.form else 'LOCAL' auth_method = request.form.get('auth_method', 'LOCAL')
# addition fields for registration case # addition fields for registration case
firstname = request.form['firstname'] if 'firstname' in request.form else None firstname = request.form.get('firstname')
lastname = request.form['lastname'] if 'lastname' in request.form else None lastname = request.form.get('lastname')
email = request.form['email'] if 'email' in request.form else None email = request.form.get('email')
rpassword = request.form['rpassword'] if 'rpassword' in request.form else None rpassword = request.form.get('rpassword')
if None in [firstname, lastname, email]: if None in [firstname, lastname, email]:
#login case #login case
@ -259,8 +254,8 @@ def login():
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
session.pop('user_id') session.pop('user_id', None)
session.pop('github_token') session.pop('github_token', None)
logout_user() logout_user()
return redirect(url_for('login')) return redirect(url_for('login'))

View File

@ -11,3 +11,4 @@ SQLAlchemy==1.0.9
sqlalchemy-migrate==0.10.0 sqlalchemy-migrate==0.10.0
onetimepass==1.0.1 onetimepass==1.0.1
PyQRCode==1.2 PyQRCode==1.2
Flask-OAuthlib==0.9.3