adapt client oidc

This commit is contained in:
Cayo Puigdefabregas 2023-05-19 17:05:02 +02:00
parent 7a128e6e7f
commit 7b2bfd095c
3 changed files with 28 additions and 31 deletions

View File

@ -41,30 +41,22 @@
<body>
<main>
<section class="container mt-3">
<div class="row">
<div class="col">
<nav class="header-nav ms-auto">
<ul class="d-flex align-items-right">
<li class="nav-item">
{% if user.is_anonymous %}
{% if not rols and user.is_anonymous %}
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#validateModal">Validate</button>
{% else %}
<button class="btn btn-primary" id="buttonRol" data-bs-toggle="modal" data-bs-target="#rolsModal">Select your rol</button>
{% endif %}
</li>
</ul>
{{ rol }}
</nav>
<section class="container mt-3">
<div class="row">
<div class="col">
{% if not rol and rols %}
<button class="btn btn-primary">Select a Rol</button>
{% endif %}
</div>
</div>
<div class="row">
<div class="col">
<div class="col-xl-12">
<div class="card">
@ -236,7 +228,7 @@
</div>
</div>
{% if user.is_anonymous %}
{% if user.is_anonymous and not rols %}
<div class="modal fade" id="validateModal" tabindex="-1" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
@ -250,10 +242,13 @@
<a class="btn btn-primary" type="button"
href="{{ url_for('core.login') }}?next={{ device_real.url.to_text() }}">
User of system
</a> <br />
<a class="btn btn-primary mt-3" type="button" href="#">
User with Metamax Wallet
</a>
{% if oidc %}
<br />
<a class="btn btn-primary mt-3" type="button" href="{{ url_for('oidc.login_other_inventory') }}?next={{ device_real.url.to_text() }}">
User of other inventory
</a>
{% endif %}
</div>
<div class="modal-footer"></div>

View File

@ -1,7 +1,4 @@
import datetime
import uuid
from itertools import filterfalse
import flask
import marshmallow
from ereuseapi.methods import API
@ -10,14 +7,12 @@ from flask import current_app as app
from flask import g, render_template, request, session
from flask.json import jsonify
from flask_sqlalchemy import Pagination
from marshmallow import Schema as MarshmallowSchema
from marshmallow import fields
from marshmallow import fields as f
from marshmallow import validate as v
from sqlalchemy.util import OrderedSet
from teal import query
from teal.cache import cache
from teal.db import ResourceNotFound
from teal.marshmallow import ValidationError
from teal.resource import View
@ -30,7 +25,6 @@ from ereuse_devicehub.resources.action.models import Trade
from ereuse_devicehub.resources.device import states
from ereuse_devicehub.resources.device.models import Computer, Device, Manufacturer
from ereuse_devicehub.resources.device.search import DeviceSearch
from ereuse_devicehub.resources.enums import SnapshotSoftware
from ereuse_devicehub.resources.lot.models import LotDeviceDescendants
from ereuse_devicehub.resources.tag.model import Tag
@ -138,9 +132,13 @@ class DeviceView(View):
return self.one_private(id)
def get_rols(self):
if not g.user.is_authenticated:
rols = session.get('rols')
if not g.user.is_authenticated and not rols:
return []
if rols:
return [(k, k) for k in rols]
if 'trublo' not in app.blueprints.keys():
return []
@ -184,8 +182,10 @@ class DeviceView(View):
placeholder = device.binding or device.placeholder
device_abstract = placeholder and placeholder.binding or device
device_real = placeholder and placeholder.device or device
oidc = 'oidc' in app.blueprints.keys()
return render_template(
'devices/layout.html',
oidc=oidc,
placeholder=placeholder,
device=device,
device_abstract=device_abstract,

View File

@ -2,7 +2,7 @@ import flask
from decouple import config
from flask import Blueprint
from flask import current_app as app
from flask import g
from flask import g, session
from flask.views import View
from flask_login import current_user, login_required, login_user, logout_user
from sqlalchemy import or_
@ -64,6 +64,8 @@ class LoginView(View):
class LogoutView(View):
def dispatch_request(self):
session_vars = ['token_dlt', 'rols']
[session.pop(i, '') for i in session_vars]
logout_user()
return flask.redirect(flask.url_for('core.login'))