def deploy(): """Run deployment tasks.""" db.create_all() # create or update user roles db.session.begin(subtransactions=True) Role.insert_roles() UserDal.add_user('test', '', '123456', 1)
def deploy(): """Run deployment tasks.""" # db.drop_all() db.create_all() # create or update user roles db.session.begin(subtransactions=True) Role.insert_roles() UserDal.add_user('test', '', '123456', 1)
def delete_user(username): if username == current_user.username: raise BadParam('cannot delete yourself') user = UserDal.get_user_info(username=username) if not user: raise BadParam('No such user with name: %s' % username) result = user.json_serialize(include=('username', 'email', 'role')) UserDal.delete_user(username) return result
def login(): if request.method == 'POST': form = request.get_json(force=True) user = UserDal.get_user_info(username=form['username']) if user is not None and user.verify_password(form['password']): login_user(user, remember=True) return current_user.username raise DnsdbException('Invalid username or password.', msg_ch=u'账号或密码错误') else: raise Unauthorized()
def add_user(username, email, password, role_id): UserDal.add_user(username, email, password, role_id)
def list_user(**kwargs): return UserDal.list_user(**kwargs)
def get_user(username): user = UserDal.get_user_info(username=username) if user is None: return [] return [UserDal.get_user_info(username=username).json_serialize()]
def get_roles(): return UserDal.get_roles()
def get_update_info(result, **kwargs): op_after = kwargs.copy() op_after.pop('password', None) role_id = op_after.pop('role_id') op_after['role'] = UserDal.get_role_name(role_id) return kwargs['username'], {}, op_after
def list_user(**kwargs): print kwargs return UserDal.list_user(**kwargs)