Add the possibility to save mtn public keys per user
* src/IDF/Key.php: new column "type" which is either "ssh" or "mtn"; utility functions to query the mtn key name and id as well as all available key types for the current IDF installation * src/IDF/Migrations/16KeyType.php: needed migration script * src/IDF/Plugin/SyncGit/Cron.php: ensure only SSH keys are handled * adapt forms and templates accordingly
This commit is contained in:
@@ -77,21 +77,27 @@ class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||
'initial' => '',
|
||||
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||
'widget_attrs' => array(
|
||||
'choices' =>
|
||||
'choices' =>
|
||||
Pluf_L10n::getInstalledLanguages()
|
||||
),
|
||||
));
|
||||
|
||||
$this->fields['ssh_key'] = new Pluf_Form_Field_Varchar(
|
||||
$this->fields['public_key'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => false,
|
||||
'label' => __('Add a public SSH key'),
|
||||
'label' => __('Add a public key'),
|
||||
'initial' => '',
|
||||
'widget_attrs' => array('rows' => 3,
|
||||
'cols' => 40),
|
||||
'widget' => 'Pluf_Form_Widget_TextareaInput',
|
||||
'help_text' => __('Be careful to provide the public key and not the private key!')
|
||||
));
|
||||
|
||||
$this->fields['public_key_type'] = new Pluf_Form_Field_Varchar(
|
||||
array('required' => true,
|
||||
'label' => __('Key type'),
|
||||
'initial' => 'ssh',
|
||||
'widget_attrs' => array('choices' => IDF_Key::getAvailableKeyTypes()),
|
||||
'widget' => 'Pluf_Form_Widget_SelectInput',
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@@ -138,10 +144,11 @@ class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||
Pluf_Signal::send('Pluf_User::passwordUpdated',
|
||||
'IDF_Form_Admin_UserCreate', $params);
|
||||
// Create the ssh key as needed
|
||||
if ('' !== $this->cleaned_data['ssh_key']) {
|
||||
if ('' !== $this->cleaned_data['public_key']) {
|
||||
$key = new IDF_Key();
|
||||
$key->user = $user;
|
||||
$key->content = $this->cleaned_data['ssh_key'];
|
||||
$key->content = $this->cleaned_data['public_key'];
|
||||
$key->type = $this->cleaned_data['public_key_type'];
|
||||
$key->create();
|
||||
}
|
||||
// Send an email to the user with the password
|
||||
@@ -162,16 +169,11 @@ class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||
return $user;
|
||||
}
|
||||
|
||||
function clean_ssh_key()
|
||||
{
|
||||
return IDF_Form_UserAccount::checkSshKey($this->cleaned_data['ssh_key']);
|
||||
}
|
||||
|
||||
function clean_last_name()
|
||||
{
|
||||
$last_name = trim($this->cleaned_data['last_name']);
|
||||
if ($last_name == mb_strtoupper($last_name)) {
|
||||
return mb_convert_case(mb_strtolower($last_name),
|
||||
return mb_convert_case(mb_strtolower($last_name),
|
||||
MB_CASE_TITLE, 'UTF-8');
|
||||
}
|
||||
return $last_name;
|
||||
@@ -181,7 +183,7 @@ class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||
{
|
||||
$first_name = trim($this->cleaned_data['first_name']);
|
||||
if ($first_name == mb_strtoupper($first_name)) {
|
||||
return mb_convert_case(mb_strtolower($first_name),
|
||||
return mb_convert_case(mb_strtolower($first_name),
|
||||
MB_CASE_TITLE, 'UTF-8');
|
||||
}
|
||||
return $first_name;
|
||||
@@ -211,4 +213,16 @@ class IDF_Form_Admin_UserCreate extends Pluf_Form
|
||||
}
|
||||
return $this->cleaned_data['login'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether any given public key is valid
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
$this->cleaned_data['public_key'] =
|
||||
IDF_Form_UserAccount::checkPublicKey($this->cleaned_data['public_key'],
|
||||
$this->cleaned_data['public_key_type']);
|
||||
|
||||
return $this->cleaned_data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user