Skip to content

Commit

Permalink
1005 #1 總覺的checkLogin好像哪裡怪怪的
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulipuli Chen committed Oct 5, 2019
1 parent 92fe7f8 commit ada977b
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 94 deletions.
39 changes: 27 additions & 12 deletions client-src/VueController.js
Expand Up @@ -13,6 +13,8 @@ import VueRouter from 'vue-router'
Vue.use(VueRouter)
//import router from 'router.js'

import axios from 'axios'

// --------------------
import routes from './routes'

Expand All @@ -25,9 +27,20 @@ import Chat from './components/Chat/Chat.vue'

let $ = require('jquery')

$('body').append(`<div id="app"></div>`)
// -----------------------
// 確認 baseURL

let baseURL
let baseScript = $('script#ChatAPP:first')
if (baseScript.length === 1) {
baseURL = baseScript.attr('src').split('/').slice(0, 3).join('/')
//console.log(baseURL)
config.baseURL = baseURL
}

// -----------------------

$('body').append(`<div id="app"></div>`)

// -----------------------

Expand All @@ -36,13 +49,6 @@ let VueController = {
i18n: i18n,
template: `
<div class="non-invasive-web-style-framework">
<router-link to="/">
<button type="button" class="ui button">Go to Login</button>
</router-link>
<router-link to="/chat/p">
<button type="button" class="ui button">Go to Chat</button>
</router-link>
<router-view v-bind:config="config"
v-bind:status="status"
v-bind:progress="progress"
Expand All @@ -54,7 +60,7 @@ let VueController = {
status: {
message: 'Hello world.',
username: '',
isLogin: false
//isLogin: false
},
progress: {
component: false,
Expand All @@ -70,16 +76,25 @@ let VueController = {
//"chat-room": Chat
},
router: new VueRouter({
routes
routes: routes
}),
watch: {

},
mounted: function () {

this.checkLogin()
}, // mounted: function () {
methods: {

checkLogin: async function () {
let result = await axios.get(`${this.config.baseURL}/check-login`)
if (result.data === false) {
this.$router.replace('/')
}
else {
this.status.username = result.data
this.$router.replace('/chat')
}
}
} // methods: {
}

Expand Down
12 changes: 5 additions & 7 deletions client-src/components/Chat/Chat.html
@@ -1,4 +1,4 @@
<div class="ui form container">
<div class="ui form segment">

<div class="ui large feed">
<div class="event"
Expand All @@ -22,17 +22,15 @@

<!-- ==================================== -->

<div class="unstackable fields">
<div class="unstackable inline fields">
<div class="ten wide field">
<label for="WritingMessage">
{{ status.username }}
</label>
<div class="ui input fluid">
<label for="WritingMessage">
{{ status.username }}
</label>
<input type="text"
id="WritingMessage"
v-on:keyup.enter="send"
v-model="writingMessage" />
</div>
</div>
<div class="three wide field">
<button type="button"
Expand Down
8 changes: 3 additions & 5 deletions client-src/components/Chat/Chat.js
Expand Up @@ -17,17 +17,14 @@ module.exports = {

},
mounted: function () {
if (this.status.isLogin === false) {
this.$router.replace('/')
return false
}
this.loadUsers()
},
methods: {
loadUsers: async function () {
let users = await axios.get('http://127.0.0.1:3333/user/all')
this.users = users.data
},
/*
addUser: async function () {
let unixMS = (new Date()).getTime()
await axios.get('http://127.0.0.1:3333/user/create', {
Expand All @@ -40,12 +37,13 @@ module.exports = {
console.log('addUser')
this.loadUsers()
},
*/
send: async function () {
console.log(this.message)
},
logout: async function () {
await axios.get(`${this.config.baseURL}/logout`)
this.status.isLogin = false
this.status.username = ''
this.$router.replace('/')
}
} // methods
Expand Down
2 changes: 1 addition & 1 deletion client-src/components/Login/Login.html
@@ -1,4 +1,4 @@
<div class="ui form container">
<div class="ui form segment">

<div class="ui field"
v-if="errorMessage !== ''">
Expand Down
12 changes: 6 additions & 6 deletions client-src/components/Login/Login.js
Expand Up @@ -50,7 +50,7 @@ module.exports = {

//console.log([this.username, this.email, this.password])

let result = await axios.get('http://127.0.0.1:3333/register', {
let result = await axios.get(`${this.config.baseURL}/register`, {
params: {
username: this.username,
email: this.email,
Expand All @@ -69,18 +69,18 @@ module.exports = {
return false
}
else {
this.status.isLogin = true
//this.status.isLogin = true
this.status.username = this.username
this.errorMessage = ''
this.$router.push('chat')
this.$router.replace('chat')
}
},
login: async function() {
this.mode = 'login'

//console.log([this.username, this.email, this.password])

let result = await axios.get('http://127.0.0.1:3333/login', {
let result = await axios.get(`${this.config.baseURL}/login`, {
params: {
username: this.username,
password: this.password,
Expand All @@ -102,10 +102,10 @@ module.exports = {
return false
}
else {
this.status.isLogin = true
//this.status.isLogin = true
this.status.username = this.username
this.errorMessage = ''
this.$router.push('chat')
this.$router.replace('chat')
}
},
loginWithGoogle() {
Expand Down
2 changes: 1 addition & 1 deletion cors/public/index.html
Expand Up @@ -10,6 +10,6 @@
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut hendrerit urna quis mi dignissim dapibus sed congue magna. Praesent nisl quam, congue at felis sit amet, semper vehicula tellus. Suspendisse in tortor diam. Etiam quis finibus ex. Etiam non aliquam odio, ac hendrerit tellus. Nunc venenatis nec quam imperdiet efficitur. Aenean dapibus mi at sollicitudin feugiat. Sed ultricies lectus tellus, vitae cursus leo auctor ut. Donec nec dolor id sem venenatis tincidunt.</p>
</div>

<script src="http://localhost:3333/dist/bundle.js"></script>
<script src="http://localhost:3333/dist/bundle.js" id="ChatAPP"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -14,6 +14,6 @@
APP doesn't work if you see this message.
</div>

<script src="http://localhost:3333/dist/bundle.js"></script>
<script src="http://localhost:3333/dist/bundle.js" id="ChatAPP"></script>
</body>
</html>

0 comments on commit ada977b

Please sign in to comment.