public IActionResult SendSmsConfirm(string smsText, string phoneNumber) { string nvm; //string ApiKey = "bb7ad448e474177ad90ee1ab"; //string SecurityCode = "PersianDoorsCo!@#12345"; //string lineNumber = "30004747474480"; var setting = dbSetting.GetAll().FirstOrDefault(); string ApiKey = setting.SMSApiAddress; string SecurityCode = setting.SMSUsername; string lineNumber = setting.SMSApiNumber; //متن پیامک string message = smsText; //شماره مقصد string mobileNumber = phoneNumber; var result = SmsIrService.SendSms(ApiKey, SecurityCode, lineNumber, message, mobileNumber); if (result) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Insert, contentRootPath); return(RedirectToAction("SendSms", new { notification = nvm })); } nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath); return(RedirectToAction("SendSms", new { notification = nvm })); }
}//end ApproveVerificationToken public async Task <int> ResetPassword(ApplicationUser _User) { if (_User != null) { var setting = _db.Setting.FirstOrDefault(); var isUserName_Number = double.TryParse(_User.UserName, out double r) ? r : 0; var token = await GeneratePhoneNumberTokenAsync(_User); if (token != null) { string message = $"کد بازیابی کلمه عبور: {token}"; if (isUserName_Number > 0) { string mobileNumber = _User.UserName; var result = SmsIrService.SendSms(setting.SMSApiAddress, setting.SMSPassword, setting.SMSApiNumber, message, mobileNumber); } else { EmailViewModel emailViewModel = new EmailViewModel() { Subject = "ایمیل تاییدیه ثبت نام", ReceiverEmail = _User.UserName, Content = message, SenderEmail = setting.AdminEmail, Password = setting.AdminEmailPassword }; var port = int.TryParse(setting.EmailPort, out int rr) ? rr : 587; EmailService.EmailService.Send(emailViewModel, setting.EmailServiceProvider, port); } var hasPassword = await _userManager.HasPasswordAsync(_User); if (hasPassword == true) { var removePassword = await _userManager.RemovePasswordAsync(_User); } return(1); } return(-2); } else { return(0); } }
/// <summary> /// Return Parameters: 1 => SentBySMS, 2 => SentByEmail, 0 => nothing happens, -1 => Error /// </summary> /// <param name="_User"></param> /// <returns></returns> public async Task <int> SendVerificationToken(ApplicationUser _User) { try { if (_User != null) { var setting = _db.Setting.FirstOrDefault(); string token = await GenerateForPhoneNumber(_User); string message = $"کد تایید شما: {token}"; var lastTokens = _db.Tokens.Where(x => x.UserId == _User.Id).ToList(); if (lastTokens.Count > 0) { _db.Tokens.RemoveRange(lastTokens); _db.SaveChanges(); } Tokens tokens = new Tokens() { UserId = _User.Id, Token = token, Used = false }; await _db.Tokens.AddAsync(tokens); await _db.SaveChangesAsync(); var isUserName_Number = double.TryParse(_User.UserName, out double r) ? r : 0; if (isUserName_Number > 0) { //متن پیامک //string message = smsText; //شماره مقصد string mobileNumber = _User.UserName; var result = SmsIrService.SendSms(setting.SMSApiAddress, setting.SMSPassword, setting.SMSApiNumber, message, mobileNumber); //SMSService.SMSService SMS = new SMSService.SMSService(_db); //SMS.SendSMS(new List<string> { _User.UserName }, message); return(1); } else { //still not complete.... EmailViewModel emailViewModel = new EmailViewModel() { Subject = "ایمیل تاییدیه ثبت نام", ReceiverEmail = _User.UserName, Content = message, SenderEmail = setting.AdminEmail, Password = setting.AdminEmailPassword }; var port = int.TryParse(setting.EmailPort, out int rr) ? rr : 587; EmailService.EmailService.Send(emailViewModel, setting.EmailServiceProvider, port); return(2); } } return(0); } catch (Exception ex) { return(-1); } }//end SendVerificationToken