public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, Mobile = model.Mobile, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); var userActivation = new UserActivation { Id = Guid.NewGuid().ToString(), Created = DateTime.Now, Expires = DateTime.Now.AddMinutes(ActivationExpiryInMinutes), IdentityCode = code, UserId = user.Id, ShortCode = Health.Configuration.Extensions.GetRandomNumber() }; await _doctorManager.AddUserActivation(userActivation); //Send SMS with the short code _smsSender.Send(model.Mobile, "Activation code: " + userActivation.ShortCode); try { if (!string.IsNullOrWhiteSpace(model.Email)) { await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); } } catch // Ignored { } _logger.LogInformation("User created a new account with password."); return(Ok(new { Success = true })); } AddErrors(result); } return(BadRequest(new { Success = false, Msg = "Invalid model" })); }
private void Loop_CastleWindsor(int iterations) { LoopFunction(delegate { ISmsSender oSms = container.Resolve <ISmsSender>(); oSms.Send("Hola mundo", "Hola mundo"); }, iterations); }
public bool Login(string phone, string password) { var re = _userDal.Exists(phone, password); if (re) { _smsSender.Send(phone, "您已成功登录系统"); } return(re); }
private void btnCastleWindsor_Click(object sender, EventArgs e) { txtOutput.AppendTextLine("CASTLE WINDSOR TEST"); txtOutput.AppendTextLine("-------------------"); ISmsSender oSms = container.Resolve <ISmsSender>(); oSms.Send("Hola mundo", "Hola mundo"); txtOutput.AppendTextLine("RESULT:"); txtOutput.AppendTextLine(TraceFile.Output); txtOutput.AppendTextLine("-------------------"); TraceFile.Output = ""; }
public bool Login(string phone, string password) { bool re = _userDal.Exists(phone, password); if (re) { ISmsSender smsSender = _smsSenderFactory.Create(); smsSender.Send(phone, "您已成功登录系统"); } return(re); }
public SendRegCodeResult SendRegCode(string mobile) { if (mobile.Length != 11) { return(SendRegCodeResult.WrongFormat); } if (mobile.Equals("13900000000")) { return(SendRegCodeResult.AlreadyRegistered); } _smsSender.Send(mobile, "123456"); return(SendRegCodeResult.Ok); }
public static SmsResult Send(this ISmsSender sender, string phone, string msg) { var item = new SmsItem { message = msg, phone = phone }; var lst = new List <SmsItem>() { item }; return(sender.Send(lst).First()); }
public async Task <IActionResult> SendSms([FromBody] SendSmsReq req) { if (!ModelState.IsValid) { return(BadRequest()); } Result result = await _smsSender.Send(req.Number, req.Message); if (result.Failure) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Otp(int userId, string mobileNumber, string email) { var code = await _otpProxy.Generate(new OtpGenerateParameter { UserId = userId }); await _smsSender.Send(new SmsSendParameter { MobileNumber = mobileNumber, Text = $"Your activation key is {Environment.NewLine}{code}" }); new OtpParameters { UserId = userId, Email = email }; return(View()); }
public AuthenticationResult Authenticate(string userName, string password) { var validationResult = _userNamePasswordValidator.Validate(userName, password); if (validationResult is InvalidUserNamePassword) { return(AuthenticationResult.InvalidUsernamePassword); } if (validationResult is ValidUserNamePassword validUserNamePassword) { var user = validUserNamePassword.User; var twoFactorCode = _twoFactorCodeGenerator.Generate(); _smsSender.Send(user.PhoneNumber, twoFactorCode); return(AuthenticationResult.TwoFactorAuthenticationViaSmsInitiated); } throw new Exception("Unknown validation result: " + validationResult.GetType()); }
public async Task <Result <string> > CreateCode(string username) { var user = await userService.GetUser(username); if (user == null) { return(UserNotFound); } var code = GenerateCode(); var sendSuccess = smsService.Send(user.Phone, code); if (sendSuccess != SmsResult.OK) { return(FailedToSendSms); } await verificationService.Create(username, code); return(code); }
public async Task <SendSMSResponse> Get(SendSMS request) { var receiverCountry = CountryLookup.ByPhoneNumber( await Db.SelectAsync <Country>(), request.To.ReplaceAll("+", "")); var sentState = await SmsSender.Send(request.From, request.To, request.Text); var sms = request.ConvertTo <Sms>(); sms.CreatedAt = DateTime.Now.ToUniversalTime(); sms.State = sentState; sms.Price = receiverCountry.PricePerSMS; sms.CountryId = receiverCountry.Id; await Db.SaveAsync(sms); return(new SendSMSResponse { State = sms.State }); }
private void SendIdentifyCodeByPhone(string phone, IdentifyCodeOutput identifyCode, IdentifyCodeType identifyCodeType) { string smsTempleteCode; string title = ""; switch (identifyCodeType) { case IdentifyCodeType.Register: smsTempleteCode = "SMS_128575019"; title = "用户注册"; break; case IdentifyCodeType.RetrievePwd: smsTempleteCode = "SMS_128545037"; title = "找回密码"; break; default: throw new LotteryException("无法获取该种类型的验证码"); } var templateParam = "{\"code\":\"" + identifyCode.Code + "\"}"; SendCommandAsync(new AddMessageRecordCommand(Guid.NewGuid().ToString(), null, phone, title, templateParam, (int)identifyCodeType, (int)AccountRegistType.Phone, _lotterySession.UserId)); if (identifyCode.IsNew) { SendCommandAsync(new AddIdentifyCodeCommand(identifyCode.IdentifyCodeId, phone, identifyCode.Code, (int)identifyCodeType, (int)AccountRegistType.Phone, identifyCode.ExpirationDate, _lotterySession.UserId)); } else { SendCommandAsync(new UpdateIdentifyCodeCommand(identifyCode.IdentifyCodeId, identifyCode.Code, phone, identifyCode.ExpirationDate, _lotterySession.UserId)); } _smsSender.Send(phone, templateParam, smsTempleteCode); }
public async Task <Result> GenerateSmsCode(string userId) { string timeoutKey = string.Format(SEND_SMS_KEY, userId); bool timeout = _memoryCache.TryGetValue(timeoutKey, out string temp); if (timeout) { return(Result.Fail("to_many_requests", "To many requests")); } _memoryCache.Set(timeoutKey, "temp", TimeSpan.FromSeconds(SEND_TIMEOUT_SECONDS)); AppUserEntity appUser = await _userManager.FindByIdAsync(userId); if (appUser == null) { _logger.LogError($"No user. UserId {userId}"); return(Result.Fail($"no_user", "No User")); } if (string.IsNullOrEmpty(appUser.PhoneNumber)) { _logger.LogError($"User does not have a phone number. UserId {userId}"); return(Result.Fail($"phone_number_not_found", "Phone number not found")); } string code = await _userManager.GenerateTwoFactorTokenAsync(appUser, TwoFactorAuthenticationType.Phone.ToProvider()); Result smsSendResult = await _smsSender.Send(appUser.PhoneNumber, $"Authentication code: {code}"); if (smsSendResult.Failure) { return(Result.Fail(smsSendResult.Errors)); } return(Result.Ok()); }