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,5 +1,6 @@
<?php namespace FireflyIII\Models;
use Crypt;
use Illuminate\Database\Eloquent\Model;
/**
@@ -20,7 +21,12 @@ class Preference extends Model
*/
public function getDataAttribute($value)
{
return json_decode($value);
if (is_null($this->data_encrypted)) {
return json_decode($value);
}
$data = Crypt::decrypt($this->data_encrypted);
return json_decode($data);
}
/**
@@ -31,12 +37,37 @@ class Preference extends Model
return ['created_at', 'updated_at'];
}
/**
* @param $value
*
* @return float|int
*/
public function getNameAttribute($value)
{
if (is_null($this->name_encrypted)) {
return $value;
}
$value = Crypt::decrypt($this->name_encrypted);
return $value;
}
/**
* @param $value
*/
public function setDataAttribute($value)
{
$this->attributes['data'] = json_encode($value);
$this->attributes['data'] = '';//json_encode($value);
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
}
/**
* @param $value
*/
public function setNameAttribute($value)
{
$this->attributes['name_encrypted'] = Crypt::encrypt($value);
$this->attributes['name'] = $value;
}
/**