Commit ac45e4f6c81150dadbaef1786e05c9fd681d46ce
1 parent
ff427e6d
修复登陆的bug
Showing
6 changed files
with
58 additions
and
7 deletions
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.vmanager.user; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.vmanager.play.PlayController; | |
| 4 | +import org.slf4j.Logger; | |
| 5 | +import org.slf4j.LoggerFactory; | |
| 6 | +import org.springframework.beans.factory.annotation.Value; | |
| 7 | +import org.springframework.util.StringUtils; | |
| 8 | +import org.springframework.web.bind.annotation.CrossOrigin; | |
| 9 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | +import org.springframework.web.bind.annotation.RestController; | |
| 11 | + | |
| 12 | +@CrossOrigin | |
| 13 | +@RestController | |
| 14 | +@RequestMapping("/api") | |
| 15 | +public class UserController { | |
| 16 | + | |
| 17 | + private final static Logger logger = LoggerFactory.getLogger(UserController.class); | |
| 18 | + | |
| 19 | + | |
| 20 | + @Value("${auth.username}") | |
| 21 | + private String usernameConfig; | |
| 22 | + | |
| 23 | + @Value("${auth.password}") | |
| 24 | + private String passwordConfig; | |
| 25 | + | |
| 26 | + @RequestMapping("/user/login") | |
| 27 | + public String login(String username, String password){ | |
| 28 | + if (!StringUtils.isEmpty(username) && username.equals(usernameConfig) | |
| 29 | + && !StringUtils.isEmpty(password) && password.equals(passwordConfig)) { | |
| 30 | + return "success"; | |
| 31 | + }else { | |
| 32 | + return "fail"; | |
| 33 | + } | |
| 34 | + } | |
| 35 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/web/AuthController.java
| ... | ... | @@ -19,12 +19,12 @@ public class AuthController { |
| 19 | 19 | private String password; |
| 20 | 20 | |
| 21 | 21 | @RequestMapping("/login") |
| 22 | - public Object devices(String username, String password){ | |
| 23 | - if (!StringUtils.isEmpty(username) && username.equals(username) | |
| 24 | - && !StringUtils.isEmpty(password) && password.equals(password)) { | |
| 22 | + public String devices(String name, String passwd){ | |
| 23 | + if (!StringUtils.isEmpty(name) && name.equals(username) | |
| 24 | + && !StringUtils.isEmpty(passwd) && passwd.equals(password)) { | |
| 25 | 25 | return "success"; |
| 26 | 26 | }else { |
| 27 | - return "fait"; | |
| 27 | + return "fail"; | |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | } | ... | ... |
web_src/package-lock.json
| ... | ... | @@ -5175,6 +5175,11 @@ |
| 5175 | 5175 | "integrity": "sha1-9OaGxd4eofhn28rT1G2WlCjfmMQ=", |
| 5176 | 5176 | "dev": true |
| 5177 | 5177 | }, |
| 5178 | + "js-md5": { | |
| 5179 | + "version": "0.7.3", | |
| 5180 | + "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz", | |
| 5181 | + "integrity": "sha512-ZC41vPSTLKGwIRjqDh8DfXoCrdQIyBgspJVPXHBGu4nZlAEvG3nf+jO9avM9RmLiGakg7vz974ms99nEV0tmTQ==" | |
| 5182 | + }, | |
| 5178 | 5183 | "js-tokens": { |
| 5179 | 5184 | "version": "3.0.2", |
| 5180 | 5185 | "resolved": "https://registry.npm.taobao.org/js-tokens/download/js-tokens-3.0.2.tgz", | ... | ... |
web_src/package.json
web_src/src/components/Login.vue
| ... | ... | @@ -18,7 +18,6 @@ |
| 18 | 18 | </template> |
| 19 | 19 | |
| 20 | 20 | <script> |
| 21 | -import crypto from 'crypto' | |
| 22 | 21 | export default { |
| 23 | 22 | name: 'Login', |
| 24 | 23 | data(){ |
| ... | ... | @@ -56,13 +55,13 @@ export default { |
| 56 | 55 | //需要想后端发送的登录参数 |
| 57 | 56 | let loginParam = { |
| 58 | 57 | username: this.username, |
| 59 | - password: crypto.createHash('md5').update(this.password, "utf8").digest('hex') | |
| 58 | + password: this.$md5(this.password) | |
| 60 | 59 | } |
| 61 | 60 | var that = this; |
| 62 | 61 | //设置在登录状态 |
| 63 | 62 | this.isLoging = true; |
| 64 | 63 | |
| 65 | - this.$axios.get("/auth/login",{ | |
| 64 | + this.$axios.get("/api/user/login",{ | |
| 66 | 65 | params: loginParam |
| 67 | 66 | } ) |
| 68 | 67 | .then(function (res) { |
| ... | ... | @@ -71,6 +70,13 @@ export default { |
| 71 | 70 | that.$cookies.set("session", {"username": that.username}) ; |
| 72 | 71 | //登录成功后 |
| 73 | 72 | that.$router.push('/'); |
| 73 | + }else{ | |
| 74 | + that.isLoging = false; | |
| 75 | + that.$message({ | |
| 76 | + showClose: true, | |
| 77 | + message: '登录失败,用户名或密码错误', | |
| 78 | + type: 'error' | |
| 79 | + }); | |
| 74 | 80 | } |
| 75 | 81 | }) |
| 76 | 82 | .catch(function (error) { | ... | ... |
web_src/src/main.js
| ... | ... | @@ -9,6 +9,10 @@ import VueCookies from 'vue-cookies'; |
| 9 | 9 | import echarts from 'echarts'; |
| 10 | 10 | |
| 11 | 11 | import VueClipboard from 'vue-clipboard2' |
| 12 | + | |
| 13 | +import md5 from 'js-md5' | |
| 14 | +Vue.prototype.$md5 = md5 | |
| 15 | + | |
| 12 | 16 | Vue.use(VueClipboard) |
| 13 | 17 | Vue.use(ElementUI); |
| 14 | 18 | Vue.use(VueCookies); | ... | ... |