Skip to content
Snippets Groups Projects
Verified Commit f9b8ac37 authored by Dominik Frantisek Bucik's avatar Dominik Frantisek Bucik
Browse files

refactor: :bulb: Removed obsolete code

removed unused obsolete code from module

BREAKING CHANGE: :firecracker: Removed LoginModify AuthProc filter
parent 2ef33bd8
Branches
Tags
1 merge request!10refactor: 💡remove old hostel, rename references to LS Username Login
Pipeline #296326 passed
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\lsaai\Auth\Process;
use SimpleSAML\Auth\ProcessingFilter;
use SimpleSAML\Error\Exception;
use SimpleSAML\Logger;
/**
* Class LoginModify.
*
* This filter takes username entered by user and modifies it in the following way: 1) trim whitespaces around input, 2)
* replace '@' from email with '_', 3) replace "domain" with lowercase string
*/
class LoginModify extends ProcessingFilter
{
private $loginAttrName;
public function __construct($config, $reserved)
{
parent::__construct($config, $reserved);
assert('is_array($config)');
if (!isset($config['loginAttrName'])) {
throw new Exception("lsaai:LoginModify missing mandatory configuration option 'loginAttrName'.");
}
$this->loginAttrName = (string) $config['loginAttrName'];
}
public function process(&$request)
{
assert('is_array($request)');
$oldUserName = $request['Attributes'][$this->loginAttrName][0];
$userName = trim($oldUserName);
// $userNameParts = explode('@', $userName, 2);
// $userName = $userNameParts[0] . '_' . strtolower($userNameParts[1]);
$request['Attributes'][$this->loginAttrName][0] = $userName;
Logger::debug('lsaai:LoginModify - Modified ' . $oldUserName . ' to new format ' . $userName);
}
}
...@@ -187,185 +187,4 @@ class TemplateHelper ...@@ -187,185 +187,4 @@ class TemplateHelper
self::printItem($name . '[' . $index . ']', $item); self::printItem($name . '[' . $index . ']', $item);
} }
} }
public static function searchScript()
{
return '<script type="text/javascript">
$(document).ready(function() {
$("#query").liveUpdate("#list");
});
</script>';
}
/**
* Show icon for IdP.
* Logos are turned off by default, because they are loaded via URL from IdP.
* Some IdPs have bad configuration, so it breaks the WAYF.
* @param $metadata
* @param $logos
* @return string
*/
public static function showIcon($metadata, $logos = false)
{
if ($logos) {
if (isset($metadata['UIInfo']['Logo'][0]['url'])) {
return '<img src="' .
htmlspecialchars(HTTP::resolveURL($metadata['UIInfo']['Logo'][0]['url'])) .
'" class="idp-logo">';
}
if (isset($metadata['icon'])) {
return '<img src="' . htmlspecialchars(HTTP::resolveURL($metadata['icon'])) .
'" class="idp-logo">';
}
}
return '';
}
/**
* @param sspmod_perun_DiscoTemplate $t
* @param array $metadata
* @param bool $favourite
*
* @return string html
*/
public static function showEntry($t, $metadata, $favourite = false)
{
if (isset($metadata['tags']) && in_array('social', $metadata['tags'], true)) {
return self::showEntrySocial($t, $metadata);
}
$extra = ($favourite ? ' favourite' : '');
$html = '<a class="metaentry' . $extra . ' list-group-item" href="' . $t->getContinueUrl(
$metadata['entityid']
) . '">';
$html .= '<strong>' . $t->getTranslatedEntityName($metadata) . '</strong>';
$html .= TemplateHelper::showIcon($metadata);
$html .= '</a>';
return $html;
}
/**
* @param sspmod_perun_DiscoTemplate $t
* @param array $metadata
*
* @return string html
*/
public static function showEntrySocial($t, $metadata)
{
$bck = 'white';
if (!empty($metadata['color'])) {
$bck = $metadata['color'];
}
$html = '<a class="btn btn-block social" href="' . $t->getContinueUrl(
$metadata['entityid']
) . '" style="background: ' . $bck . '">';
$html .= '<img src="' . $metadata['icon'] . '">';
$html .= '<strong>Sign in with ' . $t->getTranslatedEntityName($metadata) . '</strong>';
$html .= '</a>';
return $html;
}
/**
* Recursive attribute array listing function.
*
* @param SimpleSAML_XHTML_Template $t Template object
* @param array $attributes Attributes to be presented
* @param string $nameParent Name of parent element
*
* @return string HTML representation of the attributes
*/
public static function presentAttributesOld($t, $attributes, $nameParent)
{
$i = 0;
$summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"';
if (strlen($nameParent) > 0) {
$parentStr = strtolower($nameParent) . '_';
$str = '<table class="table attributes" ' . $summary . '>';
} else {
$parentStr = '';
$str = '<table id="table_with_attributes" class="table attributes" ' . $summary . '>';
$str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') .
'</caption>';
}
foreach ($attributes as $name => $value) {
$nameraw = $name;
$name = $t->getAttributeTranslation($parentStr . $nameraw);
if (preg_match('/^child_/', $nameraw)) {
// insert child table
$parentName = preg_replace('/^child_/', '', $nameraw);
foreach ($value as $child) {
$str .= "\n" . '<tr class="odd"><td style="padding: 2em">' .
self::presentAttributesOld($t, $child, $parentName) . '</td></tr>';
}
} else {
// insert values directly
$str .= "\n" . '<tr><td><span class="attrname">' . htmlspecialchars($name) . '</span>';
$isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true);
if ($isHidden) {
$hiddenId = SimpleSAML\Utils\Random::generateID();
$str .= '<div class="attrvalue" style="display: none;" id="hidden_' . $hiddenId . '">';
} else {
$str .= '<div class="attrvalue">';
}
if (sizeof($value) > 1) {
// we hawe several values
$str .= '<ul>';
foreach ($value as $listitem) {
if ('jpegPhoto' === $nameraw) {
$str .= '<li><img src="data:image/jpeg;base64,' .
htmlspecialchars($listitem) .
'" alt="User photo" /></li>';
} else {
$str .= '<li>' . htmlspecialchars($listitem) . '</li>';
}
}
$str .= '</ul>';
} elseif (isset($value[0])) {
// we hawe only one value
if ('jpegPhoto' === $nameraw) {
$str .= '<img src="data:image/jpeg;base64,' .
htmlspecialchars($value[0]) .
'" alt="User photo" />';
} else {
$str .= htmlspecialchars($value[0]);
}
} // end of if multivalue
$str .= '</div>';
if ($isHidden) {
$str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">';
$str .= '... ';
$str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' .
$hiddenId;
$str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">';
$str .= $t->t('{consent:consent:show_attribute}');
$str .= '</a>';
$str .= '</div>';
}
$str .= '</td></tr>';
} // end else: not child table
} // end foreach
$str .= isset($attributes) ? '</table>' : '';
return $str;
}
} }
<?php
/**
* This is simple example of template for perun Discovery service.
*
* Allow type hinting in IDE
*
* @var sspmod_perun_DiscoTemplate $this
*/
declare(strict_types=1);
use SimpleSAML\Module\lsaai\TemplateHelper;
$this->data['jquery'] = [
'core' => true,
'ui' => true,
'css' => true,
];
$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' . SimpleSAML\Module::getModuleUrl(
'discopower/style.css'
) . '" />';
$this->data['head'] .= '<link rel="stylesheet" media="screen" type="text/css" href="' . SimpleSAML\Module::getModuleUrl(
'lsaai/res/css/disco.css'
) . '" />';
$this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML\Module::getModuleUrl(
'discopower/js/jquery.livesearch.js'
) . '"></script>';
$this->data['head'] .= '<script type="text/javascript" src="' . SimpleSAML\Module::getModuleUrl(
'discopower/js/suggest.js'
) . '"></script>';
$this->data['head'] .= TemplateHelper::searchScript();
$this->includeAtTemplateBase('includes/header.php');
$this->includeAtTemplateBase('includes/footer.php');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment