Skip to content

Commit

Permalink
add update user. update screen logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
hirotaka.koga committed Dec 9, 2018
1 parent 34b1547 commit b8753b7
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 68 deletions.
2 changes: 2 additions & 0 deletions Memo.md
Expand Up @@ -149,6 +149,8 @@ yarn add monaco-editor

yarn add vee-validate

yarn add es6-promise

yarn run build

yarn run build && yarn run hot
Expand Down
19 changes: 19 additions & 0 deletions app/Http/Controllers/Auth/Rest/RestLoginController.php
Expand Up @@ -61,4 +61,23 @@ public function user(Request $request) {
// 認証ユーザ情報を返す
return ['check' => Auth::check(), 'user' => Auth::user()];
}

/**
* update.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request) {
$user = Auth::user();

if ($request->has('email')) $user->email = $request->input('email');
if ($request->has('name')) $user->name = $request->input('name');
//if ($request->has('password')) $user->name = $request->input('password');
if ($request->has('markdown')) $user->markdown = $request->input('markdown');
if ($request->has('gtoken')) $user->gtoken = $request->input('gtoken');
$user->save();

return ['update' => true, 'user' => Auth::user()];
}
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"bootstrap-honoka": "^4.1.3",
"es6-promise": "^4.2.5",
"monaco-editor": "^0.15.6",
"open-iconic": "^1.1.1",
"tui-editor": "^1.2.6",
Expand Down
91 changes: 50 additions & 41 deletions public/mix-manifest.json
@@ -1,45 +1,54 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css",
"/0.ff766803b30bd3c7713c.hot-update.js": "/0.ff766803b30bd3c7713c.hot-update.js",
"/0.80bde75d7328f16e1c45.hot-update.js": "/0.80bde75d7328f16e1c45.hot-update.js",
"/0.b0bf0b80491845fd4a09.hot-update.js": "/0.b0bf0b80491845fd4a09.hot-update.js",
"/0.51dd5a4fb06074459f97.hot-update.js": "/0.51dd5a4fb06074459f97.hot-update.js",
"/0.01bbefb99099980c9bd5.hot-update.js": "/0.01bbefb99099980c9bd5.hot-update.js",
"/0.4a9dba3d39478ebb77d8.hot-update.js": "/0.4a9dba3d39478ebb77d8.hot-update.js",
"/0.e763779e63a90dc58edf.hot-update.js": "/0.e763779e63a90dc58edf.hot-update.js",
"/0.4bd9b3a7835f6466ec50.hot-update.js": "/0.4bd9b3a7835f6466ec50.hot-update.js",
"/0.4eecc91bb61ea7ee9ff0.hot-update.js": "/0.4eecc91bb61ea7ee9ff0.hot-update.js",
"/0.13657acccc146062c7e6.hot-update.js": "/0.13657acccc146062c7e6.hot-update.js",
"/0.2a3038d36867617f9be4.hot-update.js": "/0.2a3038d36867617f9be4.hot-update.js",
"/0.06d845d61f57eabdfe8d.hot-update.js": "/0.06d845d61f57eabdfe8d.hot-update.js",
"/0.48c35aa99da76221bcaa.hot-update.js": "/0.48c35aa99da76221bcaa.hot-update.js",
"/0.5a81fd74c6b991774d4b.hot-update.js": "/0.5a81fd74c6b991774d4b.hot-update.js",
"/0.869ba0dc8fc466fdd9fc.hot-update.js": "/0.869ba0dc8fc466fdd9fc.hot-update.js",
"/0.450024d9afbc03849e15.hot-update.js": "/0.450024d9afbc03849e15.hot-update.js",
"/0.fa62c66ad5d04c278f31.hot-update.js": "/0.fa62c66ad5d04c278f31.hot-update.js",
"/0.11c87fc139c432424d38.hot-update.js": "/0.11c87fc139c432424d38.hot-update.js",
"/0.af16433dd584f86d396e.hot-update.js": "/0.af16433dd584f86d396e.hot-update.js",
"/0.6a09e68b9b9a24ef702a.hot-update.js": "/0.6a09e68b9b9a24ef702a.hot-update.js",
"/0.b03beebb7b6f991183ab.hot-update.js": "/0.b03beebb7b6f991183ab.hot-update.js",
"/0.5ed6fa3d2a5a5439e36d.hot-update.js": "/0.5ed6fa3d2a5a5439e36d.hot-update.js",
"/0.f2a5fbcd0d7d70b6aa4d.hot-update.js": "/0.f2a5fbcd0d7d70b6aa4d.hot-update.js",
"/0.bdc2c04ec1f37479787c.hot-update.js": "/0.bdc2c04ec1f37479787c.hot-update.js",
"/0.83c96ae32edd2a365b56.hot-update.js": "/0.83c96ae32edd2a365b56.hot-update.js",
"/0.7f665706317c7abd6f83.hot-update.js": "/0.7f665706317c7abd6f83.hot-update.js",
"/0.240c50214addc2102413.hot-update.js": "/0.240c50214addc2102413.hot-update.js",
"/0.2184d6790dbcbd75aa53.hot-update.js": "/0.2184d6790dbcbd75aa53.hot-update.js",
"/0.3854d95516836515b281.hot-update.js": "/0.3854d95516836515b281.hot-update.js",
"/0.0d617251ee53c3e0c263.hot-update.js": "/0.0d617251ee53c3e0c263.hot-update.js",
"/0.a08acef3e62d02c91afb.hot-update.js": "/0.a08acef3e62d02c91afb.hot-update.js",
"/0.e73649aa85d6ad0dacec.hot-update.js": "/0.e73649aa85d6ad0dacec.hot-update.js",
"/0.788c6b329d9f86f14e39.hot-update.js": "/0.788c6b329d9f86f14e39.hot-update.js",
"/0.89f4104f65a925c1ffcf.hot-update.js": "/0.89f4104f65a925c1ffcf.hot-update.js",
"/0.7ffc1623fb752be3737e.hot-update.js": "/0.7ffc1623fb752be3737e.hot-update.js",
"/0.418ccb512eaaed127ff1.hot-update.js": "/0.418ccb512eaaed127ff1.hot-update.js",
"/0.5cd6a7fad6d2bf08e375.hot-update.js": "/0.5cd6a7fad6d2bf08e375.hot-update.js",
"/0.fd74102df7d2bb83580c.hot-update.js": "/0.fd74102df7d2bb83580c.hot-update.js",
"/0.e0f5d0e6b9fae6dec103.hot-update.js": "/0.e0f5d0e6b9fae6dec103.hot-update.js",
"/0.938c658e37a3a2a357c1.hot-update.js": "/0.938c658e37a3a2a357c1.hot-update.js",
"/0.ddd46225ecc68cab3a08.hot-update.js": "/0.ddd46225ecc68cab3a08.hot-update.js"
"/0.3fa18f54dc652bd5bd62.hot-update.js": "/0.3fa18f54dc652bd5bd62.hot-update.js",
"/0.4758d0eb373ed9c7a77f.hot-update.js": "/0.4758d0eb373ed9c7a77f.hot-update.js",
"/0.408c1efae6deaa4820d4.hot-update.js": "/0.408c1efae6deaa4820d4.hot-update.js",
"/0.6afdab49e83178d33fd7.hot-update.js": "/0.6afdab49e83178d33fd7.hot-update.js",
"/0.3abbc233bb12b604e237.hot-update.js": "/0.3abbc233bb12b604e237.hot-update.js",
"/0.46a2e3d86208fd970aba.hot-update.js": "/0.46a2e3d86208fd970aba.hot-update.js",
"/0.7eb30545e33373e6b376.hot-update.js": "/0.7eb30545e33373e6b376.hot-update.js",
"/0.9c96042e7021c979b1b7.hot-update.js": "/0.9c96042e7021c979b1b7.hot-update.js",
"/0.5cda46f2a9706266ca26.hot-update.js": "/0.5cda46f2a9706266ca26.hot-update.js",
"/0.28f355477668549ce242.hot-update.js": "/0.28f355477668549ce242.hot-update.js",
"/0.3e48d2e1567939c010b7.hot-update.js": "/0.3e48d2e1567939c010b7.hot-update.js",
"/0.ded744609dcbb4dbad01.hot-update.js": "/0.ded744609dcbb4dbad01.hot-update.js",
"/0.545710289cfebeadad50.hot-update.js": "/0.545710289cfebeadad50.hot-update.js",
"/0.d6699d1edef9a4be2dd4.hot-update.js": "/0.d6699d1edef9a4be2dd4.hot-update.js",
"/0.4fb3fd4b6c06c960e316.hot-update.js": "/0.4fb3fd4b6c06c960e316.hot-update.js",
"/0.1e2f9f8ee7383daf4afc.hot-update.js": "/0.1e2f9f8ee7383daf4afc.hot-update.js",
"/0.214c77e1d66667111318.hot-update.js": "/0.214c77e1d66667111318.hot-update.js",
"/0.e40b719474da96d5c5b7.hot-update.js": "/0.e40b719474da96d5c5b7.hot-update.js",
"/0.57e1e5c783d15dd50c8f.hot-update.js": "/0.57e1e5c783d15dd50c8f.hot-update.js",
"/0.6ad50b6f672b2d5b5632.hot-update.js": "/0.6ad50b6f672b2d5b5632.hot-update.js",
"/0.c19474f3402d74929308.hot-update.js": "/0.c19474f3402d74929308.hot-update.js",
"/0.59f67fb8c02b68b9b3a4.hot-update.js": "/0.59f67fb8c02b68b9b3a4.hot-update.js",
"/0.69c0b42840b671754378.hot-update.js": "/0.69c0b42840b671754378.hot-update.js",
"/0.61bf3ff8830a466448f6.hot-update.js": "/0.61bf3ff8830a466448f6.hot-update.js",
"/0.c2998b4f392ce2691190.hot-update.js": "/0.c2998b4f392ce2691190.hot-update.js",
"/0.7dd462e0793eee905268.hot-update.js": "/0.7dd462e0793eee905268.hot-update.js",
"/0.c2e45820c89d5275ad14.hot-update.js": "/0.c2e45820c89d5275ad14.hot-update.js",
"/0.4bfc791007a71d5526a6.hot-update.js": "/0.4bfc791007a71d5526a6.hot-update.js",
"/0.e8000df6680050f1eca9.hot-update.js": "/0.e8000df6680050f1eca9.hot-update.js",
"/0.550925f23ffb2c59c72a.hot-update.js": "/0.550925f23ffb2c59c72a.hot-update.js",
"/0.a84656a652c775d9ca0a.hot-update.js": "/0.a84656a652c775d9ca0a.hot-update.js",
"/0.df65e0da83e1d8a4ff8e.hot-update.js": "/0.df65e0da83e1d8a4ff8e.hot-update.js",
"/0.5543dc8000869254150f.hot-update.js": "/0.5543dc8000869254150f.hot-update.js",
"/0.b5aaa51d3a09ccd68322.hot-update.js": "/0.b5aaa51d3a09ccd68322.hot-update.js",
"/0.c51c713e1b569b5263b8.hot-update.js": "/0.c51c713e1b569b5263b8.hot-update.js",
"/0.c3b9ce9c6d270eeb841a.hot-update.js": "/0.c3b9ce9c6d270eeb841a.hot-update.js",
"/0.83800e0d19959a6c70a8.hot-update.js": "/0.83800e0d19959a6c70a8.hot-update.js",
"/0.badbb3a51fd191717312.hot-update.js": "/0.badbb3a51fd191717312.hot-update.js",
"/0.fa37b9ff00c77f9f677f.hot-update.js": "/0.fa37b9ff00c77f9f677f.hot-update.js",
"/0.4376c4c6ec8fc7f0af05.hot-update.js": "/0.4376c4c6ec8fc7f0af05.hot-update.js",
"/0.e4cb93fd1dd623801b5a.hot-update.js": "/0.e4cb93fd1dd623801b5a.hot-update.js",
"/0.7050559ef2185f361757.hot-update.js": "/0.7050559ef2185f361757.hot-update.js",
"/0.c68925b401b99db180b6.hot-update.js": "/0.c68925b401b99db180b6.hot-update.js",
"/0.51c9ae20031a3c316313.hot-update.js": "/0.51c9ae20031a3c316313.hot-update.js",
"/0.2f1f5dbebd65d91f5bca.hot-update.js": "/0.2f1f5dbebd65d91f5bca.hot-update.js",
"/0.04652462f22840ede6d0.hot-update.js": "/0.04652462f22840ede6d0.hot-update.js",
"/0.09effc604df047e4128f.hot-update.js": "/0.09effc604df047e4128f.hot-update.js",
"/0.583705f3555e206b583b.hot-update.js": "/0.583705f3555e206b583b.hot-update.js",
"/0.dfd1daa34991821a7d52.hot-update.js": "/0.dfd1daa34991821a7d52.hot-update.js",
"/0.663597de208af1b692b6.hot-update.js": "/0.663597de208af1b692b6.hot-update.js"
}
131 changes: 107 additions & 24 deletions resources/js/app.js
Expand Up @@ -10,6 +10,9 @@ require('./bootstrap');
require('./halocontext/jquery.halocontext');
require('./sidebar/bootstrap-sidebar');

// import es6 promise
import 'es6-promise/auto';

// import VeeValidate
import VeeValidate, { Validator } from'vee-validate';

Expand All @@ -19,6 +22,10 @@ import Editor from 'tui-editor/dist/tui-editor-Editor-all.js';
// require Vue
window.Vue = require('vue');

// import Vuex
import Vuex from 'vuex';
window.Vue.use(Vuex);

// use VeeValidate
window.Vue.use(VeeValidate);

Expand Down Expand Up @@ -48,12 +55,23 @@ Vue.component('example-component', require('./components/ExampleComponent.vue'))
// return Vue.component(_.last(key.split('/')).split('.')[0], files(key))
// })

// const editor = new Editor({
// el: document.querySelector('#edit-section'),
// //viewer: true,
// initialEditType: 'markdown',
// useCommandShortcut: true,
// previewStyle: 'vertical',
// height: '100%',
// initialValue: '',
// language: 'ja',
// exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table']
// });

/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/

const app = new Vue({
el: '#app',
methods: {
Expand All @@ -70,18 +88,6 @@ const app = new Vue({
}
},
mounted() {
var editor = new Editor({
el: document.querySelector('#editSection'),
//viewer: true,
initialEditType: 'markdown',
useCommandShortcut: true,
previewStyle: 'vertical',
height: '100%',
initialValue: '',
language: 'ja',
exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table']
});

// const params = { path : 'welcome.md' };
// const url = "http://"+this.backend+"/gdrive";

Expand All @@ -101,8 +107,63 @@ const app = new Vue({
}
});

const store = new Vuex.Store({
state: {
user: null,
editor: new Editor({
el: document.querySelector('#edit-section'),
//viewer: true,
initialEditType: 'markdown',
useCommandShortcut: true,
previewStyle: 'vertical',
height: '100%',
initialValue: '',
language: 'ja',
exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table'],
events: {change: function() {
//console.log("change markdown.");
if (store.state.user)
store.state.user.markdown = store.state.editor.getMarkdown();
//console.log("update markdown.");
}}
})
},
// Storeに対するGetterを定義
getters: {
user(state) {
return state.user;
},
editor(state) {
return state.editor;
},
editorMarkdown(state) {
return state.editor.getMarkdown();
}
},
// Storeに対するActionを定義
actions: {
setUser (context, user) {
context.commit('SET_USER', user); // Actionはmutationsを呼ぶ
},
setMarkdown (context, markdown) {
context.commit('SET_MARKDOWN', markdown); // Actionはmutationsを呼ぶ
},
},
mutations: {
SET_USER (state, user) {
state.user = user;
state.editor.setMarkdown(state.user.markdown, false/*cursorToEndopt*/);
//console.log(state.user);
},
SET_MARKDOWN (state, markdown) {
state.editor.setMarkdown(markdown, false/*cursorToEndopt*/);
},
},
});

