ldap avatar

This commit is contained in:
afornerot 2023-07-20 15:52:51 +02:00
parent 41e11123da
commit 1be43b086c
7 changed files with 15 additions and 12 deletions

2
.env
View File

@ -67,7 +67,7 @@ OAUTH_USERNAME=username
OAUTH_EMAIL=email
OAUTH_LASTNAME=lastname
OAUTH_FIRSTNAME=firstname
OAUTH_AVATAR=avatar
OAUTH_AVATAR=picture
OAUTH_AUTOSUBMIT=1 # if APP_AUTH = OPENID autocréer les users non existant
OAUTH_AUTOUPDATE=1 # if APP_AUTH = OPENID automodifier les users existant

View File

@ -9,6 +9,7 @@ framework:
# Remove or comment this section to explicitly disable session support.
session:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
name: 'nuosso'
save_path: '@Redis'
gc_probability: null
cookie_secure: auto

View File

@ -15,5 +15,5 @@
"code"
],
"logo_uri": "http://127.0.0.1:8080/images/logo.png",
"scope": "openid"
"scope": "openid profile email"
}

View File

@ -87,6 +87,7 @@ class HydraController extends AbstractController
'email' => $user->getEmail(),
'firstname' => $user->getFirstname(),
'lastname' => $user->getLastname(),
'picture' => $user->getAvatar(),
];
$request->getSession()->set('datas', $datas);
@ -148,7 +149,7 @@ class HydraController extends AbstractController
$email = "$username@nomail.fr";
$lastname = $username;
$firstname = ' ';
$firstname = 'noavatar.png';
$avatar = '';
// Rechercher l'utilisateur
if (isset($userldap[$this->getParameter('ldapFirstname')])) {
@ -164,7 +165,7 @@ class HydraController extends AbstractController
}
if (isset($userldap[$this->getParameter('ldapAvatar')])) {
$avatar = $userldap[$this->getParameter('ldapAvatar')];
$avatar = "data:image/jpeg;base64,".base64_encode($userldap[$this->getParameter('ldapAvatar')]);
}
$response = $this->apiservice->run('PUT', $this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'), ['subject' => $email, 'acr' => 'string']);
@ -177,6 +178,7 @@ class HydraController extends AbstractController
'email' => $email,
'firstname' => $firstname,
'lastname' => $lastname,
'picture' => $avatar,
];
$request->getSession()->set('datas', $datas);

View File

@ -97,7 +97,7 @@ class SecurityController extends AbstractController
$email = "$username@nomail.fr";
$lastname = $username;
$firstname = ' ';
$avatar = 'noavatar.png';
$avatar = 'images/noavatar.png';
// Rechercher l'utilisateur
if (isset($attributes[$this->getParameter('casUsername')])) {
@ -170,7 +170,7 @@ class SecurityController extends AbstractController
$email = "$username@nomail.fr";
$lastname = $username;
$firstname = ' ';
$avatar = 'noavatar.png';
$avatar = 'images/noavatar.png';
// Rechercher l'utilisateur
if (isset($userldap[$this->getParameter('ldapFirstname')])) {
@ -212,7 +212,7 @@ class SecurityController extends AbstractController
$state = Uuid::uuid4();
$request->getSession()->set('oauthState', $state);
$callback = $this->generateUrl('app_loginopenidcallback', [], UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getParameter('oauthLoginurl').'?client_id='.$this->getParameter('oauthClientid').'&redirect_uri='.$callback.'&response_type=code&state='.$state.'&scope=openid';
$url = $this->getParameter('oauthLoginurl').'?client_id='.$this->getParameter('oauthClientid').'&redirect_uri='.$callback.'&response_type=code&state='.$state.'&scope=openid profile email';
return $this->redirect($url);
}
@ -265,7 +265,7 @@ class SecurityController extends AbstractController
$email = "$username@nomail.fr";
$lastname = $username;
$firstname = ' ';
$avatar = 'noavatar.png';
$avatar = 'images/noavatar.png';
// Récupérer les attributs associés
if (isset($attributes[$this->getParameter('oauthEmail')])) {
@ -385,7 +385,7 @@ class SecurityController extends AbstractController
$email = $username.'@nomail.com';
}
if (empty($avatar)) {
$avatar = 'noavatar.png';
$avatar = 'images/noavatar.png';
}
if (empty($firstname)) {
$firstname = ' ';
@ -414,7 +414,7 @@ class SecurityController extends AbstractController
private function updateuser($user, $firstname, $lastname, $email, $avatar, $em)
{
if ('noavatar.png' == $avatar) {
if ('images/noavatar.png' == $avatar) {
$avatar = $user->getAvatar();
}

View File

@ -72,7 +72,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
private $email;
/**
* @ORM\Column(type="string", length=250, nullable=true, options={"default" : 0})
* @ORM\Column(type="text")
*/
private $avatar;

View File

@ -25,7 +25,7 @@
<div class="card mt-5" style="max-width:600px; margin:auto;">
<div class="card-body d-flex">
<div>
<img src="{{ asset('images/' ~ app.user.avatar)}}" style="height:100px; background-color: #212529"/>
<img src="{{ (app.user.avatar starts with 'images/' ? asset(app.user.avatar) : app.user.avatar ) }}" style="height:100px; background-color: #212529"/>
</div>
<div class="ps-3">