def register_view(self): from common.login import RegistrationForm form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): from common.user import User user = User() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) db_control.get_db().session.add(user) db_control.get_db().session.commit() login.login_user(user) return redirect(url_for('.index')) link = '<p>Already have an account? <a href="' + url_for( '.login_view') + '">Click here to log in.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(CVAdminIndexView, self).index()
from sqlalchemy import func import api_control as ac import db_control from app_view import CVAdminModelView from common.util import get_now, get_botname, get_target_composevalue, get_target_display, output_datetime,\ display_datetime,\ get_list_by_botassign, get_list_count_by_botassign, get_CQ_display from plugin import PluginsRegistry from plugins.score import ScoreRecord from plugins.setting import BotParam __registry__ = pr = PluginsRegistry() # Model---------------------------------------------------------------------------------------------------- db = db_control.get_db() @pr.register_model(11) class Sign(db.Model): __bind_key__ = 'score' __tablename__ = 'sign' id = db.Column(db.Integer, primary_key=True, autoincrement=True) botid = db.Column(db.String(20), nullable=False) target = db.Column(db.String(20), nullable=False) member_id = db.Column(db.String(20), nullable=False) member_name = db.Column(db.String(20), nullable=False) date = db.Column(db.Date, nullable=False, default=lambda: get_now(),
def validate_login(self, field): if db_control.get_db().session.query( user.User).filter_by(username=self.username.data).count() > 0: raise validators.ValidationError('Duplicate username')
def get_user(self): # return login_model.User.find_user(self.username) return db_control.get_db().session.query( user.User).filter_by(username=self.username.data).first()
def init(app): ''' 初始化 :param app:flask app :return: ''' global admin admin = Admin( app, name="云谷机器人控制台", index_view=CVAdminIndexView(name='仪表板', menu_icon_type='fa', menu_icon_value='dashboard'), # base_template = 'admin/layout.html', template_mode='bootstrap2') # Flask views @app.route('/') def index(): return render_template("admin/redirect.html") # bower_components @app.route('/bower_components/<path:path>') def send_bower(path): return send_from_directory( os.path.join(app.root_path, 'bower_components'), path) @app.route('/dist/<path:path>') def send_dist(path): return send_from_directory(os.path.join(app.root_path, 'dist'), path) @app.route('/js/<path:path>') def send_js(path): return send_from_directory(os.path.join(app.root_path, 'js'), path) @app.errorhandler(401) def unauthenticated(e): return render_template('401.html'), 401 @app.errorhandler(403) def forbidden(e): return render_template('403.html'), 403 @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 # category设置图标 admin.category_icon_classes = { '消息管理': 'fa fa-comments-o', '报点管理': 'fa fa-gift', '积分管理': 'fa fa-money', '统计分析': 'fa fa-bar-chart-o', '机器人设置': 'fa fa-reddit', '系统设置': 'fa fa-cogs' } from plugin import hub views = {} models = {} # 从插件中加载已注册的模型类和视图类 for (hub_k, hub_v) in hub.registry_map.items(): for (model_k, model_v) in hub_v.model_map.items(): models[model_k] = model_v for (view_k, view_v) in hub_v.view_map.items(): views[view_k] = view_v # 按注册的排序顺序创建数据模型视图 models_list = [models[k] for k in sorted(models.keys())] for model in models_list: model_class = model view_class = views[model.__name__ + 'View'] # 不对Fields missing问题提示警告 with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'Fields missing from ruleset', UserWarning) admin.add_view(view_class(model_class, db_control.get_db().session)) # 创建文件视图 admin.add_view( CVAdminFileView(get_db_dir(), '', name='数据库文件', category='系统设置'))