public async Task <ObjectResponse <User> > LoginUserAsync(string email, string password, string signinIp) { UserDb user = await _ivySchoolRepository.GetAllActiveUsers().FirstOrDefaultAsync(e => e.Email == email && e.Password == password); if (user == null) { return(ObjectResponse <User> .Error("The user does not exist.")); } SigninHistoryDb signIn = new SigninHistoryDb() { SigninTime = DateTime.Now, SigninIp = signinIp, userId = user.UserId, }; try { await _ivySchoolRepository.AddSignIn(signIn); } catch (DBOperationException ex) { return(ObjectResponse <User> .Error(ex.Message)); } return(ObjectResponse <User> .Success(user.ToUser())); }
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 <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 <ObjectResponse <IEnumerable <StudentUser> > > GetStudentList() { try { var students = (await _ivySchoolRepository.GetStudents().ToListAsync()).Select(ConvertToStudentUser); return(ObjectResponse <IEnumerable <StudentUser> > .Success(students)); } catch (DBOperationException ex) { return(ObjectResponse <IEnumerable <StudentUser> > .Error(ex.Message)); } }
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 <ObjectResponse <StudentDetail> > GetStudentDetail(int studentId) { try { var student = await _ivySchoolRepository.GetStudents().FirstOrDefaultAsync(); return(ObjectResponse <StudentDetail> .Success(ConvertToStudentDetail(student))); } catch (DBOperationException ex) { return(ObjectResponse <StudentDetail> .Error(ex.Message)); } }
public async Task <ObjectResponse <IEnumerable <User> > > GetAdministrators() { try { var admins = await _ivySchoolRepository.GetAllActiveUsers() .Where(u => u.RoleUsers.Any(ru => ru.Role.Role == "Admin")) .Select(u => u.ToUser()) .ToListAsync(); return(ObjectResponse <IEnumerable <User> > .Success(admins)); } catch (Exception ex) { return(ObjectResponse <IEnumerable <User> > .Error(ex.Message)); } }
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 <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)); }