public async Task <ActionResult> ChangePhone(ChangePhoneInputDto inputDto) { var phone = await _validationComponent.GetTicketPhoneAsync(inputDto.Code); if (string.IsNullOrWhiteSpace(phone)) { return(ObjectResponse.Error("身份验证无效或验证已过期")); } if (inputDto.Phone == phone) { return(ObjectResponse.Error("输入手机号与原手机号相同")); } var dataContent = await _validationComponent.ValidSmsAsync(inputDto.Phone, inputDto.Code); if (!dataContent.Data) { return(ObjectResponse.Ok(dataContent.Code, dataContent.Message)); } var result = await _userService.ChangePhoneAsync(phone, inputDto.Phone); return(ObjectResponse.Ok(result)); }
public async Task <IActionResult> BindUser([FromBody] BindExternalUserInputDto inputDto) { var result = await _externalUserService.BindExternalUser(User.GetClientId().ToInt32(), User.GetUserId(), inputDto.ProviderKey, inputDto.LoginProvider, inputDto.NickName); return(ObjectResponse.Ok(result)); }
public async Task <IActionResult> UnbindUser([FromBody] UnbindExternalUserInputDto inputDto) { await _externalUserService.UnBindExternalUser(User.GetClientId().ToInt32(), User.GetUserId(), inputDto.LoginProvider); return(ObjectResponse.Ok()); }
public async Task <ActionResult> ResetPassword(ResetPasswordInputDto inputDto) { var password = _encryptService.DecryptRsa(inputDto.Password); if (string.IsNullOrEmpty(password)) { return(ObjectResponse.Error("密码格式不正确")); } if (Regex.IsMatch(password, RegexConstance.IsPassword) == false) { return(ObjectResponse.Error(password.Length < 6 ? "密码长度不能少于6个字符" : "密码长度不能超过20个字符")); } var phone = await _validationComponent.GetTicketPhoneAsync(inputDto.Ticket); if (string.IsNullOrWhiteSpace(phone)) { return(ObjectResponse.Error("身份验证无效或验证已过期")); } var phoneExists = await _userService.ExistPhoneAsync(phone); if (!phoneExists) { return(ObjectResponse.Error("该用户不存在")); } await _userService.ResetPasswordAsync(phone, password); return(ObjectResponse.Ok()); }
public async Task <IActionResult> LoginByPassBind(LoginByPassBindModel model) { var result = await HttpContext.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); if (result.Succeeded == false) { return(ObjectResponse.Ok(10026, "External authentication error")); } var(loginProvider, providerKey) = GetExternalUser(result); if (loginProvider.IsEmpty() || providerKey.IsEmpty()) { return(ObjectResponse.Ok(10026, "操作超时,请重新授权")); } var loginResult = await _userService.LoginByPasswordAsync(model.UserName, model.Password); if (loginResult.Code != 0) { return(ObjectResponse.Ok(loginResult.Code, loginResult.Message)); } await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); await SignIn(loginResult.Data, UserLoginModel.External); return(ObjectResponse.Ok()); }
public async Task <IActionResult> GetErrorMsg(string errorId) { var err = await _interaction.GetErrorContextAsync(errorId); if (err == null) { return(ObjectResponse.Ok(0, "未知错误")); } return(ObjectResponse.Ok(0, err.ErrorDescription)); }
public async Task <IActionResult> DeleteUser(int id) { var externalUser = await _externalUserRepository.TableNoTracking.FirstOrDefaultAsync(x => x.Id == id); if (externalUser != null) { _externalUserRepository.Delete(externalUser); await _unitOfWork.SaveChangesAsync(); } return(ObjectResponse.Ok()); }
public async Task <IActionResult> GetUsers() { var clientId = User.GetClientId(); _logger.LogInformation(clientId); var externalUsers = await _externalUserService.GetExternalUsers(User.GetClientId().ToInt32(), User.GetUserId()); var getUserOutputs = _mapper.Map <List <GetExternalUserOutputDto> >(externalUsers); return(ObjectResponse.Ok(getUserOutputs)); }
public async Task <IActionResult> GetUser([FromQuery] GetExternalUserInputDto inputDto) { var externalUser = await _externalUserService.GetExternalUser(User.GetClientId().ToInt32(), inputDto.ProviderKey); if (null == externalUser) { return(ObjectResponse.Error("第三方用户不存在")); } var externalUserOutput = _mapper.Map <GetExternalUserOutputDto>(externalUser); return(ObjectResponse.Ok(externalUserOutput)); }
public async Task <IActionResult> Create([FromBody] ModifyClientInputDto input) { var clientEntity = _mapper.Map <ClientEntity>(input); clientEntity.Id = Guid.NewGuid().ToString(); clientEntity.ClientSecret = Guid.NewGuid().ToString("N"); clientEntity.Enabled = true; await _clientRepository.InsertAsync(clientEntity); await _unitOfWork.SaveChangesAsync(); await _clientInCacheRepository.ClearCacheByIdAsync(clientEntity.ClientId); return(ObjectResponse.Ok()); }
public async Task <IActionResult> Update(string id, [FromBody] ModifyClientInputDto input) { var clientEntity = await _clientRepository.Table.FirstOrDefaultAsync(c => c.Id == id); if (clientEntity != null) { _mapper.Map(input, clientEntity); await _unitOfWork.SaveChangesAsync(); await _clientInCacheRepository.ClearCacheByIdAsync(clientEntity.ClientId); } return(ObjectResponse.Ok()); }
public async Task <IActionResult> ValidateIdentity(IdentityValidateInputDto inputDto) { var validSms = await _validationComponent.ValidSmsAsync(inputDto.Phone, inputDto.Code); if (!validSms.Data) { return(ObjectResponse.Ok(validSms.Code, validSms.Message)); } if (!await _userService.ExistPhoneAsync(inputDto.Phone)) { return(ObjectResponse.Error("手机号不存在")); } var ticket = await _validationComponent.CreateTicketAsync(inputDto.Phone); return(ObjectResponse.Ok(data: ticket)); }
public async Task <ActionResult> Send(SmsSendInputDto inputDto) { var(response, errMsg) = await _externalClient.CaptchaTicketVerify(inputDto.Ticket, inputDto.RandStr); if (response != 1) { return(ObjectResponse.Error(errMsg)); } if (!await _validationComponent.CheckOverLimit(inputDto.Phone)) { return(ObjectResponse.Error("请求频繁请稍后再试")); } var smsType = (ValidationType)inputDto.Type; var result = await _validationComponent.SendAsync(_appSettings.ClientId, inputDto.Phone, smsType, HttpContext.GetIp()); return(ObjectResponse.Ok(result.Code, result.Message)); }
public async Task <ActionResult> GetUserInfo() { var userEntity = await _userService.GetUserByPhoneAsync(User.GetPhoneNo()); var nickName = userEntity.NickName; var userId = userEntity.Id; var openId = User.GetOpenId(); var phone = Regex.Replace(userEntity.Phone, "(\\d{3})\\d{4}(\\d{4})", "$1****$2"); var userInfoOutput = new GetUserInfoOutput { UserId = userId, OpenId = openId, NickName = nickName, Phone = phone }; return(ObjectResponse.Ok(userInfoOutput)); }
public async Task <IActionResult> Login(UserLoginInputDto inputDto) { var(response, errMsg) = await _externalClient.CaptchaTicketVerify(inputDto.Ticket, inputDto.RandStr); if (response != 1) { return(ObjectResponse.Ok(-1, errMsg)); } var result = await _userService.LoginByPasswordAsync(inputDto.UserName, inputDto.Password); if (result.Code != 0) { return(ObjectResponse.Ok(result.Code, result.Message)); } await SignIn(result.Data, UserLoginModel.Password, inputDto.RememberMe); return(ObjectResponse.Ok()); }
public async Task <IActionResult> LoginBySms(LoginBySmsInputDto inputDto) { var validSms = await _validationComponent.ValidSmsAsync(inputDto.Phone, inputDto.Code); if (!validSms.Data) { return(ObjectResponse.Ok(validSms.Code, validSms.Message)); } var userEntity = await _userService.GetUserByPhoneAsync(inputDto.Phone); if (userEntity == null) { return(ObjectResponse.Ok(-1, "用户不存在或未注册")); } if (userEntity.Enabled == false) { return(ObjectResponse.Ok(20043, "您的账号已被禁止登录")); } await SignIn(userEntity, UserLoginModel.SmsCode); return(ObjectResponse.Ok()); }
public async Task <IActionResult> Register(RegisterInputDto inputDto) { var password = _encryptService.DecryptRsa(inputDto.Password); if (string.IsNullOrEmpty(password)) { return(ObjectResponse.Error("密码格式不正确")); } if (Regex.IsMatch(password, RegexConstance.IsPassword) == false) { return(ObjectResponse.Error(password.Length < 6 ? "密码长度不能少于6个字符" : "密码长度不能超过20个字符")); } //验证验证码 var validResult = await _validationComponent.ValidSmsAsync(inputDto.Phone, inputDto.Code); if (!validResult.Data) { return(ObjectResponse.Ok(validResult.Code, validResult.Message)); } if (await _userService.ExistPhoneAsync(inputDto.Phone)) { return(ObjectResponse.Error("手机号已存在")); } var userEntity = await _userService.RegisterAsync(inputDto.Phone, password, _appSettings.ClientId, _appSettings.ClientName, HttpContext.GetIp(), inputDto.Nickname); var openId = MD5.Compute($"openId{_appSettings.ClientId}{userEntity.Id}"); var registerOutput = _mapper.Map <RegisterOutputDto>(userEntity); registerOutput.OpenId = openId; return(ObjectResponse.Ok(registerOutput)); }
public async Task <IActionResult> GetClients() { var clients = await _clientRepository.TableNoTracking.Where(c => c.Enabled).ToListAsync(); return(ObjectResponse.Ok(clients)); }
public async Task <IActionResult> Post([FromBody] AuthorizationCodeModel data) { var(error, result) = await _authorizeClient.GetToken(data.Code, data.State, data.RedirectUri); return(!string.IsNullOrEmpty(error) ? ObjectResponse.Ok(-1, error) : ObjectResponse.Ok(result)); }
public async Task <IActionResult> SignOut() { await HttpContext.SignOutAsync(IdentityServerConstants.DefaultCookieAuthenticationScheme); return(ObjectResponse.Ok()); }
public async Task <IActionResult> LoginByCodeBind(LoginByCodeBindModel model) { var result = await HttpContext.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); if (result.Succeeded == false) { return(ObjectResponse.Ok(10026, "External authentication error")); } var(loginProvider, providerKey) = GetExternalUser(result); if (loginProvider.IsEmpty() || providerKey.IsEmpty()) { return(ObjectResponse.Ok(10026, "操作超时,请重新授权")); } var phoneExist = await _userService.ExistPhoneAsync(model.Phone); var validResult = await _validationComponent.ValidSmsAsync(model.Phone, model.Code); //验证验证码 if (!validResult.Data) { return(ObjectResponse.Ok(20009, "验证码不正确")); } if (!string.IsNullOrEmpty(model.Code)) { await _validationComponent.ClearSession(model.Phone); } if (!phoneExist) {//注册用户 var password = Str.GetRandomString(10); await _userService.RegisterAsync(model.Phone, password, _appSettings.ClientId, _appSettings.ClientName, HttpContext.GetIp()); } var account = await _userService.GetUserByPhoneAsync(model.Phone); if (null == account) { return(ObjectResponse.Ok(20041, "该用户不存在")); } if (!account.Enabled) { return(ObjectResponse.Ok(20043, "您的账号已被禁用")); } //绑定 var bindResult = await _externalUserService.BindExternalUser(_appSettings.ClientId, account.Id, providerKey, loginProvider, string.Empty); if (bindResult.Code != 0) { return(ObjectResponse.Ok(bindResult.Code, bindResult.Message)); } await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme); await SignIn(account, UserLoginModel.External); return(ObjectResponse.Ok()); }