public static void Send(string num, BulkSMS model) { string theNumber = num; if ((num.StartsWith("234"))) { // theNumber = num.Substring(3); } if ((num.StartsWith("+234"))) { theNumber = num.Substring(1); } if ((num.StartsWith("0"))) { theNumber = num.Substring(1); theNumber = "234" + theNumber; } string senderusername = "******"; string senderpassword = "******"; string senderid = "School"; string body = model.Body; string sURL; StreamReader objReader; sURL = "http://login.betasms.com/customer/api/?username="******"&password="******"&message=" + body + "&sender=" + senderid + "&mobiles=" + theNumber;// +"&type=1&message=" + txtMessage.Text; WebRequest wrGETURL; wrGETURL = WebRequest.Create(sURL); try { Stream objStream; objStream = wrGETURL.GetResponse().GetResponseStream(); objReader = new StreamReader(objStream); objReader.Close(); } catch (Exception ex) { // continue; // ex.ToString(); } //h }
public async Task <IActionResult> OnPostAsync(string returnUrl = null, bool acceptTerms = false, bool isMobileConfirmed = false) { returnUrl = returnUrl ?? Url.Content("~/"); ReturnUrl = returnUrl; ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); Input.Mobile = ConvertClass.PersianToEnglish(Input.Mobile); if (ModelState.IsValid) { //Mobile Verification //Create four digint number for verify code as a token Random randomNumber = new Random(); string token = randomNumber.Next(0, 9999).ToString("D4"); //Create new user var user = new ApplicationUser { UserName = Input.Mobile, FullName = Input.FullName, Mobile = Input.Mobile, MobileVerificationCode = token, IsMobileConfirmed = false, RegisteredDate = System.DateTime.Now, ClientRole = ClientRole.Public }; //Create User and save to database var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, ClientRole.Public.ToString()); _logger.LogInformation("User created a new account with password."); //Send token (verification code) to the Client var bulkSMS = new BulkSMS(_clientFactory); var mobileFormatForSMS = _config.GetValue <string>("BulkSMS:Code") + Input.Mobile.Remove(0, 1); var bulkSMSMessage = new List <BulkSMSMessage>() { new BulkSMSMessage() { Number = mobileFormatForSMS, Text = $"Code= {token}. {_config.GetValue<string>("BulkSMS:Website")}" } }; var response = await bulkSMS.SendBulkSMS(senderId : _config.GetValue <string>("BulkSMS:SenderId"), messageParameter : bulkSMSMessage, apiKey : _config.GetValue <string>("BulkSMS:ApiKey"), clientId : _config.GetValue <string>("BulkSMS:ClientId")); if (response.IsSuccessStatusCode) { var smsResult = await response.Content.ReadAsStringAsync(); //Handle Error } if (_userManager.Options.SignIn.RequireConfirmedAccount && !string.IsNullOrEmpty(user.Email)) { return(RedirectToPage("RegisterConfirmation", new { email = user.Email })); } else { //Send Client to verify the phone number user.Id = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(user.Id)); return(RedirectToPage("PhoneNumberVerification", new { returnUrl = ReturnUrl, userid = user.Id })); } } foreach (var error in result.Errors) { if (error.Code.Equals("DuplicateUserName")) { error.Description = "An account already exists with this number. Please try to login"; } ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ReturnUrl = returnUrl; Input.Mobile = ConvertClass.PersianToEnglish(Input.Mobile); if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(Input.Mobile); if (user != null) { if (!user.IsMobileConfirmed) { string token = user.MobileVerificationCode; //Send token to the KavenegarApi (for sending to client) if (string.IsNullOrEmpty(token)) { Random randomNumber = new Random(); token = randomNumber.Next(0, 9999).ToString("D4"); user.MobileVerificationCode = token; await _userManager.UpdateAsync(user); } var bulkSMS = new BulkSMS(_clientFactory); var mobileFormatForSMS = _config.GetValue <string>("BulkSMS:Code") + user.Mobile.Remove(0, 1); var bulkSMSMessage = new List <BulkSMSMessage>() { new BulkSMSMessage() { Number = mobileFormatForSMS, Text = $"Code= {token}. {_config.GetValue<string>("BulkSMS:Website")}" } }; var response = await bulkSMS.SendBulkSMS(senderId : _config.GetValue <string>("BulkSMS:SenderId"), messageParameter : bulkSMSMessage, apiKey : _config.GetValue <string>("BulkSMS:ApiKey"), clientId : _config.GetValue <string>("BulkSMS:ClientId")); if (response.IsSuccessStatusCode) { var smsResult = await response.Content.ReadAsStringAsync(); //Handle Error } //Send Client to verify the phone number user.Id = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(user.Id)); return(RedirectToPage("PhoneNumberVerification", new { returnUrl = ReturnUrl, userid = user.Id })); } } else { ModelState.AddModelError(string.Empty, "Mobile number or password is not correct!"); return(Page()); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(Input.Mobile, Input.Password, Input.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { HttpContext.Session.SetInt32("Message", (int)Messages.LoggedIn); _logger.LogInformation("User logged in."); return(LocalRedirect(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { ModelState.AddModelError(string.Empty, "Mobile number or password is not correct!"); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }
public static dynamic SendNow(BulkSMS model) { try { if (!(string.IsNullOrEmpty(model.Numbers))) { string[] numbers = model.Numbers.Split(';'); if (numbers.Count() > 0) { foreach (string num in numbers) { Send(num, model); //ttp://login.betasms.com/customer/api/[email protected]&password=light&message=test&sender=demo&mobiles=2347034455709 } } } if (!(string.IsNullOrEmpty(model.ClassArm))) { string theArm = model.ClassArm; UnitOfWork work = new UnitOfWork(); List<PrimarySchoolStudent> theStudent = work.PrimarySchoolStudentRepository.Get(a => a.LevelType == theArm && a.HomeTelephone != null).ToList(); string[] numbers = model.ClassArm.Split(';'); if (theStudent.Count() > 0) { foreach (PrimarySchoolStudent stu in theStudent) { string num = stu.HomeTelephone; Send(num, model); } } } if (!(string.IsNullOrEmpty(model.Class))) { List<PrimarySchoolStudent> theStudent = new List<PrimarySchoolStudent>(); string Class = model.Class; UnitOfWork work = new UnitOfWork(); if(Class =="All Students") { theStudent = work.PrimarySchoolStudentRepository.Get(a => a.HomeTelephone != null).ToList(); if (theStudent.Count() > 0) { foreach (PrimarySchoolStudent stu in theStudent) { string num = stu.HomeTelephone; Send(num, model); } } } if (Class == "All Staff") { List<PrimarySchoolStaff> theStaff = work.PrimarySchoolStaffRepository.Get(a => a.Telephone != null).ToList(); if (theStaff.Count() > 0) { foreach (PrimarySchoolStaff staff in theStaff) { string num = staff.Telephone; Send(num, model); } } } else { theStudent = work.PrimarySchoolStudentRepository.Get(a => a.PresentLevel == Class && a.HomeTelephone != null).ToList(); if (theStudent.Count() > 0) { foreach (PrimarySchoolStudent stu in theStudent) { string num = stu.HomeTelephone; Send(num, model); } } } // string[] numbers = model.ClassArm.Split(';'); } } catch (Exception e) { return 1; } return 3; }