功能:统一账号输入校验并调整首页轮播图
This commit is contained in:
@@ -7,6 +7,8 @@ export interface ShopVO {
|
|||||||
address: string
|
address: string
|
||||||
businessHours: string
|
businessHours: string
|
||||||
status?: number
|
status?: number
|
||||||
|
coverImageFileId?: string
|
||||||
|
coverImageUrls?: string[]
|
||||||
imageFileIds: string
|
imageFileIds: string
|
||||||
imageUrls?: string[]
|
imageUrls?: string[]
|
||||||
createTime: string
|
createTime: string
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export const ACCOUNT_REGEX = /^[A-Za-z0-9]+$/
|
||||||
|
const ACCOUNT_SANITIZE_REGEX = /[^A-Za-z0-9]/g
|
||||||
|
|
||||||
|
export const ACCOUNT_RULE_MESSAGE = '账号只能包含字母和数字'
|
||||||
|
|
||||||
|
export const sanitizeAccountInput = (value: string) => (value || '').replace(ACCOUNT_SANITIZE_REGEX, '')
|
||||||
@@ -54,6 +54,7 @@
|
|||||||
v-model:value="formData.account"
|
v-model:value="formData.account"
|
||||||
placeholder="请输入账号"
|
placeholder="请输入账号"
|
||||||
size="large"
|
size="large"
|
||||||
|
@input="handleAccountInput"
|
||||||
@blur="handleRegisterAccountBlur"
|
@blur="handleRegisterAccountBlur"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -119,6 +120,7 @@
|
|||||||
v-model:value="formData.account"
|
v-model:value="formData.account"
|
||||||
placeholder="请输入账号"
|
placeholder="请输入账号"
|
||||||
size="large"
|
size="large"
|
||||||
|
@input="handleAccountInput"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<UserOutlined style="color: #999" />
|
<UserOutlined style="color: #999" />
|
||||||
@@ -394,6 +396,7 @@ import { message } from 'ant-design-vue'
|
|||||||
import type { Rule } from 'ant-design-vue/es/form'
|
import type { Rule } from 'ant-design-vue/es/form'
|
||||||
import { authApi } from '@/api/auth'
|
import { authApi } from '@/api/auth'
|
||||||
import { shopApi } from '@/api/shop'
|
import { shopApi } from '@/api/shop'
|
||||||
|
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||||
import {
|
import {
|
||||||
userApi,
|
userApi,
|
||||||
type AvailabilityCheckResponse,
|
type AvailabilityCheckResponse,
|
||||||
@@ -487,9 +490,17 @@ const validateConfirmPassword = async (_rule: Rule, value: string) => {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleAccountInput = () => {
|
||||||
|
const normalized = sanitizeAccountInput(formData.account)
|
||||||
|
if (normalized !== formData.account) {
|
||||||
|
formData.account = normalized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const registerRules: Record<string, Rule[]> = {
|
const registerRules: Record<string, Rule[]> = {
|
||||||
account: [
|
account: [
|
||||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||||
|
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||||
],
|
],
|
||||||
phone: [
|
phone: [
|
||||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||||
@@ -519,7 +530,8 @@ const registerRules: Record<string, Rule[]> = {
|
|||||||
|
|
||||||
const loginPasswordRules: Record<string, Rule[]> = {
|
const loginPasswordRules: Record<string, Rule[]> = {
|
||||||
account: [
|
account: [
|
||||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||||
|
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||||||
|
|||||||
@@ -35,49 +35,31 @@
|
|||||||
description="先逛作品和门店,收藏、加购、下单时再登录即可。"
|
description="先逛作品和门店,收藏、加购、下单时再登录即可。"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="banner-container">
|
<section class="section">
|
||||||
<div class="banner-carousel">
|
<div class="banner-container">
|
||||||
<a-carousel v-if="bannerImages.length" autoplay :autoplay-speed="3200" effect="fade">
|
<div class="banner-carousel">
|
||||||
<div
|
<a-carousel v-if="bannerImages.length" autoplay :autoplay-speed="3200" effect="fade">
|
||||||
v-for="banner in bannerImages"
|
<div
|
||||||
:key="banner.shopId"
|
v-for="banner in bannerImages"
|
||||||
class="banner-slide"
|
:key="banner.id"
|
||||||
@click="openShopById(banner.shopId)"
|
class="banner-slide"
|
||||||
>
|
@click="openShopById(banner.shopId)"
|
||||||
<img :src="banner.url" :alt="banner.shopName" class="banner-img" />
|
>
|
||||||
<div class="banner-copy">
|
<img :src="banner.url" :alt="banner.shopName" class="banner-img" />
|
||||||
<a-tag color="blue">门店推荐</a-tag>
|
<div class="banner-copy">
|
||||||
<h3>{{ banner.shopName }}</h3>
|
<a-tag color="blue">门店推荐</a-tag>
|
||||||
<p>{{ banner.businessHours || '欢迎到店体验' }}</p>
|
<h3>{{ banner.shopName }}</h3>
|
||||||
|
<p>{{ banner.businessHours || '欢迎到店体验' }}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</a-carousel>
|
||||||
|
<div v-else class="banner-empty">
|
||||||
|
<h3>发现适合你的美甲风格</h3>
|
||||||
|
<p>先看看门店 Banner 和精选作品,再决定今天预约谁。</p>
|
||||||
|
<a-button type="primary" @click="router.push('/products')">浏览作品</a-button>
|
||||||
</div>
|
</div>
|
||||||
</a-carousel>
|
|
||||||
<div v-else class="banner-empty">
|
|
||||||
<h3>发现适合你的美甲风格</h3>
|
|
||||||
<p>先看看热门门店和精选作品,再决定今天预约谁。</p>
|
|
||||||
<a-button type="primary" @click="router.push('/products')">浏览作品</a-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<section v-if="featuredShops.length" class="section">
|
|
||||||
<div class="section-header">
|
|
||||||
<h3>热门门店</h3>
|
|
||||||
<a class="see-all" @click="router.push('/products')">去看作品</a>
|
|
||||||
</div>
|
|
||||||
<div class="shop-strip">
|
|
||||||
<a-card
|
|
||||||
v-for="shop in featuredShops"
|
|
||||||
:key="shop.id"
|
|
||||||
class="shop-card"
|
|
||||||
hoverable
|
|
||||||
@click="openShop(shop)"
|
|
||||||
>
|
|
||||||
<div class="shop-card-name">{{ shop.shopName }}</div>
|
|
||||||
<div class="shop-card-address">{{ shop.address || '门店地址待完善' }}</div>
|
|
||||||
<div class="shop-card-hours">{{ shop.businessHours || '营业时间待完善' }}</div>
|
|
||||||
</a-card>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="section">
|
<section class="section">
|
||||||
@@ -158,6 +140,7 @@ import { fileApi } from '../api/file'
|
|||||||
import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||||
|
|
||||||
interface BannerImage {
|
interface BannerImage {
|
||||||
|
id: string
|
||||||
shopId: number
|
shopId: number
|
||||||
shopName: string
|
shopName: string
|
||||||
businessHours?: string
|
businessHours?: string
|
||||||
@@ -191,7 +174,6 @@ const pageSize = 8
|
|||||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||||
const greeting = computed(() => (isLoggedIn.value ? '欢迎回来' : '游客模式'))
|
const greeting = computed(() => (isLoggedIn.value ? '欢迎回来' : '游客模式'))
|
||||||
const displayName = computed(() => userInfo.value?.nickname || (isLoggedIn.value ? '用户' : '先看看门店和作品'))
|
const displayName = computed(() => userInfo.value?.nickname || (isLoggedIn.value ? '用户' : '先看看门店和作品'))
|
||||||
const featuredShops = computed(() => publicShops.value.slice(0, 4))
|
|
||||||
|
|
||||||
const getRandomColor = (): string => {
|
const getRandomColor = (): string => {
|
||||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||||
@@ -262,12 +244,16 @@ const loadPublicShops = async () => {
|
|||||||
const loadBannerImages = async () => {
|
const loadBannerImages = async () => {
|
||||||
const banners: BannerImage[] = []
|
const banners: BannerImage[] = []
|
||||||
for (const shop of publicShops.value) {
|
for (const shop of publicShops.value) {
|
||||||
const coverIds = (shop as any).coverImageFileId?.split(',').map((id: string) => id.trim()).filter(Boolean) || []
|
const coverIds = (shop.coverImageFileId || shop.imageFileIds || '')
|
||||||
|
.split(',')
|
||||||
|
.map(id => id.trim())
|
||||||
|
.filter(Boolean)
|
||||||
for (const id of coverIds) {
|
for (const id of coverIds) {
|
||||||
try {
|
try {
|
||||||
const url = await fileApi.getSignedUrl(Number(id)) as unknown as string
|
const url = await fileApi.getSignedUrl(Number(id)) as unknown as string
|
||||||
if (url) {
|
if (url) {
|
||||||
banners.push({
|
banners.push({
|
||||||
|
id: `${shop.id}-${id}`,
|
||||||
shopId: Number(shop.id),
|
shopId: Number(shop.id),
|
||||||
shopName: shop.shopName,
|
shopName: shop.shopName,
|
||||||
businessHours: shop.businessHours,
|
businessHours: shop.businessHours,
|
||||||
@@ -353,10 +339,6 @@ const handleProductClick = (item: ProductCardItem) => {
|
|||||||
router.push(`/product/${item.id}`)
|
router.push(`/product/${item.id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const openShop = (shop: ShopVO) => {
|
|
||||||
router.push(`/shop/${shop.id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const openShopById = (shopId: number) => {
|
const openShopById = (shopId: number) => {
|
||||||
router.push(`/shop/${shopId}`)
|
router.push(`/shop/${shopId}`)
|
||||||
}
|
}
|
||||||
@@ -418,9 +400,6 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.banner-container {
|
.banner-container {
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
margin: 18px 0 0;
|
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +492,6 @@ onUnmounted(() => {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shop-strip,
|
|
||||||
.horizontal-scroll {
|
.horizontal-scroll {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 14px;
|
gap: 14px;
|
||||||
@@ -522,31 +500,10 @@ onUnmounted(() => {
|
|||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shop-strip::-webkit-scrollbar,
|
|
||||||
.horizontal-scroll::-webkit-scrollbar {
|
.horizontal-scroll::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shop-card {
|
|
||||||
min-width: 220px;
|
|
||||||
border-radius: 18px;
|
|
||||||
background: linear-gradient(135deg, #fff 0%, #f7faff 100%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-card-name {
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: #1f1f1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-card-address,
|
|
||||||
.shop-card-hours {
|
|
||||||
margin-top: 8px;
|
|
||||||
font-size: 13px;
|
|
||||||
color: #666;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product-card {
|
.product-card {
|
||||||
width: 152px;
|
width: 152px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
@@ -643,15 +600,6 @@ onUnmounted(() => {
|
|||||||
max-width: var(--frontend-content-max-width);
|
max-width: var(--frontend-content-max-width);
|
||||||
}
|
}
|
||||||
|
|
||||||
.shop-strip {
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-card {
|
|
||||||
flex: 1 1 0;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.horizontal-scroll {
|
.horizontal-scroll {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
size="large"
|
size="large"
|
||||||
placeholder="请输入用户名"
|
placeholder="请输入用户名"
|
||||||
:prefix-icon="UserOutlined"
|
:prefix-icon="UserOutlined"
|
||||||
|
@input="handleAccountInput"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ import { message } from 'ant-design-vue'
|
|||||||
import type { FormInstance } from 'ant-design-vue'
|
import type { FormInstance } from 'ant-design-vue'
|
||||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||||
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
||||||
|
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||||
import { usePermission } from '@/utils/permission'
|
import { usePermission } from '@/utils/permission'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -100,6 +102,13 @@ const formState = reactive({
|
|||||||
})
|
})
|
||||||
let loginShopTimer: number | undefined
|
let loginShopTimer: number | undefined
|
||||||
|
|
||||||
|
const handleAccountInput = () => {
|
||||||
|
const normalized = sanitizeAccountInput(formState.account)
|
||||||
|
if (normalized !== formState.account) {
|
||||||
|
formState.account = normalized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getShopIdValue = (shop: { id: number | string; shopName: string }) => String(shop.id ?? '')
|
const getShopIdValue = (shop: { id: number | string; shopName: string }) => String(shop.id ?? '')
|
||||||
const getShopLabel = (shop: { id: number | string; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
const getShopLabel = (shop: { id: number | string; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||||
|
|
||||||
@@ -127,7 +136,7 @@ const shopPlaceholder = computed(() => {
|
|||||||
const formRules = {
|
const formRules = {
|
||||||
account: [
|
account: [
|
||||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||||
],
|
],
|
||||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||||
shopId: [{
|
shopId: [{
|
||||||
|
|||||||
@@ -111,7 +111,11 @@
|
|||||||
:wrapper-col="{ span: 16 }"
|
:wrapper-col="{ span: 16 }"
|
||||||
>
|
>
|
||||||
<a-form-item label="账号" name="account">
|
<a-form-item label="账号" name="account">
|
||||||
<a-input v-model:value="formState.account" placeholder="请输入账号" />
|
<a-input
|
||||||
|
v-model:value="formState.account"
|
||||||
|
placeholder="请输入账号"
|
||||||
|
@input="handleAccountInput"
|
||||||
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="昵称" name="nickname">
|
<a-form-item label="昵称" name="nickname">
|
||||||
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
||||||
@@ -360,6 +364,7 @@ import { message, Modal } from 'ant-design-vue'
|
|||||||
import type { FormInstance } from 'ant-design-vue'
|
import type { FormInstance } from 'ant-design-vue'
|
||||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||||
import { DEFAULT_AVATAR } from '@/constants'
|
import { DEFAULT_AVATAR } from '@/constants'
|
||||||
|
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||||
import {
|
import {
|
||||||
adminShopApi,
|
adminShopApi,
|
||||||
adminUserApi,
|
adminUserApi,
|
||||||
@@ -427,6 +432,13 @@ const formState = reactive({
|
|||||||
shopIds: [] as string[]
|
shopIds: [] as string[]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const handleAccountInput = () => {
|
||||||
|
const normalized = sanitizeAccountInput(formState.account)
|
||||||
|
if (normalized !== formState.account) {
|
||||||
|
formState.account = normalized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
||||||
changeScene: 'RECHARGE',
|
changeScene: 'RECHARGE',
|
||||||
amount: undefined as unknown as number,
|
amount: undefined as unknown as number,
|
||||||
@@ -441,7 +453,10 @@ const vipForm = reactive<AdminUserVipOverrideRequest>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const formRules = {
|
const formRules = {
|
||||||
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
account: [
|
||||||
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||||
|
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||||
|
],
|
||||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||||
phone: [
|
phone: [
|
||||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||||
|
|||||||
+32
@@ -1,9 +1,14 @@
|
|||||||
package com.xiaowang.yuminailcore.common;
|
package com.xiaowang.yuminailcore.common;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
|
import org.springframework.validation.BindException;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器
|
* 全局异常处理器
|
||||||
*
|
*
|
||||||
@@ -14,6 +19,33 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
public Result<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||||
|
String message = e.getBindingResult().getAllErrors().stream()
|
||||||
|
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("请求参数不合法");
|
||||||
|
return Result.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(BindException.class)
|
||||||
|
public Result<Void> handleBindException(BindException e) {
|
||||||
|
String message = e.getBindingResult().getAllErrors().stream()
|
||||||
|
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("请求参数不合法");
|
||||||
|
return Result.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(ConstraintViolationException.class)
|
||||||
|
public Result<Void> handleConstraintViolationException(ConstraintViolationException e) {
|
||||||
|
String message = e.getConstraintViolations().stream()
|
||||||
|
.map(violation -> violation.getMessage())
|
||||||
|
.findFirst()
|
||||||
|
.orElse("请求参数不合法");
|
||||||
|
return Result.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理运行时异常
|
* 处理运行时异常
|
||||||
*/
|
*/
|
||||||
|
|||||||
+4
-2
@@ -5,11 +5,13 @@ import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
|||||||
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
|
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
|
||||||
import com.xiaowang.yuminailcore.dto.SwitchShopRequestDTO;
|
import com.xiaowang.yuminailcore.dto.SwitchShopRequestDTO;
|
||||||
import com.xiaowang.yuminailcore.service.UserService;
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import com.xiaowang.yuminailcore.vo.LoginShopSelectionVO;
|
import com.xiaowang.yuminailcore.vo.LoginShopSelectionVO;
|
||||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -20,14 +22,14 @@ public class AdminAuthController {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Result<LoginResponseVO> login(@RequestBody LoginRequestDTO loginRequestDTO) {
|
public Result<LoginResponseVO> login(@Valid @RequestBody LoginRequestDTO loginRequestDTO) {
|
||||||
LoginResponseVO loginResponseVO = userService.adminLogin(loginRequestDTO);
|
LoginResponseVO loginResponseVO = userService.adminLogin(loginRequestDTO);
|
||||||
return Result.success(loginResponseVO);
|
return Result.success(loginResponseVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/login-shops/{account}")
|
@GetMapping("/login-shops/{account}")
|
||||||
public Result<LoginShopSelectionVO> getLoginShops(@PathVariable String account) {
|
public Result<LoginShopSelectionVO> getLoginShops(@PathVariable String account) {
|
||||||
return Result.success(userService.getAdminLoginShopSelection(account));
|
return Result.success(userService.getAdminLoginShopSelection(AccountValidationUtils.requireValidAccount(account)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/switch-shop")
|
@PostMapping("/switch-shop")
|
||||||
|
|||||||
+3
-2
@@ -17,6 +17,7 @@ import lombok.Data;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -48,7 +49,7 @@ public class AdminUserController {
|
|||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("user:create")
|
@RequirePermission("user:create")
|
||||||
public Result<Long> createUser(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
public Result<Long> createUser(HttpServletRequest request, @Valid @RequestBody UserDTO userDTO) {
|
||||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
@@ -62,7 +63,7 @@ public class AdminUserController {
|
|||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("user:edit")
|
@RequirePermission("user:edit")
|
||||||
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody UserDTO userDTO) {
|
||||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
UserVO targetUser = userService.getUserById(id);
|
UserVO targetUser = userService.getUserById(id);
|
||||||
if (targetUser == null) {
|
if (targetUser == null) {
|
||||||
|
|||||||
+13
-24
@@ -12,11 +12,13 @@ import com.xiaowang.yuminailcore.vo.UserVO;
|
|||||||
import com.xiaowang.yuminailcore.service.MinioService;
|
import com.xiaowang.yuminailcore.service.MinioService;
|
||||||
import com.xiaowang.yuminailcore.service.UserService;
|
import com.xiaowang.yuminailcore.service.UserService;
|
||||||
import com.xiaowang.yuminailcore.service.VerificationCodeService;
|
import com.xiaowang.yuminailcore.service.VerificationCodeService;
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import javax.validation.Valid;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -48,7 +50,7 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@RequirePermission("user:create")
|
@RequirePermission("user:create")
|
||||||
public Result<Long> createUser(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
public Result<Long> createUser(HttpServletRequest request, @Valid @RequestBody UserDTO userDTO) {
|
||||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||||
@@ -69,7 +71,7 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission("user:edit")
|
@RequirePermission("user:edit")
|
||||||
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody UserDTO userDTO) {
|
||||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
UserVO targetUser = requireAccessibleUser(currentUser, id, "鏃犳潈缂栬緫鍏朵粬搴楅摵鐢ㄦ埛");
|
UserVO targetUser = requireAccessibleUser(currentUser, id, "鏃犳潈缂栬緫鍏朵粬搴楅摵鐢ㄦ埛");
|
||||||
if (userDTO.getType() != null) {
|
if (userDTO.getType() != null) {
|
||||||
@@ -172,7 +174,7 @@ public class UserController {
|
|||||||
@RequirePermission("user:view")
|
@RequirePermission("user:view")
|
||||||
public Result<UserVO> getUserByAccount(HttpServletRequest request, @PathVariable String account) {
|
public Result<UserVO> getUserByAccount(HttpServletRequest request, @PathVariable String account) {
|
||||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
UserVO userVO = userService.getUserByAccount(account);
|
UserVO userVO = userService.getUserByAccount(AccountValidationUtils.requireValidAccount(account));
|
||||||
if (userVO != null) {
|
if (userVO != null) {
|
||||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userVO.getId(), "鏃犳潈鏌ョ湅鍏朵粬搴楅摵鐢ㄦ埛");
|
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userVO.getId(), "鏃犳潈鏌ョ湅鍏朵粬搴楅摵鐢ㄦ埛");
|
||||||
}
|
}
|
||||||
@@ -181,9 +183,10 @@ public class UserController {
|
|||||||
|
|
||||||
@GetMapping("/check/account/{account}")
|
@GetMapping("/check/account/{account}")
|
||||||
public Result<AvailabilityVO> checkAccountAvailability(@PathVariable String account) {
|
public Result<AvailabilityVO> checkAccountAvailability(@PathVariable String account) {
|
||||||
|
String normalizedAccount = AccountValidationUtils.requireValidAccount(account);
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, account)
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
);
|
);
|
||||||
boolean available = userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete());
|
boolean available = userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete());
|
||||||
String message = available ? "账号可用" : "账号已被注册";
|
String message = available ? "账号可用" : "账号已被注册";
|
||||||
@@ -192,9 +195,10 @@ public class UserController {
|
|||||||
|
|
||||||
@GetMapping("/check/login-account/{account}")
|
@GetMapping("/check/login-account/{account}")
|
||||||
public Result<LoginAccountAvailabilityVO> checkLoginAccountAvailability(@PathVariable String account) {
|
public Result<LoginAccountAvailabilityVO> checkLoginAccountAvailability(@PathVariable String account) {
|
||||||
|
String normalizedAccount = AccountValidationUtils.requireValidAccount(account);
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, account)
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
.eq(UserDO::getIsDelete, 0)
|
.eq(UserDO::getIsDelete, 0)
|
||||||
.last("limit 1")
|
.last("limit 1")
|
||||||
);
|
);
|
||||||
@@ -208,7 +212,7 @@ public class UserController {
|
|||||||
|
|
||||||
@GetMapping("/check/login-shops/account/{account}")
|
@GetMapping("/check/login-shops/account/{account}")
|
||||||
public Result<LoginShopSelectionVO> getLoginShopsByAccount(@PathVariable String account) {
|
public Result<LoginShopSelectionVO> getLoginShopsByAccount(@PathVariable String account) {
|
||||||
return Result.success(userService.getLoginShopSelectionByAccount(account));
|
return Result.success(userService.getLoginShopSelectionByAccount(AccountValidationUtils.requireValidAccount(account)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/check/login-shops/phone/{phone}")
|
@GetMapping("/check/login-shops/phone/{phone}")
|
||||||
@@ -235,7 +239,7 @@ public class UserController {
|
|||||||
* @return 登录响应VO
|
* @return 登录响应VO
|
||||||
*/
|
*/
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Result<LoginResponseVO> login(@RequestBody LoginRequestDTO loginRequestDTO) {
|
public Result<LoginResponseVO> login(@Valid @RequestBody LoginRequestDTO loginRequestDTO) {
|
||||||
LoginResponseVO loginResponseVO = userService.login(loginRequestDTO);
|
LoginResponseVO loginResponseVO = userService.login(loginRequestDTO);
|
||||||
return Result.success(loginResponseVO);
|
return Result.success(loginResponseVO);
|
||||||
}
|
}
|
||||||
@@ -265,7 +269,7 @@ public class UserController {
|
|||||||
* @return 是否注册成功
|
* @return 是否注册成功
|
||||||
*/
|
*/
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public Result<Boolean> register(@RequestBody RegisterRequestDTO registerRequestDTO) {
|
public Result<Boolean> register(@Valid @RequestBody RegisterRequestDTO registerRequestDTO) {
|
||||||
boolean success = userService.register(registerRequestDTO);
|
boolean success = userService.register(registerRequestDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
@@ -339,7 +343,7 @@ public class UserController {
|
|||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
@PutMapping({"/update", "/info"})
|
@PutMapping({"/update", "/info"})
|
||||||
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @Valid @RequestBody UserDTO userDTO) {
|
||||||
Long userId = (Long) request.getAttribute("userId");
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
boolean success = userService.updateCurrentUserInfo(userId, userDTO);
|
boolean success = userService.updateCurrentUserInfo(userId, userDTO);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
@@ -460,21 +464,6 @@ public class UserController {
|
|||||||
return Result.error("管理员账号无法注销");
|
return Result.error("管理员账号无法注销");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在删除前先重命名账号和手机号,添加删除时间戳
|
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
|
||||||
String newAccount = userDO.getAccount() + "_deleted_" + timestamp;
|
|
||||||
String newPhone = userDO.getPhone() + "_deleted_" + timestamp;
|
|
||||||
|
|
||||||
try {
|
|
||||||
UserDTO updateDTO = new UserDTO();
|
|
||||||
updateDTO.setAccount(newAccount);
|
|
||||||
updateDTO.setPhone(newPhone);
|
|
||||||
userService.updateUser(userId, updateDTO);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("重命名账号和手机号失败: " + e.getMessage());
|
|
||||||
// 重命名失败也继续删除流程
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean success = userService.deleteUser(userId);
|
boolean success = userService.deleteUser(userId);
|
||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.xiaowang.yuminailcore.dto;
|
package com.xiaowang.yuminailcore.dto;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录请求 DTO
|
* 登录请求 DTO
|
||||||
* 用于用户账号密码登录
|
* 用于用户账号密码登录
|
||||||
@@ -17,6 +21,8 @@ public class LoginRequestDTO {
|
|||||||
/**
|
/**
|
||||||
* 账号
|
* 账号
|
||||||
*/
|
*/
|
||||||
|
@NotBlank(message = "账号不能为空")
|
||||||
|
@Pattern(regexp = AccountValidationUtils.ACCOUNT_REGEX, message = "账号只能包含字母和数字")
|
||||||
private String account;
|
private String account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,4 +39,4 @@ public class LoginRequestDTO {
|
|||||||
* 店铺ID
|
* 店铺ID
|
||||||
*/
|
*/
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xiaowang.yuminailcore.dto;
|
package com.xiaowang.yuminailcore.dto;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
@@ -13,6 +14,8 @@ import javax.validation.constraints.Pattern;
|
|||||||
@Data
|
@Data
|
||||||
public class RegisterRequestDTO {
|
public class RegisterRequestDTO {
|
||||||
|
|
||||||
|
@NotBlank(message = "账号不能为空")
|
||||||
|
@Pattern(regexp = AccountValidationUtils.ACCOUNT_REGEX, message = "账号只能包含字母和数字")
|
||||||
private String account;
|
private String account;
|
||||||
|
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@@ -29,4 +32,4 @@ public class RegisterRequestDTO {
|
|||||||
@NotBlank(message = "验证码不能为空")
|
@NotBlank(message = "验证码不能为空")
|
||||||
@Pattern(regexp = "^\\d{6}$", message = "验证码必须是6位数字")
|
@Pattern(regexp = "^\\d{6}$", message = "验证码必须是6位数字")
|
||||||
private String verificationCode;
|
private String verificationCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.xiaowang.yuminailcore.dto;
|
package com.xiaowang.yuminailcore.dto;
|
||||||
|
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +34,7 @@ public class UserDTO {
|
|||||||
/**
|
/**
|
||||||
* 用户账号(登录用)
|
* 用户账号(登录用)
|
||||||
*/
|
*/
|
||||||
|
@Pattern(regexp = AccountValidationUtils.ACCOUNT_REGEX, message = "账号只能包含字母和数字")
|
||||||
private String account;
|
private String account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+19
-10
@@ -19,6 +19,7 @@ import com.xiaowang.yuminailcore.service.VerificationCodeService;
|
|||||||
import com.xiaowang.yuminailcore.support.PermissionPolicy;
|
import com.xiaowang.yuminailcore.support.PermissionPolicy;
|
||||||
import com.xiaowang.yuminailcore.support.RequestShopContext;
|
import com.xiaowang.yuminailcore.support.RequestShopContext;
|
||||||
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
|
import com.xiaowang.yuminailcore.support.UserShopBindingSupport;
|
||||||
|
import com.xiaowang.yuminailcore.utils.AccountValidationUtils;
|
||||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||||
import com.xiaowang.yuminailcore.vo.LoginShopSelectionVO;
|
import com.xiaowang.yuminailcore.vo.LoginShopSelectionVO;
|
||||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||||
@@ -222,10 +223,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createUser(UserDTO userDTO) {
|
public Long createUser(UserDTO userDTO) {
|
||||||
|
String validatedAccount = AccountValidationUtils.requireValidAccount(userDTO.getAccount());
|
||||||
// 检查账号是否已存在
|
// 检查账号是否已存在
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
.eq(UserDO::getAccount, validatedAccount)
|
||||||
.eq(UserDO::getIsDelete, 0)
|
.eq(UserDO::getIsDelete, 0)
|
||||||
);
|
);
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
@@ -243,7 +245,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
UserDO userDO = new UserDO();
|
UserDO userDO = new UserDO();
|
||||||
userDO.setShopId(validatedShopId);
|
userDO.setShopId(validatedShopId);
|
||||||
userDO.setNickname(userDTO.getNickname());
|
userDO.setNickname(userDTO.getNickname());
|
||||||
userDO.setAccount(userDTO.getAccount());
|
userDO.setAccount(validatedAccount);
|
||||||
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||||
userDO.setPhone(validatedPhone);
|
userDO.setPhone(validatedPhone);
|
||||||
userDO.setSignature(userDTO.getSignature());
|
userDO.setSignature(userDTO.getSignature());
|
||||||
@@ -326,16 +328,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新账号(如果提供且变更)
|
// 更新账号(如果提供且变更)
|
||||||
if (userDTO.getAccount() != null && !userDTO.getAccount().equals(userDO.getAccount())) {
|
String normalizedAccount = AccountValidationUtils.validateOptionalAccount(userDTO.getAccount());
|
||||||
|
if (normalizedAccount != null && !normalizedAccount.equals(userDO.getAccount())) {
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
.eq(UserDO::getIsDelete, 0)
|
.eq(UserDO::getIsDelete, 0)
|
||||||
);
|
);
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
throw new RuntimeException("账号已存在");
|
throw new RuntimeException("账号已存在");
|
||||||
}
|
}
|
||||||
userDO.setAccount(userDTO.getAccount());
|
userDO.setAccount(normalizedAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新其他字段(如果提供)
|
// 更新其他字段(如果提供)
|
||||||
@@ -483,9 +486,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserVO getUserByAccount(String account) {
|
public UserVO getUserByAccount(String account) {
|
||||||
|
String normalizedAccount = AccountValidationUtils.requireValidAccount(account);
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, account)
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
.eq(UserDO::getIsDelete, 0)
|
.eq(UserDO::getIsDelete, 0)
|
||||||
);
|
);
|
||||||
if (userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete())) {
|
if (userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete())) {
|
||||||
@@ -546,6 +550,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
if (!StringUtils.hasText(normalizedAccount)) {
|
if (!StringUtils.hasText(normalizedAccount)) {
|
||||||
return buildLoginShopSelection(List.of(), false, "请输入账号后再选择店铺");
|
return buildLoginShopSelection(List.of(), false, "请输入账号后再选择店铺");
|
||||||
}
|
}
|
||||||
|
AccountValidationUtils.ensureValidAccountFormat(normalizedAccount);
|
||||||
|
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
@@ -622,6 +627,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
if (!StringUtils.hasText(normalizedAccount)) {
|
if (!StringUtils.hasText(normalizedAccount)) {
|
||||||
return buildLoginShopSelection(List.of(), false, "请输入账号后再选择店铺");
|
return buildLoginShopSelection(List.of(), false, "请输入账号后再选择店铺");
|
||||||
}
|
}
|
||||||
|
AccountValidationUtils.ensureValidAccountFormat(normalizedAccount);
|
||||||
|
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
@@ -657,9 +663,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginResponseVO login(LoginRequestDTO loginRequestDTO) {
|
public LoginResponseVO login(LoginRequestDTO loginRequestDTO) {
|
||||||
|
String normalizedAccount = AccountValidationUtils.requireValidAccount(loginRequestDTO.getAccount());
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
);
|
);
|
||||||
|
|
||||||
assertUserAvailable(userDO);
|
assertUserAvailable(userDO);
|
||||||
@@ -735,9 +742,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public LoginResponseVO adminLogin(LoginRequestDTO loginRequestDTO) {
|
public LoginResponseVO adminLogin(LoginRequestDTO loginRequestDTO) {
|
||||||
|
String normalizedAccount = AccountValidationUtils.requireValidAccount(loginRequestDTO.getAccount());
|
||||||
UserDO userDO = userMapper.selectOne(
|
UserDO userDO = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
.eq(UserDO::getAccount, normalizedAccount)
|
||||||
);
|
);
|
||||||
|
|
||||||
assertUserAvailable(userDO);
|
assertUserAvailable(userDO);
|
||||||
@@ -823,13 +831,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean register(RegisterRequestDTO registerRequestDTO) {
|
public boolean register(RegisterRequestDTO registerRequestDTO) {
|
||||||
|
String validatedAccount = AccountValidationUtils.requireValidAccount(registerRequestDTO.getAccount());
|
||||||
if (!verificationCodeService.verifyCode(registerRequestDTO.getPhone(), registerRequestDTO.getVerificationCode())) {
|
if (!verificationCodeService.verifyCode(registerRequestDTO.getPhone(), registerRequestDTO.getVerificationCode())) {
|
||||||
throw new RuntimeException("验证码错误或已过期");
|
throw new RuntimeException("验证码错误或已过期");
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDO existingUser = userMapper.selectOne(
|
UserDO existingUser = userMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(UserDO.class)
|
Wrappers.lambdaQuery(UserDO.class)
|
||||||
.eq(UserDO::getAccount, registerRequestDTO.getAccount())
|
.eq(UserDO::getAccount, validatedAccount)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
@@ -857,7 +866,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
|
|
||||||
UserDO userDO = new UserDO();
|
UserDO userDO = new UserDO();
|
||||||
userDO.setShopId(validatedShopId);
|
userDO.setShopId(validatedShopId);
|
||||||
userDO.setAccount(registerRequestDTO.getAccount());
|
userDO.setAccount(validatedAccount);
|
||||||
userDO.setPassword(passwordEncoder.encode(registerRequestDTO.getPassword()));
|
userDO.setPassword(passwordEncoder.encode(registerRequestDTO.getPassword()));
|
||||||
userDO.setNickname(registerRequestDTO.getNickname());
|
userDO.setNickname(registerRequestDTO.getNickname());
|
||||||
userDO.setPhone(registerRequestDTO.getPhone());
|
userDO.setPhone(registerRequestDTO.getPhone());
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.xiaowang.yuminailcore.utils;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public final class AccountValidationUtils {
|
||||||
|
|
||||||
|
public static final String ACCOUNT_REGEX = "^[A-Za-z0-9]+$";
|
||||||
|
private static final Pattern ACCOUNT_PATTERN = Pattern.compile(ACCOUNT_REGEX);
|
||||||
|
|
||||||
|
private AccountValidationUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String normalizeAccount(String account) {
|
||||||
|
return account == null ? "" : account.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ensureValidAccountFormat(String account) {
|
||||||
|
if (!StringUtils.hasText(account)) {
|
||||||
|
throw new RuntimeException("账号不能为空");
|
||||||
|
}
|
||||||
|
if (!ACCOUNT_PATTERN.matcher(account).matches()) {
|
||||||
|
throw new RuntimeException("账号只能包含字母和数字");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String requireValidAccount(String account) {
|
||||||
|
String normalized = normalizeAccount(account);
|
||||||
|
ensureValidAccountFormat(normalized);
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String validateOptionalAccount(String account) {
|
||||||
|
if (account == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String normalized = normalizeAccount(account);
|
||||||
|
ensureValidAccountFormat(normalized);
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# 2026-03-26 账号输入限制为字母数字
|
||||||
|
|
||||||
|
## 本次调整
|
||||||
|
|
||||||
|
- 所有账号输入框统一限制为只允许输入字母和数字。
|
||||||
|
- 前端输入阶段实时过滤非法字符,后端接口层和业务层同步增加账号格式兜底校验。
|
||||||
|
|
||||||
|
## 前端修改
|
||||||
|
|
||||||
|
- 新增 [account.ts](/E:/code/xiaowang/Frontend/src/utils/account.ts)
|
||||||
|
- 统一维护账号正则、提示文案、输入过滤方法。
|
||||||
|
|
||||||
|
- 调整 [AuthView.vue](/E:/code/xiaowang/Frontend/src/views/AuthView.vue)
|
||||||
|
- 登录/注册的账号输入框实时过滤非字母数字字符。
|
||||||
|
- 登录与注册表单的账号规则增加“只能包含字母和数字”校验。
|
||||||
|
|
||||||
|
- 调整 [AdminLoginView.vue](/E:/code/xiaowang/Frontend/src/views/admin/AdminLoginView.vue)
|
||||||
|
- 后台登录账号输入框实时过滤非法字符。
|
||||||
|
- 后台登录表单账号规则改为只允许字母和数字。
|
||||||
|
|
||||||
|
- 调整 [UsersView.vue](/E:/code/xiaowang/Frontend/src/views/admin/UsersView.vue)
|
||||||
|
- 后台新增/编辑用户时,账号输入框实时过滤非法字符。
|
||||||
|
- 新增/编辑用户表单账号规则改为只允许字母和数字。
|
||||||
|
|
||||||
|
## 后端修改
|
||||||
|
|
||||||
|
- 新增 [AccountValidationUtils.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/utils/AccountValidationUtils.java)
|
||||||
|
- 统一账号格式规则与校验方法。
|
||||||
|
|
||||||
|
- 调整 DTO:
|
||||||
|
- [RegisterRequestDTO.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/RegisterRequestDTO.java)
|
||||||
|
- [LoginRequestDTO.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/LoginRequestDTO.java)
|
||||||
|
- [UserDTO.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/UserDTO.java)
|
||||||
|
- 为账号字段补充“只能包含字母和数字”的校验约束。
|
||||||
|
|
||||||
|
- 调整控制器:
|
||||||
|
- [UserController.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/UserController.java)
|
||||||
|
- [AdminAuthController.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminAuthController.java)
|
||||||
|
- [AdminUserController.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java)
|
||||||
|
- 登录、注册、用户创建/编辑、账号检测等入口统一接入账号格式校验。
|
||||||
|
|
||||||
|
- 调整 [UserServiceImpl.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/UserServiceImpl.java)
|
||||||
|
- 用户创建、编辑、登录、注册、登录店铺查询等业务统一使用账号格式校验。
|
||||||
|
|
||||||
|
- 调整 [GlobalExceptionHandler.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/common/GlobalExceptionHandler.java)
|
||||||
|
- 补充参数校验异常处理,返回更明确的前端提示。
|
||||||
|
|
||||||
|
## 顺手修正
|
||||||
|
|
||||||
|
- 注销账号接口原先会先调用一次通用更新接口重命名账号,这在新增账号格式校验后会产生冲突。
|
||||||
|
- 现在直接复用已有删除逻辑中的“删除占位账号”处理,避免重复改名流程。
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# 2026-03-26 首页 Banner 位置调整
|
||||||
|
|
||||||
|
## 本次调整
|
||||||
|
|
||||||
|
- 根据最新确认,首页不再展示“热门门店”标题或模块名。
|
||||||
|
- 原“热门门店”所在位置只保留 Banner 轮播展示。
|
||||||
|
|
||||||
|
## 具体修改
|
||||||
|
|
||||||
|
- 调整 [HomeView.vue](/E:/code/xiaowang/Frontend/src/views/HomeView.vue)
|
||||||
|
- 移除 Banner 区上方的“热门门店”标题和提示文案。
|
||||||
|
- 保留 Banner 轮播本体,继续放在原热门门店所在位置。
|
||||||
|
- 调整 Banner 空状态提示文案,避免继续出现“热门门店”字样。
|
||||||
|
|
||||||
|
## 结果
|
||||||
|
|
||||||
|
- 首页首个内容展示位现在就是纯 Banner,不再给用户造成“热门门店列表”的理解偏差。
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# 2026-03-26 首页热门门店改为 Banner 轮播
|
||||||
|
|
||||||
|
## 本次调整
|
||||||
|
|
||||||
|
- 将首页原来的“热门门店”卡片列表改为 Banner 展示模块。
|
||||||
|
- 当门店配置了多张 Banner 图时,首页按轮播方式展示。
|
||||||
|
- 点击 Banner 可直接进入对应门店详情页。
|
||||||
|
|
||||||
|
## 具体修改
|
||||||
|
|
||||||
|
- 调整 [HomeView.vue](/E:/code/xiaowang/Frontend/src/views/HomeView.vue)
|
||||||
|
- 移除首页“热门门店”横向卡片区,避免和顶部门店 Banner 重复展示。
|
||||||
|
- 将 Banner 区明确作为“热门门店”模块主体。
|
||||||
|
- 轮播项 `key` 改为 `shopId-imageId` 组合值,避免同门店多图时重复 key。
|
||||||
|
- 门店未单独配置 Banner 时,回退使用门店普通图片作为展示来源。
|
||||||
|
|
||||||
|
- 调整 [shop.ts](/E:/code/xiaowang/Frontend/src/api/shop.ts)
|
||||||
|
- 为 `ShopVO` 补充 `coverImageFileId`、`coverImageUrls` 字段定义,减少首页逻辑对 `any` 的依赖。
|
||||||
|
|
||||||
|
## 结果
|
||||||
|
|
||||||
|
- 首页“热门门店”区域现在以视觉 Banner 为主,更符合门店展示位的使用方式。
|
||||||
|
- 多 Banner 门店可以连续轮播展示,点击后仍然进入对应门店详情,不影响原有跳转链路。
|
||||||
Reference in New Issue
Block a user