| @@ -18,6 +18,7 @@ | |||
| localStorage.setItem('username', user.username); | |||
| localStorage.setItem('level', user.level); | |||
| localStorage.setItem('department', user.department); | |||
| localStorage.setItem('account', user.account); | |||
| } | |||
| } | |||
| const level = localStorage.getItem('level'); | |||
| @@ -49,6 +50,7 @@ | |||
| localStorage.removeItem('username'); | |||
| localStorage.removeItem('department'); | |||
| localStorage.removeItem('level'); | |||
| localStorage.removeItem('account'); | |||
| } | |||
| } | |||
| } | |||
| @@ -136,6 +136,37 @@ | |||
| </v-menu> | |||
| </v-app-bar> | |||
| <v-content> | |||
| <v-dialog width="500" v-model="dialogModifyPwd" @click:outside="dialogModifyPwd = false"> | |||
| <v-card> | |||
| <v-card-title> | |||
| <span class="headline font-weight-bold">修改密碼</span> | |||
| </v-card-title> | |||
| <v-card-text> | |||
| <v-container> | |||
| <v-text-field v-model="oldPwd" type="password" outlined rounded label="舊密碼"/> | |||
| <v-text-field v-model="newPwd" type="password" outlined rounded label="新密碼"/> | |||
| <v-text-field v-model="chechNewPwd" type="password" outlined rounded label="確認新密碼"/> | |||
| </v-container> | |||
| </v-card-text> | |||
| <v-card-actions> | |||
| <v-spacer></v-spacer> | |||
| <v-btn | |||
| color="blue darken-1" | |||
| text | |||
| @click="() => {this.dialogModifyPwd = false; this.newPwd = ''; this.oldPwd = ''; this.chechNewPwd = '';}" | |||
| > | |||
| 取消 | |||
| </v-btn> | |||
| <v-btn | |||
| color="blue darken-1" | |||
| text | |||
| @click="modifyPwd" | |||
| > | |||
| 修改 | |||
| </v-btn> | |||
| </v-card-actions> | |||
| </v-card> | |||
| </v-dialog> | |||
| <keep-alive> | |||
| <router-view></router-view> | |||
| </keep-alive> | |||
| @@ -170,6 +201,15 @@ | |||
| this1: this, | |||
| menuitems: [ | |||
| { | |||
| icon: 'mdi-pencil', | |||
| href: '', | |||
| title: '修改密碼', | |||
| click: () => { | |||
| // this.this1.logout(); | |||
| this.dialogModifyPwd = true; | |||
| }, | |||
| }, | |||
| { | |||
| icon: 'mdi-exit-to-app', | |||
| href: '#', | |||
| title: '登出', | |||
| @@ -178,6 +218,10 @@ | |||
| }, | |||
| }, | |||
| ], | |||
| dialogModifyPwd: false, | |||
| oldPwd: '', | |||
| newPwd: '', | |||
| chechNewPwd: '', | |||
| } | |||
| }, | |||
| created() { | |||
| @@ -204,7 +248,8 @@ | |||
| this.$emit("authenticated", { | |||
| 'username': null, | |||
| 'department': null, | |||
| 'level': null | |||
| 'level': null, | |||
| 'account': null, | |||
| }); | |||
| }, | |||
| async getRoutes() { | |||
| @@ -240,6 +285,38 @@ | |||
| if (level === '3') { | |||
| this.items = [{'text': '資訊資產清冊', 'route': '/serverlist'}]; | |||
| } | |||
| }, | |||
| modifyPwd() { | |||
| if (this.newPwd !== this.chechNewPwd) { | |||
| alert('請確認新密碼正確'); | |||
| return; | |||
| } | |||
| if (this.newPwd === this.oldPwd) { | |||
| alert('新舊密碼不得相同'); | |||
| return; | |||
| } | |||
| const pattern = new RegExp('\\s|\\W'); | |||
| if ( this.oldPwd === '' || pattern.test(this.oldPwd) || this.newPwd === '' || pattern.test(this.newPwd)) { | |||
| alert('1.密碼不得有空白\n' + | |||
| '2.限定英文及數字\n'); | |||
| return; | |||
| } | |||
| this.$axios.put('account/pwd', { | |||
| oldPwd: this.oldPwd, | |||
| newPwd: this.newPwd, | |||
| account: localStorage.getItem('account') | |||
| }).then((resp) => { | |||
| if (resp.data.code !== 200) { | |||
| alert(resp.data.message); | |||
| } else { | |||
| alert('已修改'); | |||
| this.dialogModifyPwd = false; | |||
| } | |||
| this.oldPwd = ''; | |||
| this.newPwd = ''; | |||
| this.chechNewPwd = ''; | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| @@ -99,7 +99,8 @@ | |||
| { | |||
| 'username': json.data.username, | |||
| 'department': json.data.department, | |||
| 'level': json.data.level | |||
| 'level': json.data.level, | |||
| 'account': json.data.account | |||
| }); | |||
| } else { | |||
| _this.message = json.message; | |||
| @@ -2,6 +2,7 @@ package com.moze.rms.controller; | |||
| import com.moze.rms.dao.AccountDAO; | |||
| import com.moze.rms.entity.dto.PwdDTO; | |||
| import com.moze.rms.entity.model.Account; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @@ -75,5 +76,15 @@ public class AccountController { | |||
| return new JsonResult(StatusCode.SUCCESS, accountDAO.finfDepartments()); | |||
| } | |||
| @PutMapping("/pwd") | |||
| public JsonResult modifyPwd(@RequestBody PwdDTO pwdDTO) { | |||
| Optional<Map<String, Object>> user = accountDAO.findUser(pwdDTO.getAccount().toLowerCase()); | |||
| if (user.isPresent() && user.get().get("pwd").equals(pwdDTO.getOldPwd())) { | |||
| accountDAO.modifyPwd(pwdDTO.getNewPwd(), pwdDTO.getAccount().toLowerCase()); | |||
| return new JsonResult(StatusCode.SUCCESS, null); | |||
| } else { | |||
| return new JsonResult(StatusCode.PASSWORD_INCORRECT, null); | |||
| } | |||
| } | |||
| } | |||
| @@ -31,8 +31,9 @@ public enum StatusCode { | |||
| DUPLICATE_ID(420, "員工編號重複"), | |||
| DUPLICATE_ACCOUNT(421, "帳號重複"); | |||
| DUPLICATE_ACCOUNT(421, "帳號重複"), | |||
| PASSWORD_INCORRECT(422, "密碼錯誤"); | |||
| private int code; | |||
| @@ -1,10 +1,12 @@ | |||
| package com.moze.rms.dao; | |||
| import com.moze.rms.entity.dto.PwdDTO; | |||
| import com.moze.rms.entity.model.Account; | |||
| import org.jdbi.v3.core.Handle; | |||
| import org.jdbi.v3.sqlobject.SqlObject; | |||
| import org.jdbi.v3.sqlobject.config.RegisterBeanMapper; | |||
| import org.jdbi.v3.sqlobject.statement.SqlQuery; | |||
| import org.jdbi.v3.sqlobject.statement.SqlUpdate; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -73,4 +75,8 @@ public interface AccountDAO extends SqlObject { | |||
| @SqlQuery("select count(*) from account where account = ?;") | |||
| Integer findByAccount(String account); | |||
| @SqlUpdate("update account set pwd = ? where lower(account) = ?") | |||
| void modifyPwd(String newPwd, String account); | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| package com.moze.rms.entity.dto; | |||
| import lombok.Data; | |||
| import lombok.NoArgsConstructor; | |||
| @Data | |||
| @NoArgsConstructor | |||
| public class PwdDTO { | |||
| private String account; | |||
| private String oldPwd; | |||
| private String newPwd; | |||
| } | |||
| @@ -1,5 +1,5 @@ | |||
| #spring.profiles.active=dev | |||
| spring.profiles.active=pro | |||
| spring.profiles.active=dev | |||
| #spring.profiles.active=pro | |||
| server.servlet.context-path=/rms | |||
| spring.servlet.multipart.max-file-size=100MB | |||