fix: 微信注册头像仅写入客户表避免 RBAC Avatar 超长
fix: 微信注册头像仅写入客户表避免 RBAC Avatar 超长
This commit is contained in:
commit
2dba6fb47e
@ -8,10 +8,15 @@ public static class WeChatRegistrationFieldNormalizer
|
|||||||
public const int CustomerNameMaxLength = 128;
|
public const int CustomerNameMaxLength = 128;
|
||||||
public const int PhoneMaxLength = 16;
|
public const int PhoneMaxLength = 16;
|
||||||
public const int EmailMaxLength = 64;
|
public const int EmailMaxLength = 64;
|
||||||
public const int AvatarMaxLength = 255;
|
/// <summary>客户表 WechatAvatar 列长度。</summary>
|
||||||
|
public const int CustomerWechatAvatarMaxLength = 255;
|
||||||
public const int NicknameMaxLength = 64;
|
public const int NicknameMaxLength = 64;
|
||||||
public const int OpenidMaxLength = 64;
|
public const int OpenidMaxLength = 64;
|
||||||
|
|
||||||
|
/// <summary>微信头像仅写入 t_customer;RBAC user.Avatar 列更短,注册时不写入。</summary>
|
||||||
|
public static string? NormalizeCustomerWechatAvatar(string? avatar) =>
|
||||||
|
TruncateOptional(avatar, CustomerWechatAvatarMaxLength);
|
||||||
|
|
||||||
public static string TruncateRequired(string value, int maxLength)
|
public static string TruncateRequired(string value, int maxLength)
|
||||||
{
|
{
|
||||||
var normalized = value.Trim();
|
var normalized = value.Trim();
|
||||||
|
|||||||
@ -98,9 +98,7 @@ public class WeChatCustomerService(
|
|||||||
var wechatNickname = WeChatRegistrationFieldNormalizer.TruncateOptional(
|
var wechatNickname = WeChatRegistrationFieldNormalizer.TruncateOptional(
|
||||||
input.Wechat.Nickname,
|
input.Wechat.Nickname,
|
||||||
WeChatRegistrationFieldNormalizer.NicknameMaxLength);
|
WeChatRegistrationFieldNormalizer.NicknameMaxLength);
|
||||||
var wechatAvatar = WeChatRegistrationFieldNormalizer.TruncateOptional(
|
var wechatAvatar = WeChatRegistrationFieldNormalizer.NormalizeCustomerWechatAvatar(input.Wechat.Avatar);
|
||||||
input.Wechat.Avatar,
|
|
||||||
WeChatRegistrationFieldNormalizer.AvatarMaxLength);
|
|
||||||
|
|
||||||
if (password.Length < 6)
|
if (password.Length < 6)
|
||||||
{
|
{
|
||||||
@ -126,7 +124,6 @@ public class WeChatCustomerService(
|
|||||||
Account = phone,
|
Account = phone,
|
||||||
Password = password,
|
Password = password,
|
||||||
Email = email,
|
Email = email,
|
||||||
Avatar = wechatAvatar,
|
|
||||||
RoleIds = [customerRoleId]
|
RoleIds = [customerRoleId]
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -170,8 +167,15 @@ public class WeChatCustomerService(
|
|||||||
|
|
||||||
var account = NormalizeRequired(input.Account, "账号");
|
var account = NormalizeRequired(input.Account, "账号");
|
||||||
var password = NormalizeRequired(input.Password, "密码");
|
var password = NormalizeRequired(input.Password, "密码");
|
||||||
|
var wechatOpenid = WeChatRegistrationFieldNormalizer.TruncateRequired(
|
||||||
|
input.Wechat.Openid.Trim(),
|
||||||
|
WeChatRegistrationFieldNormalizer.OpenidMaxLength);
|
||||||
|
var wechatNickname = WeChatRegistrationFieldNormalizer.TruncateOptional(
|
||||||
|
input.Wechat.Nickname,
|
||||||
|
WeChatRegistrationFieldNormalizer.NicknameMaxLength);
|
||||||
|
var wechatAvatar = WeChatRegistrationFieldNormalizer.NormalizeCustomerWechatAvatar(input.Wechat.Avatar);
|
||||||
|
|
||||||
if (await customerRepository.GetByWechatOpenidAsync(input.Wechat.Openid, cancellationToken) != null)
|
if (await customerRepository.ExistsWechatOpenidAnyAsync(wechatOpenid, cancellationToken))
|
||||||
{
|
{
|
||||||
throw new BusinessException("当前微信已绑定账号");
|
throw new BusinessException("当前微信已绑定账号");
|
||||||
}
|
}
|
||||||
@ -199,9 +203,9 @@ public class WeChatCustomerService(
|
|||||||
throw new BusinessException("账号或密码错误");
|
throw new BusinessException("账号或密码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
customer.WechatOpenid = input.Wechat.Openid;
|
customer.WechatOpenid = wechatOpenid;
|
||||||
customer.WechatNickname = NormalizeOptional(input.Wechat.Nickname) ?? customer.WechatNickname;
|
customer.WechatNickname = wechatNickname ?? customer.WechatNickname;
|
||||||
customer.WechatAvatar = NormalizeOptional(input.Wechat.Avatar) ?? customer.WechatAvatar;
|
customer.WechatAvatar = wechatAvatar ?? customer.WechatAvatar;
|
||||||
await customerRepository.UpdateAsync(customer, cancellationToken);
|
await customerRepository.UpdateAsync(customer, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user