def init_database_values(): from remanager_back.data_auth.models import UserModel, AuthorityModel, RevokedTokenModel from remanager_back.database.organizacion import Organizacion authority0 = AuthorityModel(authority_name=settings.AUTHORITY_ROOT) authority0.save_to_db() authority1 = AuthorityModel(authority_name=settings.AUTHORITY_ADMIN) authority1.save_to_db() authority2 = AuthorityModel(authority_name=settings.AUTHORITY_USER) authority2.save_to_db() root = UserModel(login=settings.ROOT_OBJECT['login'], password=UserModel.generate_hash( settings.ROOT_OBJECT['password']), firstName=settings.ROOT_OBJECT['firstName'], email=settings.ROOT_OBJECT['email'], activated=True) root.authorities.append(authority0) root.authorities.append(authority1) root.authorities.append(authority2) root.save_to_db() admin = UserModel(login=settings.ADMIN_OBJECT['login'], password=UserModel.generate_hash( settings.ADMIN_OBJECT['password']), firstName=settings.ADMIN_OBJECT['firstName'], lastName=settings.ADMIN_OBJECT['lastName'], email=settings.ADMIN_OBJECT['email'], activated=True) admin.authorities.append(authority1) admin.authorities.append(authority2) admin.save_to_db() organizacion = Organizacion.objects( correoCreador=settings.ORGANIZACION_OBJECT['correo_creador']).first() if organizacion is None: organizacion = Organizacion() organizacion.nombre = settings.ORGANIZACION_OBJECT['nombre'] organizacion.descripcion = settings.ORGANIZACION_OBJECT['descripcion'] organizacion.correoCreador = settings.ORGANIZACION_OBJECT[ 'correo_creador'] organizacion.save() root.organizationId = str(organizacion.id) root.save_to_db() admin.organizationId = str(organizacion.id) admin.save_to_db()
def put(self): user_login = get_jwt_identity() current_user = UserModel.find_by_login(user_login) if not current_user: abort(401, 'El usuario con login {} no existe'.format(user_login)) data = change_pss_parser.parse_args() if not UserModel.verify_hash(data['old_password'], current_user.password): abort(401, 'El password anterior no coincide') current_user.password = UserModel.generate_hash(data['new_password']) current_user.save_to_db() return {'message': 'El password se ha cambiado correctamente'}
def crear_usuario(login: str, password: str, first_name: str, last_name: str, email: str, organization_id: str, authorities: List[str]) -> UserModel: user = UserModel(login=login, password=UserModel.generate_hash(password), firstName=first_name, lastName=last_name, email=email, organizationId=organization_id, activated=False) for authority_str in authorities: authority = AuthorityModel.find_by_authority_name(authority_str) if authority is not None: user.authorities.append(authority) user.save_to_db() return user