Skip to content

Commit

Permalink
refactor: Choose between user registration phone number and email add…
Browse files Browse the repository at this point in the history
…ress
  • Loading branch information
wzh425 committed Mar 26, 2024
1 parent eb3b664 commit 6b88125
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ public class RegisterFieldDto

public bool Required { get; set; }

public bool CannotUpdate { get; private set; }

[JsonConstructor]
public RegisterFieldDto(RegisterFieldTypes registerFieldType, int sort, bool required)
{
RegisterFieldType = registerFieldType;
Sort = sort;
Required = required;
if (RegisterFieldType is RegisterFieldTypes.PhoneNumber)
{
CannotUpdate = true;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ async Task RegisterVerifyAsync(RegisterByEmailModel model)
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_EMAIL_CAPTCHA);
}
}
var smsCodeKey = CacheKey.MsgCodeRegisterAndLoginKey(model.PhoneNumber);
var smsCode = await _distributedCacheClient.GetAsync<string>(smsCodeKey);
if (!model.SmsCode.Equals(smsCode))

if (model.UserRegisterType == UserRegisterTypes.PhoneNumber || !string.IsNullOrEmpty(model.PhoneNumber))
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_SMS_CAPTCHA);
var smsCodeKey = CacheKey.MsgCodeRegisterAndLoginKey(model.PhoneNumber);
var smsCode = await _distributedCacheClient.GetAsync<string>(smsCodeKey);
if (!model.SmsCode.Equals(smsCode))
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_SMS_CAPTCHA);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"MASA_NAMESPACE": "masastack",
"MASA_CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 3,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"MASA_ENVIRONMENT": "Development",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=10.130.0.235,24878;Database=auth_dev;User Id=ss;Password=Hzss@123;"
"DefaultConnection": "Server=10.130.0.19,2415;Database=auth_dev;User Id=ss;Password=Hzss@123;"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public async Task AddCustomLoginAsync(FormContext context)
OpenErrorMessage(T("Register configuration items are required"));
return;
}
if (!CustomLogin.RegisterFields.Any(r => (r.RegisterFieldType == RegisterFieldTypes.PhoneNumber || r.RegisterFieldType == RegisterFieldTypes.Email) && r.Required))
{
Tab = CustomLoginTab.Register;
OpenErrorMessage(T("PhoneNumberAndEmailEmptyError"));
return;
}

await CustomLoginService.AddAsync(CustomLogin);
OpenSuccessMessage(T("Add Custom Login success"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
{
<MRow Class="mb-6" @key="@(registerField.RegisterFieldType!=default?registerField.RegisterFieldType:registerField.Sort)">
<MCol Cols="6">
<RegisterFieldSelect @bind-Value="registerField.RegisterFieldType" Disabled="registerField.CannotUpdate" Excludes="Value.Select(v => v.RegisterFieldType).ToList()" />
<RegisterFieldSelect @bind-Value="registerField.RegisterFieldType" Excludes="Value.Select(v => v.RegisterFieldType).ToList()" />
</MCol>
<MCol Cols="2" Class="d-flex">
<MSwitch @bind-Value="registerField.Required" Disabled="registerField.CannotUpdate" Class="my-auto my-0 pt-0" TValue="bool"/>
<MSwitch @bind-Value="registerField.Required" Class="my-auto my-0 pt-0" TValue="bool"/>
</MCol>
<MCol Class="d-flex">
<div class="my-auto">
Expand All @@ -39,7 +39,7 @@
<MButton Class="mr-6" Icon OnClick="async () =>await Down(registerField)" Disabled="registerField.Sort == Value.Max(v => v.Sort)">
<SIcon Tooltip="@T("Down")">mdi-menu-down</SIcon>
</MButton>
<MButton Class="mr-6" Icon OnClick="async () =>await Remove(registerField)" Disabled="registerField.CannotUpdate">
<MButton Class="mr-6" Icon OnClick="async () =>await Remove(registerField)">
<SIcon Tooltip="@T("Delete")">mdi-delete-outline</SIcon>
</MButton>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public async Task UpdateCustomLoginAsync(FormContext context)
OpenErrorMessage(T("Register configuration items are required"));
return;
}
if (!CustomLogin.RegisterFields.Any(r => (r.RegisterFieldType == RegisterFieldTypes.PhoneNumber || r.RegisterFieldType == RegisterFieldTypes.Email) && r.Required))
{
Tab = CustomLoginTab.Register;
OpenErrorMessage(T("PhoneNumberAndEmailEmptyError"));
return;
}

await CustomLoginService.UpdateAsync(CustomLogin);
OpenSuccessMessage(T("Edit Custom Login data success"));
Expand Down
3 changes: 2 additions & 1 deletion src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"CustomLoginBlock": {
"TitleName": "Name",
"NameRequired": "Name is required",
"DisplayNameRequired": "DisplayName is required"
"DisplayNameRequired": "DisplayName is required",
"PhoneNumberAndEmailEmptyError": "One of phone number and email must have a value"
},
"ConfirmChangePassword": "I confirm to change the password",
"PasswordValidateFailed": "Password validate failed",
Expand Down
3 changes: 2 additions & 1 deletion src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@
"Name is required": "姓名必须填写",
"Title is required": "标题必须填写",
"NameRequired": "姓名必须填写",
"DisplayNameRequired": "昵称必须填写"
"DisplayNameRequired": "昵称必须填写",
"PhoneNumberAndEmailEmptyError": "电话号码和邮件其中一个必须有值"
},

"OperationLog": "操作日志",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"TLS_NAME": "",
"MASA_CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 3,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"MASA_ENVIRONMENT": "Development",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ await AuthClient.UserService.RegisterByPhoneAsync(new RegisterByPhoneModel

var loginInputModel = new LoginInputModel
{
PhoneLogin = true,
PhoneLogin = RegisterFields.Any(x => x.RegisterFieldType == RegisterFieldTypes.PhoneNumber),
SmsCode = _inputModel.SmsCode,
Password = _inputModel.Password,
Account = _inputModel.Email ?? "",
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Masa.Auth.Web.Sso/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"MASA_NAMESPACE": "masastack",
"MASA_CLUSTER": "Default",
"OTLP_URL": "https://otel-collector.masastack:9013",
"REDIS": "{\"RedisHost\": \"10.130.0.235\", \"RedisPort\": 24615, \"RedisDb\": 0,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.235\", \"Port\": 24878,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 3,\"RedisPassword\": \"Hzss@123\"}",
"CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}",
"MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]",
"ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}",
"MASA_ENVIRONMENT": "Development",
Expand Down

0 comments on commit 6b88125

Please sign in to comment.