完成账号安全设置全部内容
This commit is contained in:
parent
4d04d1317e
commit
6831b13024
@ -6,9 +6,12 @@ import com.example.entity.dto.AccountDetails;
|
||||
import com.example.entity.vo.request.ChangePasswordVO;
|
||||
import com.example.entity.vo.request.DetailsSaveVO;
|
||||
import com.example.entity.vo.request.ModifyEmailVO;
|
||||
import com.example.entity.vo.request.PrivacySaveVO;
|
||||
import com.example.entity.vo.response.AccountDetailsVO;
|
||||
import com.example.entity.vo.response.AccountPrivacyVO;
|
||||
import com.example.entity.vo.response.AccountVO;
|
||||
import com.example.service.AccountDetailsService;
|
||||
import com.example.service.AccountPrivacyService;
|
||||
import com.example.service.AccountService;
|
||||
import com.example.utils.Const;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -30,6 +33,9 @@ public class AccountController {
|
||||
@Resource
|
||||
AccountDetailsService detailsService;
|
||||
|
||||
@Resource
|
||||
AccountPrivacyService privacyService;
|
||||
|
||||
@GetMapping("/info")
|
||||
public RestBean<AccountVO> info(@RequestAttribute(Const.ATTR_USER_ID) int id){
|
||||
Account account = service.findAccountById(id);
|
||||
@ -63,6 +69,18 @@ public class AccountController {
|
||||
return this.messageHandle(() -> service.changePassword(id, vo));
|
||||
}
|
||||
|
||||
@PostMapping("/save-privacy")
|
||||
public RestBean<Void> savePrivacy(@RequestAttribute(Const.ATTR_USER_ID) int id,
|
||||
@RequestBody @Valid PrivacySaveVO vo){
|
||||
privacyService.savePrivacy(id, vo);
|
||||
return RestBean.success();
|
||||
}
|
||||
|
||||
@GetMapping("/privacy")
|
||||
public RestBean<AccountPrivacyVO> privacy(@RequestAttribute(Const.ATTR_USER_ID) int id){
|
||||
return RestBean.success(privacyService.accountPrivacy(id).asViewObject(AccountPrivacyVO.class));
|
||||
}
|
||||
|
||||
private <T> RestBean<T> messageHandle(Supplier<String> action){
|
||||
String message = action.get();
|
||||
if(message == null)
|
||||
|
@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class AccountDetails implements BaseData {
|
||||
@TableId(type = IdType.AUTO)
|
||||
int id;
|
||||
Integer id;
|
||||
int gender;
|
||||
String phone;
|
||||
String qq;
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.example.entity.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.entity.BaseData;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("db_account_privacy")
|
||||
public class AccountPrivacy implements BaseData {
|
||||
@TableId(type = IdType.AUTO)
|
||||
final Integer id;
|
||||
boolean phone = true;
|
||||
boolean email = true;
|
||||
boolean wx = true;
|
||||
boolean qq = true;
|
||||
boolean gender = true;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.example.entity.vo.request;
|
||||
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PrivacySaveVO {
|
||||
@Pattern(regexp = "(phone|email|wx|qq|gender)")
|
||||
String type;
|
||||
boolean status;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.example.entity.vo.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AccountPrivacyVO {
|
||||
boolean phone = true;
|
||||
boolean email = true;
|
||||
boolean wx = true;
|
||||
boolean qq = true;
|
||||
boolean gender = true;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.entity.dto.AccountPrivacy;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AccountPrivacyMapper extends BaseMapper<AccountPrivacy> {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.example.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.example.entity.dto.AccountPrivacy;
|
||||
import com.example.entity.vo.request.PrivacySaveVO;
|
||||
|
||||
public interface AccountPrivacyService extends IService<AccountPrivacy> {
|
||||
void savePrivacy(int id, PrivacySaveVO vo);
|
||||
AccountPrivacy accountPrivacy(int id);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.example.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.example.entity.dto.AccountPrivacy;
|
||||
import com.example.entity.vo.request.PrivacySaveVO;
|
||||
import com.example.mapper.AccountPrivacyMapper;
|
||||
import com.example.service.AccountPrivacyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class AccountPrivacyServiceImpl extends ServiceImpl<AccountPrivacyMapper, AccountPrivacy> implements AccountPrivacyService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void savePrivacy(int id, PrivacySaveVO vo) {
|
||||
AccountPrivacy privacy = Optional.ofNullable(this.getById(id)).orElse(new AccountPrivacy(id));
|
||||
switch (vo.getType()) {
|
||||
case "phone" -> privacy.setPhone(vo.isStatus());
|
||||
case "email" -> privacy.setEmail(vo.isStatus());
|
||||
case "gender" -> privacy.setGender(vo.isStatus());
|
||||
case "wx" -> privacy.setWx(vo.isStatus());
|
||||
case "qq" -> privacy.setQq(vo.isStatus());
|
||||
}
|
||||
this.saveOrUpdate(privacy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountPrivacy accountPrivacy(int id) {
|
||||
return this.getById(id);
|
||||
}
|
||||
}
|
@ -2,54 +2,55 @@
|
||||
import {ElIcon} from "element-plus";
|
||||
|
||||
defineProps({
|
||||
title: String,
|
||||
desc: String,
|
||||
icon: Object
|
||||
title: String,
|
||||
desc: String,
|
||||
icon: Object
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card">
|
||||
<div class="card-header" v-if="title">
|
||||
<div>
|
||||
<el-icon style="margin-right: 3px">
|
||||
<component :is="icon"/>
|
||||
</el-icon>
|
||||
{{title}}
|
||||
</div>
|
||||
<div>{{desc}}</div>
|
||||
<div class="card">
|
||||
<div class="card-header" v-if="title">
|
||||
<div>
|
||||
<el-icon style="margin-right: 3px">
|
||||
<component :is="icon"/>
|
||||
</el-icon>
|
||||
{{ title }}
|
||||
</div>
|
||||
<div>{{ desc }}</div>
|
||||
</div>
|
||||
<slot/>
|
||||
</div>
|
||||
<slot/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.card {
|
||||
border-radius: 5px;
|
||||
border: solid 1px var(--el-border-color);
|
||||
background-color: var(--el-bg-color);
|
||||
box-sizing: border-box;
|
||||
min-height: 20px;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
border: solid 1px var(--el-border-color);
|
||||
background-color: var(--el-bg-color);
|
||||
box-sizing: border-box;
|
||||
min-height: 20px;
|
||||
padding: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
border-bottom: solid 1px var(--el-border-color);
|
||||
padding-bottom: 5px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: solid 1px var(--el-border-color);
|
||||
padding-bottom: 5px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
.el-icon {
|
||||
translate: 0 2px;
|
||||
}
|
||||
.el-icon {
|
||||
translate: 0 2px;
|
||||
}
|
||||
|
||||
& > :first-child {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
& > :first-child {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
& > :last-child {
|
||||
font-size: 13px;
|
||||
color: grey;
|
||||
}
|
||||
& > :last-child {
|
||||
font-size: 13px;
|
||||
color: grey;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -2,7 +2,7 @@
|
||||
import Card from "@/components/Card.vue";
|
||||
import {Lock, Setting, Switch} from "@element-plus/icons-vue";
|
||||
import {reactive, ref} from "vue";
|
||||
import {post} from "@/net";
|
||||
import {get, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
|
||||
const form = reactive({
|
||||
@ -49,27 +49,51 @@ function resetPassword() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const privacy = reactive({
|
||||
phone: false,
|
||||
email: false,
|
||||
wx: false,
|
||||
qq: false,
|
||||
gender: false
|
||||
})
|
||||
get('/api/user/privacy', data => {
|
||||
privacy.phone = data.phone
|
||||
privacy.email = data.email
|
||||
privacy.wx = data.wx
|
||||
privacy.qq = data.qq
|
||||
privacy.gender = data.gender
|
||||
saving.value = false
|
||||
})
|
||||
const saving = ref(true)
|
||||
function savePrivacy(type, status) {
|
||||
saving.value = true
|
||||
post('/api/user/save-privacy', {
|
||||
type: type,
|
||||
status: status
|
||||
}, () => {
|
||||
ElMessage.success('隐式设置保存成功!')
|
||||
saving.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="margin: auto;max-width: 600px">
|
||||
<div style="margin-top: 20px">
|
||||
<card :icon="Setting" title="隐私设置" desc="在这里设置哪些内容可以被其他人看到,请各位小伙伴注重自己的隐私">
|
||||
<card :icon="Setting" title="隐私设置" v-loading="saving"
|
||||
desc="在这里设置哪些内容可以被其他人看到,请各位小伙伴注重自己的隐私">
|
||||
<div class="checkbox-list">
|
||||
<div>陌生人可见性设置</div>
|
||||
<div>论坛所有用户默认都是陌生人,以下设置都会针对于陌生人生效</div>
|
||||
<el-checkbox>公开展示我的手机号</el-checkbox>
|
||||
<el-checkbox>公开展示我的电子邮件地址</el-checkbox>
|
||||
<el-checkbox>公开展示我的微信号</el-checkbox>
|
||||
<el-checkbox>公开展示我的QQ号</el-checkbox>
|
||||
</div>
|
||||
<div class="checkbox-list">
|
||||
<div>好友可见性设置</div>
|
||||
<div>当您与其他用户互相添加为好友时,以下的隐私设置将会生效</div>
|
||||
<el-checkbox>公开展示我的手机号</el-checkbox>
|
||||
<el-checkbox>公开展示我的电子邮件地址</el-checkbox>
|
||||
<el-checkbox>公开展示我的微信号</el-checkbox>
|
||||
<el-checkbox>公开展示我的QQ号</el-checkbox>
|
||||
<el-checkbox @change="savePrivacy('phone', privacy.phone)"
|
||||
v-model="privacy.phone">公开展示我的手机号</el-checkbox>
|
||||
<el-checkbox @change="savePrivacy('email', privacy.email)"
|
||||
v-model="privacy.email">公开展示我的电子邮件地址</el-checkbox>
|
||||
<el-checkbox @change="savePrivacy('wx', privacy.wx)"
|
||||
v-model="privacy.wx">公开展示我的微信号</el-checkbox>
|
||||
<el-checkbox @change="savePrivacy('qq', privacy.qq)"
|
||||
v-model="privacy.qq">公开展示我的QQ号</el-checkbox>
|
||||
<el-checkbox @change="savePrivacy('gender', privacy.gender)"
|
||||
v-model="privacy.gender">公开展示我的性别</el-checkbox>
|
||||
</div>
|
||||
</card>
|
||||
<card style="margin: 20px 0"
|
||||
@ -103,16 +127,5 @@ function resetPassword() {
|
||||
margin: 0 0 20px 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:nth-child(1) {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
:nth-child(2) {
|
||||
font-size: 13px;
|
||||
font-weight: normal;
|
||||
color: grey;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
Loading…
x
Reference in New Issue
Block a user