mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 20:22:07 +00:00
Updated models for encryption.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user