1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-12-13 09:56:01 +00:00

[Web] update mailbox on idp login

This commit is contained in:
FreddleSpl0it
2024-12-02 10:35:45 +01:00
parent 6fa1c9f63d
commit f36184df64
2 changed files with 63 additions and 46 deletions

View File

@@ -2512,31 +2512,9 @@ function identity_provider($_action = null, $_data = null, $_extra = null) {
// check if email address is given
if (empty($info['email'])) return false;
// get mapped template, if not set return false
// also return false if no mappers were defined
// get mapped template
$user_template = $info['mailcow_template'];
if (empty($iam_settings['mappers']) || empty($user_template)){
clear_session();
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $info['email']),
'msg' => array('login_failed', 'empty attribute mapping or missing template attribute')
);
return false;
}
// check if matching attribute exist
$mapper_key = array_search($user_template, $iam_settings['mappers']);
if ($mapper_key === false) {
clear_session();
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $info['email']),
'msg' => array('login_failed', 'specified template not found')
);
return false;
}
// token valid, get mailbox
$stmt = $pdo->prepare("SELECT * FROM `mailbox`
@@ -2550,13 +2528,15 @@ function identity_provider($_action = null, $_data = null, $_extra = null) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row){
// success
// update user
mailbox('edit', 'mailbox_from_template', array(
'username' => $info['email'],
'name' => $info['name'],
'template' => $iam_settings['templates'][$mapper_key],
'hasAccess' => true
));
if ($mapper_key !== false) {
// update user
mailbox('edit', 'mailbox_from_template', array(
'username' => $info['email'],
'name' => $info['name'],
'template' => $iam_settings['templates'][$mapper_key],
'hasAccess' => true
));
}
set_user_loggedin_session($info['email']);
$_SESSION['return'][] = array(
'type' => 'success',
@@ -2566,6 +2546,25 @@ function identity_provider($_action = null, $_data = null, $_extra = null) {
return true;
}
if (empty($iam_settings['mappers']) || empty($user_template)){
clear_session();
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $info['email']),
'msg' => array('login_failed', 'empty attribute mapping or missing template attribute')
);
return false;
}
if ($mapper_key === false) {
clear_session();
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $info['email']),
'msg' => array('login_failed', 'specified template not found')
);
return false;
}
// create mailbox
$create_res = mailbox('add', 'mailbox_from_template', array(
'domain' => explode('@', $info['email'])[1],