Skip to content

Commit 4740fe8

Browse files
committed
fix(Login): 修复了登录时,即使密码错误仍然认为是登录成功的 bug
修复了在仅登录而没有缓存过任何题面的情况下,设置页面无法进入的 bug 增加了登陆时对账号密码输入框的锁定
1 parent bfd7995 commit 4740fe8

File tree

5 files changed

+75
-75
lines changed

5 files changed

+75
-75
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
使用 vue 进行编译,后对编译后的文件使用 Electron 打包
1212

13-
[下载地址](https://github.com/Hukeqing/codeforces-client/releases/tag/v1.2.0)
13+
[下载地址](https://github.com/Hukeqing/codeforces-client/releases/tag/v1.2.1)
1414

1515
## 功能列表(括号内为实现此功能的版本号)
1616
- [x] 登录(>=0.1.0)
@@ -27,7 +27,7 @@
2727
- [x] 题面中的链接使用本地浏览器打开(>=0.5.0)
2828
- [x] problemset 页面(>=1.0.0)
2929
- [ ] 多语言
30-
- [x] 查看错误的数据
30+
- [x] 查看错误的数据(>=1.2.0)
3131

3232
## 本地编译使用方法
3333
**由于同源策略,如果使用 vue 编译后的文件将会无法正常运行**

src/components/About.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
4747
data() {
4848
return {
49-
version: 'v1.2.0',
49+
version: 'v1.2.1',
5050
latestVersion: '',
5151
updateLink: '',
5252
}

src/components/LocalManager.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default {
105105
total += this.problems[i].memory
106106
if (this.account)
107107
total += (window.localStorage.email.length + window.localStorage.password.length) / 1024
108-
if (window.localStorage.getItem('email') != null)
108+
if (window.localStorage.savedProblem != null)
109109
total += window.localStorage.savedProblem.length / 1024
110110
if (window.localStorage.getItem('setting') != null)
111111
total += window.localStorage.setting.length / 1024

src/components/Login.vue

+70-70
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
使用 Codeforces 账号登录
66
</h1>
77
<p>
8-
<el-input placeholder="请输入邮箱" v-model="email" style="width: 300px"></el-input>
8+
<el-input placeholder="请输入邮箱" v-model="email" :disabled="loading" style="width: 300px"></el-input>
99
</p>
1010
<p>
11-
<el-input placeholder="请输入密码" v-model="password" style="width: 300px" show-password></el-input>
11+
<el-input placeholder="请输入密码" v-model="password" :disabled="loading" style="width: 300px"
12+
show-password></el-input>
1213
</p>
1314
<el-button type="primary" v-on:click="login()" style="width: 250px" :loading="loading" round>登录</el-button>
1415
</div>
@@ -23,91 +24,90 @@
2324
</template>
2425

2526
<script>
27+
let common = require('../static/crawler/common')
2628
27-
let common = require('../static/crawler/common')
29+
export default {
30+
name: "Login",
2831
29-
export default {
30-
name: "Login",
31-
32-
created() {
33-
if (this.user === '') {
34-
if (window.localStorage.email)
35-
this.email = window.localStorage.email;
36-
if (window.localStorage.password)
37-
this.password = window.localStorage.password;
38-
}
39-
},
32+
created() {
33+
if (this.user === '') {
34+
if (window.localStorage.email)
35+
this.email = window.localStorage.email;
36+
if (window.localStorage.password)
37+
this.password = window.localStorage.password;
38+
}
39+
},
4040
41-
props: {
42-
user: String,
43-
logout: String
44-
},
41+
props: {
42+
user: String,
43+
logout: String
44+
},
4545
46-
data() {
47-
return {
48-
loading: false,
49-
email: '',
50-
password: ''
51-
}
52-
},
46+
data() {
47+
return {
48+
loading: false,
49+
email: '',
50+
password: ''
51+
}
52+
},
5353
54-
methods: {
55-
login() {
56-
this.loading = true
57-
// let loading = this.$loading({
58-
// lock: true,
59-
// text: '正在登录',
60-
// background: 'rgba(0, 0, 0, 0.7)'
61-
// })
54+
methods: {
55+
login() {
56+
// let loading = this.$loading({
57+
// lock: true,
58+
// text: '正在登录',
59+
// background: 'rgba(0, 0, 0, 0.7)'
60+
// })
61+
this.loading = true
62+
common.getXCsrfToken((e, x) => {
63+
common.getLoginCookie(x, this.email, this.password, (e, u) => {
64+
// loading.close()
65+
this.loading = false
66+
if (e) {
67+
this.$message.error('登录出错,请重试')
68+
} else {
69+
if (u[0].match(/\/enter/) == null) {
70+
this.user = u[1]
71+
this.logout = u[2]
72+
this.$message.success('登录成功')
73+
this.$emit('login', {user: this.user, logout: this.logout})
74+
} else {
75+
this.$message.error('登录出错,请重试,也可能是账号密码出错')
76+
}
77+
window.localStorage.email = this.email
78+
window.localStorage.password = this.password
79+
}
80+
})
81+
})
82+
},
6283
63-
common.getXCsrfToken((e, x) => {
64-
common.getLoginCookie(x, this.email, this.password, (e, u) => {
84+
toLogout() {
85+
// let loading = this.$loading({
86+
// lock: true,
87+
// text: '正在退出登录',
88+
// background: 'rgba(0, 0, 0, 0.7)'
89+
// })
90+
this.loading = true
91+
common.logout(this.logout, (e) => {
6592
// loading.close()
6693
this.loading = false
6794
if (e) {
68-
this.$message.error('登录出错,请重试')
95+
this.$message.error('退出登录出错,请重试')
6996
} else {
70-
if (u[0] !== '/enter?back=%2F') {
71-
this.user = u[1]
72-
this.logout = u[2]
73-
} else {
74-
this.$message.error('登录出错,请重试')
75-
}
76-
window.localStorage.email = this.email
77-
window.localStorage.password = this.password
78-
this.$message.success('登录成功')
97+
this.$message.success('退出登录成功')
98+
this.user = ''
99+
this.logout = ''
79100
this.$emit('login', {user: this.user, logout: this.logout})
80101
}
81102
})
82-
})
83-
},
84-
85-
toLogout() {
86-
// let loading = this.$loading({
87-
// lock: true,
88-
// text: '正在退出登录',
89-
// background: 'rgba(0, 0, 0, 0.7)'
90-
// })
91-
common.logout(this.logout, (e) => {
92-
// loading.close()
93-
this.loading = false
94-
if (e) {
95-
this.$message.error('退出登录出错,请重试')
96-
} else {
97-
this.$message.success('退出登录成功')
98-
this.user = ''
99-
this.logout = ''
100-
this.$emit('login', {user: this.user, logout: this.logout})
101-
}
102-
})
103+
}
103104
}
104105
}
105-
}
106106
107107
</script>
108108

109109
<style scoped>
110-
.inline-div {
111-
margin-top: 100px;
112-
}
110+
.inline-div {
111+
margin-top: 100px;
112+
}
113113
</style>

src/static/crawler/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = {
5757
const $ = cheerio.load(b)
5858
// update xCsrfToken
5959
basic.xCsrfToken = $('meta[name="X-Csrf-Token"]').prop('content')
60-
console.log(basic.xCsrfToken)
60+
// console.log(basic.xCsrfToken)
6161

6262
const userCheerio = cheerio.load($('div[class="lang-chooser"]').html())
6363
let smallCheerio = cheerio.load(userCheerio(userCheerio('div')[1]).html())

0 commit comments

Comments
 (0)