def _register_user(form: RegisterForm): with db.auto_commit(): # 注意:此处使用挂载到manager上的user_model,不可使用默认的User user = manager.user_model() user.nickname = form.nickname.data if form.email.data and form.email.data.strip() != "": user.email = form.email.data user.password = form.password.data user.group_id = form.group_id.data db.session.add(user)
def wx_register_user(form): with db.auto_commit(): # 注意:此处使用挂载到manager上的user_model,不可使用默认的User user = manager.user_model() user.openid = form['openid'] user.username = '******' # if form.email.data and form.email.data.strip() != "": # user.email = '*****@*****.**' # user.password = form.password.data # user.group_id = form.group_id.data db.session.add(user)
def register_by_mina(wx_open_id): user = manager.user_model.query.filter_by(wx_open_id=wx_open_id).first() if user: raise Forbidden(msg='openid has been registered') else: with db.auto_commit(): user = manager.user_model() user.wx_open_id = wx_open_id user.username = '******' + str(manager.user_model.query.count()) db.session.add(user) return Success()
def init_admin(): """初始化超级管理员""" admin = manager.user_model.query.filter_by(username='******', delete_time=None).first() if admin is None: with db.auto_commit(): # 创建一个超级管理员 user = manager.user_model() user.username = '******' user.password = '******' user.email = '*****@*****.**' # admin 2 的时候为超级管理员,普通用户为 1 user.admin = 2 db.session.add(user)