def post(self): """ Create a new user """ if not current_user.has_admin(): return {"success": False, "message": "Access denied"}, 401 args = register.parse_args() username = args.get('username') if UserModel.objects(username__iexact=username).first(): return { 'success': False, 'message': 'Username already exists.' }, 400 user = UserModel() user.username = args.get('username') user.password = generate_password_hash(args.get('password'), method='sha256') user.name = args.get('name', "") user.email = args.get('email', "") user.is_admin = args.get('isAdmin', False) user.save() user_json = fix_ids(current_user) del user_json['password'] return {'success': True, 'user': user_json}
def post(self): """ Creates user """ users = UserModel.objects.count() if not Config.ALLOW_REGISTRATION and users != 0: return {'success': False, 'message': 'Registration of new accounts is disabled.'}, 400 args = register.parse_args() username = args.get('username') if UserModel.objects(username__iexact=username).first(): return {'success': False, 'message': 'Username already exists.'}, 400 user = UserModel() user.username = args.get('username') user.password = generate_password_hash(args.get('password'), method='sha256') user.name = args.get('name') user.email = args.get('email') if users == 0: user.is_admin = True user.save() login_user(user) user_json = fix_ids(current_user) del user_json['password'] return {'success': True, 'user': user_json}
def create_original_user(self, username, password, name, email): user = UserModel() user.username = username user.password = self.encryption_service.hash_password(password) user.name = name user.email = email user.save() return user