remove transfer from user

This commit is contained in:
osaajani 2020-01-08 13:45:20 +01:00
parent fb6abb4d91
commit b42c2490ac
5 changed files with 41 additions and 108 deletions

View File

@ -92,18 +92,6 @@ namespace controllers\internals;
return (bool) $this->model_user->update_password($id, $password);
}
/**
* Update a user transfer property value.
*
* @param string $id : User id
* @param string $transfer : New value of property transfer
*
* @return boolean;
*/
public function update_transfer(int $id, int $transfer): bool
{
return (bool) $this->model_user->update_transfer($id, $transfer);
}
/**
* Update user email.
@ -163,33 +151,22 @@ namespace controllers\internals;
return $this->model_user->get_by_api_key($api_key);
}
/**
* Return users by transfer status.
*
* @param bool $transfer : transfer status
*/
public function gets_by_transfer($transfer)
{
return $this->model_user->get_by_transfer($transfer);
}
/**
* Update a user by his id
* @param mixed $id
* @param mixed $email
* @param mixed $password
* @param mixed $admin
* @param mixed $transfer
*
* @return int : Number of modified user
*/
public function update($id, $email, $password, $admin, $transfer)
public function update($id, $email, $password, $admin, $api_key)
{
$user = [
'email' => $email,
'password' => password_hash($password, PASSWORD_DEFAULT),
'admin' => $admin,
'transfer' => $transfer,
'api_key' => $api_key,
];
return $this->model_user->update($id, $user);
@ -201,18 +178,16 @@ namespace controllers\internals;
* @param mixed $email
* @param mixed $password
* @param mixed $admin
* @param mixed $transfer
* @param ?string $api_key : The api key of the user, if null generate randomly
*
* @return mixed bool|int : false on error, id of the new user else
*/
public function create($email, $password, $admin, $transfer = false, ?string $api_key = null)
public function create($email, $password, $admin, ?string $api_key = null)
{
$user = [
'email' => $email,
'password' => password_hash($password, PASSWORD_DEFAULT),
'admin' => $admin,
'transfer' => $transfer,
'api_key' => $api_key ?? $this->generate_random_api_key(),
];

View File

@ -70,44 +70,6 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
/**
* Update user mail transfer property.
*
* @param $csrf : CSRF token
* @param string $_POST['transfer'] : New transfer property value
*/
public function update_transfer($csrf)
{
$transfer = $_POST['transfer'] ?? false;
if (!$this->verify_csrf($csrf))
{
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
if (false === $transfer)
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez choisir une option parmis celles de la liste déroulante.');
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
$transfer_update_result = $this->internal_user->update_transfer($_SESSION['user']['id'], $transfer);
if (!$transfer_update_result)
{
\FlashMessage\FlashMessage::push('danger', 'Impossible de mettre à jour.');
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
$_SESSION['user']['transfer'] = $transfer;
\FlashMessage\FlashMessage::push('success', 'Le transfert a bien été '.($transfer ? 'activé' : 'désactivé').'.');
return $this->redirect(\descartes\Router::url('Account', 'show'));
}
/**
* Update user email.

View File

@ -0,0 +1,38 @@
<?php
use Phinx\Migration\AbstractMigration;
class RemoveTransferFromUser extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$user = $this->table('user');
$user->removeColumn('transfer');
$user->update();
}
}

View File

@ -39,17 +39,6 @@ namespace models;
}
/**
* Return users by their transfer status.
* @param bool $transfer : transfer status
* @return array
*/
public function gets_by_transfer($transfer)
{
return $this->_select('user', ['transfer' => $transfer]);
}
/**
* Return list of user.
*
@ -112,18 +101,6 @@ namespace models;
}
/**
* Update a user transfer property value by his id.
* @param int $id : User id
* @param array $transfer : The new transfer property value
* @return int : Number of modified lines
*/
public function update_transfer($id, $transfer)
{
return $this->_update('user', ['transfer' => $transfer], ['id' => $id]);
}
/**
* Update a user email by his id.
* @param int $id : User id

View File

@ -106,25 +106,6 @@
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><i class="fa fa-share fa-fw"></i> Transfert des SMS par e-mail</h4>
</div>
<div class="panel-body">
<form action="<?php echo \descartes\Router::url('Account', 'update_transfer', ['csrf' => $_SESSION['csrf']]); ?>" method="POST">
<div class="form-group">
<label>Transfert activé : </label>
<select name="transfer" class="form-control">
<option value="0">Non</option>
<option value="1" <?php echo $_SESSION['user']['transfer'] ? 'selected' : ''; ?>>Oui</option>
</select>
</div>
<div class="text-center">
<button class="btn btn-success">Mettre à jour les données</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>