diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php
index b92e488..e279091 100644
--- a/app/Http/Controllers/DashboardController.php
+++ b/app/Http/Controllers/DashboardController.php
@@ -11,8 +11,6 @@ use DateTime;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
-use Intervention\Image\Constraint;
-use Intervention\Image\Facades\Image;
class DashboardController extends Controller
{
@@ -37,6 +35,7 @@ class DashboardController extends Controller
setlocale(LC_TIME, 'fr_FR.utf8');
$today = new DateTime();
$user_id = Auth::user()->getAuthIdentifier();
+ $user = \App\User::find($user_id);
$all_counts = Post::where('user_id', $user_id)->count();
$year_counts = Post::where('user_id', $user_id)->whereYear('date_post', $today->format('Y'))->count();
$month_counts = Post::where('user_id', $user_id)
@@ -57,6 +56,7 @@ class DashboardController extends Controller
return view('home', [
'already' => $already,
+ 'must_encrypt' => $user->encrypt_messages,
'all_counts' => $all_counts,
'year_counts' => $year_counts,
'month_counts' => $month_counts,
diff --git a/database/migrations/2019_10_08_100005_update_users_encryption.php b/database/migrations/2019_10_08_100005_update_users_encryption.php
new file mode 100644
index 0000000..5bc3eba
--- /dev/null
+++ b/database/migrations/2019_10_08_100005_update_users_encryption.php
@@ -0,0 +1,32 @@
+boolean('encrypt_messages')->default(true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('users', function (Blueprint $table) {
+ $table->removeColumn('encrypt_messages');
+ });
+ }
+}
diff --git a/package.json b/package.json
index b5e53e4..834b6b9 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,9 @@
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
+ "endcrypt": "^1.2.3",
"tabler-ui": "^0.0.34",
- "textarea-caret": "^3.1.0"
+ "textarea-caret": "^3.1.0",
+ "vue2-storage": "^4.0.5"
}
}
diff --git a/resources/js/app.js b/resources/js/app.js
index 0c76ddc..f9650c1 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -27,41 +27,104 @@ window.Vue = require('vue');
* or customize the JavaScript scaffolding to fit your unique needs.
*/
-import App from './components/App.vue';
+import Vue from 'vue';
+import Autocomplete from './components/Autocomplete.vue';
+import {Endcrypt} from 'endcrypt';
+import {Vue2Storage} from 'vue2-storage';
+const e = new Endcrypt();
+
+// You can specify the plug-in configuration when connecting, passing the second object to Vue.use
+Vue.use(Vue2Storage, {
+ prefix: 'journal_',
+ driver: 'session',
+ ttl: 60 * 60 * 24 * 1000
+});
Vue.config.productionTip = false;
-/** Function for collapse card */
-document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card){
- card.addEventListener('click', function(evt) {
- let $card = this.parentElement.parentElement.parentElement;
+let storeId = 'store';
+let storeElement = document.getElementById(storeId);
- $card.classList.toggle('card-collapsed');
- evt.preventDefault();
- return false;
+Vue.component(
+ 'messageform', {
+ name: 'MessageForm',
+ props: {
+ 'imageLabel': {
+ type: String,
+ default: "Choisir une image"
+ },
+ 'uploadClass': {
+ type: String,
+ default: "fe fe-upload"
+ },
+ 'mustencrypt': {
+ type: Boolean,
+ default: true
+ },
+ 'possible': {
+ type: Boolean,
+ default: false
+ }
+ },
+ methods: {
+ encrypt: function(evt) {
+ evt.preventDefault();
+ if (this.mustencrypt) {
+ // https://www.npmjs.com/package/endcrypt
+ let plain = document.querySelector("[name=message]").value;
+ document.querySelector("[name=message]").value = JSON.stringify(e.encryptWithKey(plain, this.$storage.get('passphrase')));
+ }
+ document.getElementById('messageForm').submit();
+ return false;
+ },
+ fileNameChanged: function(inputName, inputFiles) {
+ let file = inputFiles[0];
+ let imageName = file["name"];
+ if (imageName !== "") {
+ imageName = imageName.split('\\').pop();
+ }
+ if (imageName !== "") {
+ this.uploadClass = "fe fe-check";
+ this.imageLabel = imageName;
+ } else {
+ this.uploadClass = "fe fe-upload";
+ this.imageLabel = "Choisir une image";
+ }
+ }
+ },
+ beforeMount: function() {
+ let passphrase = this.$storage.get('passphrase', '');
+ if (passphrase === '') {
+ passphrase = prompt('Merci d\'entrer votre phrase de passe');
+ this.$storage.set('passphrase', passphrase);
+ }
+ /** Function for collapse and decrypt cards */
+ let $this = this;
+ document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card){
+ let cardBody = card.parentElement.parentElement.parentElement.querySelector("[data-encrypt]");
+ try {
+ let cardBodyDecrypted = JSON.parse(cardBody.innerHTML.trim());
+ cardBody.innerHTML = e.decryptWithKey(cardBodyDecrypted, $this.$storage.get('passphrase'));
+ } catch (e) {
+ console.log('can\'t decode '+ cardBody.innerHTML);
+ }
+ card.addEventListener('click', function(evt) {
+ let $card = this.parentElement.parentElement.parentElement;
+
+ $card.classList.toggle('card-collapsed');
+ evt.preventDefault();
+ return false;
+ });
+ });
+ },
+ components: {
+ Autocomplete
+ }
+ }
+);
+
+if (document.getElementById("store")) {
+ new Vue({
+ el: '#store'
});
-});
-
-let fileNameChanged = function(element, label) {
- let labelVal = label.innerText;
- let fileName = '';
- if (element.value) {
- fileName = element.value.split('\\').pop();
- }
- if (fileName) {
- label.firstChild.nextSibling.classList = "fe fe-check";
- label.querySelector('.js-fileName').innerHTML = fileName;
- } else {
- label.firstChild.nextSibling.classList = "fe fe-upload";
- label.querySelector('.js-fileName').innerHTML = labelVal;
- }
-};
-let inputFiles = document.querySelectorAll(".input-file");
-for (let i = 0, l = inputFiles.length; i < l; i++) {
- inputFiles[i].onchange = fileNameChanged.bind(null, inputFiles[i], inputFiles[i].nextSibling.nextSibling);
}
-
-// new Vue();
-const app = new Vue({
- render: h => h(App),
-}).$mount('#app');
diff --git a/resources/js/components/App.vue b/resources/js/components/App.vue
deleted file mode 100644
index 262db4e..0000000
--- a/resources/js/components/App.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
{!! $tag_detector->linkTagFrom($post->content) !!}