提交 c2448a72 编写于 作者: 江南一点雨

完善个人中心

上级 01c2e1c6
package org.javaboy.vhr.config;
import org.csource.common.MyException;
import org.csource.fastdfs.*;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
......@@ -13,7 +16,7 @@ import java.io.IOException;
* @GitHub https://github.com/lenve
* @博客 http://wangsong.blog.csdn.net
* @网站 http://www.javaboy.org
* @时间 2020-03-01 22:49
* @时间 2020-03-02 23:26
*/
public class FastDFSUtils {
private static StorageClient1 client1;
......@@ -23,8 +26,7 @@ public class FastDFSUtils {
ClientGlobal.initByProperties("fastdfs-client.properties");
TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null;
client1 = new StorageClient1(trackerServer, storageServer);
client1 = new StorageClient1(trackerServer, null);
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
......@@ -33,16 +35,15 @@ public class FastDFSUtils {
}
public static String upload(MultipartFile file) {
String name = file.getOriginalFilename();
String s = null;
String oldName = file.getOriginalFilename();
try {
s = client1.upload_file1(file.getBytes(), name.substring(name.lastIndexOf(".") + 1), null);
return client1.upload_file1(file.getBytes(), oldName.substring(oldName.lastIndexOf(".") + 1), null);
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
return s;
return null;
}
}
......@@ -6,7 +6,9 @@ import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.service.HrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -27,7 +29,7 @@ public class HrInfoController {
@Autowired
HrService hrService;
@Value("${javaboy.nginx.host}")
@Value("${fastdfs.nginx.host}")
String nginxHost;
@GetMapping("/hr/info")
......@@ -36,8 +38,9 @@ public class HrInfoController {
}
@PutMapping("/hr/info")
public RespBean updateHyById(@RequestBody Hr hr) {
if (hrService.updateHyById(hr) == 1) {
public RespBean updateHr(@RequestBody Hr hr, Authentication authentication) {
if (hrService.updateHr(hr) == 1) {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(hr, authentication.getCredentials(), authentication.getAuthorities()));
return RespBean.ok("更新成功!");
}
return RespBean.error("更新失败!");
......@@ -55,11 +58,14 @@ public class HrInfoController {
}
@PostMapping("/hr/userface")
public RespBean updateUserface(MultipartFile file, Integer id) {
String upload = FastDFSUtils.upload(file);
String url = nginxHost + upload;
public RespBean updateHrUserface(MultipartFile file, Integer id,Authentication authentication) {
String fileId = FastDFSUtils.upload(file);
String url = nginxHost + fileId;
if (hrService.updateUserface(url, id) == 1) {
return RespBean.ok("更新成功!",url);
Hr hr = (Hr) authentication.getPrincipal();
hr.setUserface(url);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(hr, authentication.getCredentials(), authentication.getAuthorities()));
return RespBean.ok("更新成功!", url);
}
return RespBean.error("更新失败!");
}
......
......@@ -17,5 +17,5 @@ spring.redis.database=0
spring.redis.port=6379
spring.redis.password=123
spring.cache.cache-names=menus_cache
# FastDFS 文件地址
javaboy.nginx.host=http://192.168.91.128/
\ No newline at end of file
fastdfs.nginx.host=http://192.168.91.128/
\ No newline at end of file
......@@ -51,12 +51,15 @@
name: "Home",
data() {
return {
user: JSON.parse(window.sessionStorage.getItem("user"))
// user: JSON.parse(window.sessionStorage.getItem("user"))
}
},
computed: {
routes() {
return this.$store.state.routes;
},
user() {
return this.$store.state.currentHr;
}
},
methods: {
......
......@@ -7,14 +7,13 @@
<div>
<div style="display: flex;justify-content: center">
<el-upload
:data="hr"
:show-file-list="false"
:on-success="onSuccess"
:data="hr"
action="/hr/userface">
<img title="点击修改用户图像" :src="hr.userface" style="width: 100px;height: 100px;border-radius: 50px"
alt="">
</el-upload>
</div>
<div>电话号码:
<el-tag>{{hr.telephone}}</el-tag>
......@@ -36,29 +35,6 @@
</div>
</div>
</el-card>
<el-dialog
title="修改密码"
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="请输入新密码" prop="pass">
<el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-dialog>
<el-dialog
title="修改用户信息"
:visible.sync="dialogVisible"
......@@ -67,7 +43,7 @@
<table>
<tr>
<td>
<el-tag>用户姓名</el-tag>
<el-tag>用户昵称</el-tag>
</td>
<td>
<el-input v-model="hr2.name"></el-input>
......@@ -104,6 +80,29 @@
<el-button type="primary" @click="updateHrInfo">确 定</el-button>
</span>
</el-dialog>
<el-dialog
title="修改密码"
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="请输入新密码" prop="pass">
<el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-dialog>
</div>
</template>
......@@ -149,8 +148,8 @@
},
hr: null,
hr2: null,
passwdDialogVisible: false,
dialogVisible: false
dialogVisible: false,
passwdDialogVisible: false
}
},
mounted() {
......@@ -158,10 +157,18 @@
},
methods: {
onSuccess() {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
this.$store.commit('initRoutes', []);
this.$router.replace("/");
this.initHr();
},
updateHrInfo() {
this.putRequest("/hr/info", this.hr2).then(resp => {
if (resp) {
this.dialogVisible = false;
this.initHr();
}
})
},
showUpdateHrInfoView() {
this.dialogVisible = true;
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
......@@ -186,24 +193,13 @@
showUpdatePasswdView() {
this.passwdDialogVisible = true;
},
updateHrInfo() {
this.putRequest("/hr/info", this.hr2).then(resp => {
if (resp) {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
this.$store.commit('initRoutes', []);
this.$router.replace("/");
}
})
},
showUpdateHrInfoView() {
this.dialogVisible = true;
},
initHr() {
this.getRequest('/hr/info').then(resp => {
if (resp) {
this.hr = resp;
this.hr2 = Object.assign({}, this.hr);
window.sessionStorage.setItem("user", JSON.stringify(resp));
this.$store.commit('INIT_CURRENTHR', resp);
}
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册