const login = new Vue({
el: '#login',
store: store,
data: {
name: null,
email: null,
Expand All @@ -129,14 +190,17 @@ const login = new Vue({

// バリデーションする
this.$validator.errors.remove('notification');
this.$validator.errors.remove('unmatch');
this.$validator.errors.remove('unregist');

this.$validator.validateAll().then((result) => {
if ( this.regist && !result ) {
// 新規登録で入力エラー
this.$validator.errors.add({field: 'notification', msg: '入力エラーがあります...'});
this.$validator.errors.add({field: 'notification', msg: 'msg'});
return false;
} else if ( this.regist && (errors.has('email') || errors.has('password')) ) {
} else if ( !this.regist && (this.$validator.errors.has('email') || this.$validator.errors.has('password')) ) {
// ログインで入力エラー
this.$validator.errors.add({field: 'notification', msg: '入力エラーがあります...'});
this.$validator.errors.add({field: 'notification', msg: 'msg'});
return false;
}
});
Expand All @@ -145,20 +209,39 @@ const login = new Vue({
// ユーザ登録する
axios.post('/api/register', { name: this.name, email: this.email, password: this.password, password_confirmation: this.password_confirmation })
.then(function(response) {
alert(JSON.stringify(response.data));
})
// alert(JSON.stringify(response.data));
if(response.data.register) {
$('#login-modal').modal('hide');
this.$store.dispatch('setUser', response.data.user);
} else {
this.$validator.errors.add({field: 'unregist', msg: 'msg'});
}
}.bind(this))// thisを使う
.catch(function(error) {
console.log('ERROR!! occurred in Backend.')
});
console.log('ERROR!! occurred in Backend.');
// errorを展開する alert(error.response.data.errors.email[0]);
Object.keys(error.response.data.errors).forEach(function(errorObjKey){
error.response.data.errors[errorObjKey].forEach(function(errorObj, index, ar){
this.$validator.errors.add({field: 'regist_error', msg: errorObj});
}, this);
}, this);
}.bind(this));// thisを使う
} else {
// ユーザ認証する
axios.post('/api/login', { email: this.email, password: this.password })
.then(function(response) {
alert(JSON.stringify(response.data));
})
// alert(JSON.stringify(response.data));
if(response.data.auth) {
$('#login-modal').modal('hide');
this.$store.dispatch('setUser', response.data.user);
this.$store.dispatch('setMarkdown', response.data.user.markdown);
} else {
this.$validator.errors.add({field: 'unmatch', msg: 'msg'});
}
}.bind(this))// thisを使う
.catch(function(error) {
console.log('ERROR!! occurred in Backend.')
});
console.log('ERROR!! occurred in Backend.');
}.bind(this));// thisを使う
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions resources/views/layouts/app.blade.php
Expand Up @@ -436,7 +436,7 @@
@yield('content')
</main>
</div>
<div id="editSection" class="m-0 mw-100" style="max-height: calc(100% - 15px);"></div>
<div id="edit-section" class="m-0 mw-100" style="max-height: calc(100% - 15px);"></div>
</main>
<nav class="sidebar bg-light simple always mini">
<div class="sticky-top">
Expand Down Expand Up @@ -524,13 +524,14 @@
<div class="form-check custom-control custom-checkbox"><!-- custom-control-inline -->
<input type="checkbox" class="custom-control-input dropdown-toggle" id="regist" v-model="regist" v-bind:class="{ 'is-invalid': errors.has('unregist') }" role="button" data-toggle="collapse" aria-expanded="false">
<label class="custom-control-label" for="regist">新規登録</label>
<span class="invalid-tooltip">既に登録されています。</span>
<span class="invalid-tooltip">登録できませんでした、既に登録されている可能性があります。</span>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">閉じる</button>
<button class="form-control btn btn-primary" type="button" v-on:click="login" v-bind:class="{ 'is-invalid': errors.has('notification') }">ログイン</button>
<button class="form-control btn btn-primary" type="button" v-on:click="login" v-bind:class="{ 'is-invalid': errors.has('notification') || errors.has('regist_error') }">ログイン</button>
<span class="invalid-tooltip" v-show="errors.has('notification')">入力エラーがあります。</span>
<span class="invalid-tooltip" v-show="errors.has('regist_error')">@{{ errors.first('regist_error') }}</span>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Expand Up @@ -23,6 +23,7 @@
Route::post('/logout', 'Auth\Rest\RestLoginController@logout');// function(Request $request) { return ['check' => Auth::check(), 'user' => Auth::user()]; }
// curl -X POST -H 'X-CSRF-TOKEN: 〜' -H 'Accept: application/json' "http://localhost:8000/api/unregister"
Route::post('/unregister', 'Auth\Rest\RestRegisterController@unregister');
Route::post('/update', 'Auth\Rest\RestLoginController@update');

Route::resource('/drive', 'Drive\OperationController');
Route::post('/drive/auth', 'Drive\OperationController@auth');
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/LoginTest.php
Expand Up @@ -44,6 +44,19 @@ public function setUp() {
$this->headersWithToken['Authorization'] = 'Bearer ' . $api_token;
}

/**
* 更新
* @return void
*/
public function testUpdate() {
$this->user['name'] = 'update';
$this->user['markdown'] = '# AAA';
$response = $this->withHeaders($this->headersWithToken)->post("/api/update", $this->user);
echo var_dump($response->content(), false);
$response
->assertJson(['update' => true]);
}

/**
* ユーザ情報を取得
* @return void
Expand Down

0 comments on commit b8753b7

Please sign in to comment.