Updated models for encryption.

This commit is contained in:
James Cole
2015-05-23 08:46:46 +02:00
parent 1c2cbd5b40
commit f05002c729
10 changed files with 221 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
<?php namespace FireflyIII\Models;
use Carbon\Carbon;
use Crypt;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
@@ -66,4 +67,31 @@ class PiggyBankRepetition extends Model
);
}
/**
* @param $value
*
* @return float|int
*/
public function getCurrentamountAttribute($value)
{
if (is_null($this->currentamount_encrypted)) {
return $value;
}
$value = intval(Crypt::decrypt($this->currentamount_encrypted));
$value = $value / 100;
return $value;
}
/**
* @param $value
*/
public function setCurrentamountAttribute($value)
{
// save in cents:
$value = intval($value * 100);
$this->attributes['currentamount_encrypted'] = Crypt::encrypt($value);
$this->attributes['currentamount'] = ($value / 100);
}
}