/// <summary> /// /// </summary> /// <param name="PhValidator"></param> /// <returns>True if created, false if already exisiting</returns> public PhoneValidation CreatePhoneValidatorEntry(PhoneValidation PhValidator, ref bool IsReused) { if (PhValidator != null) { PhoneValidation phValid = LoadPhoneValidation(PhValidator.AuthenticatedLiveID, PhValidator.PhoneNumber); if (phValid == null) { PhValidator.PartitionKey = PhValidator.RegionCode.Substring(1);//to avoid + PhValidator.RowKey = PhValidator.SecurityToken.ToString() + "_" + DateTime.Now.Ticks.ToString(); PhValidator.PhoneNumber = Security.Encrypt(PhValidator.PhoneNumber); SavePhoneValidationRecord(PhValidator); IsReused = false; PhValidator.PhoneNumber = Security.Decrypt(PhValidator.PhoneNumber); return(PhValidator); } else { IsReused = true; phValid.PhoneNumber = Security.Decrypt(phValid.PhoneNumber); return(phValid); } } return(null); }
public void ValidateMobileNumber_Test3() { string phoneNumber = "(0401) 606888"; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual("+61401606888", actual); }
public static async void ValidateMobileNumberAsync(string userName, string liveId, string countryCode, string mobileNumber, string enterpriseEmail) { PhoneValidation validationInfo = new PhoneValidation(); validationInfo.AuthenticatedLiveID = liveId; validationInfo.Name = userName; validationInfo.PhoneNumber = countryCode + mobileNumber; validationInfo.RegionCode = countryCode; validationInfo.EnterpriseEmailID = enterpriseEmail; string serviceUrl = Constants.MembershipServiceUrl + "CreatePhoneValidator"; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(PhoneValidation)); using (MemoryStream ms = new MemoryStream()) { ser.WriteObject(ms, validationInfo); string data = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length); WebClient wc = new WebClient(); wc.Headers["Content-type"] = "application/json"; wc.Headers["AuthID"] = Globals.User.LiveAuthId; wc.Encoding = Encoding.UTF8; string result = await wc.UploadStringTask(new Uri(serviceUrl), data); } }
public static AnyType Create(string type) { // Design pattern :- Lazy loading != Eager loading if (ObjectsOfOurProjects == null) { ObjectsOfOurProjects = new UnityContainer(); //Lead IValidation <ICustomer> leadValidation = new PhoneValidation(new CustomerBasicValidation()); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("Lead", new InjectionConstructor(leadValidation, "Lead")); //SelfService IValidation <ICustomer> selfServiceValidation = new CustomerBasicValidation(); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("SelfService", new InjectionConstructor(selfServiceValidation, "SelfService")); //HomeDelivery IValidation <ICustomer> homeDeliveryValidation = new AddressValidation(new CustomerBasicValidation()); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("HomeDelivery", new InjectionConstructor(homeDeliveryValidation, "HomeDelivery")); //Customer IValidation <ICustomer> customerValidation = new AddressValidation(new BillDateValidation(new BillAmountValidation(new PhoneValidation(new CustomerBasicValidation())))); ObjectsOfOurProjects.RegisterType <CustomerBase, Customer>("Customer", new InjectionConstructor(customerValidation, "Customer")); } // Design pattern :- RIP Replace If with Poly return(ObjectsOfOurProjects.Resolve <AnyType>(type)); }
public void CreatePhoneValidatorUnitTest() { HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(BaseUrl + "CreatePhoneValidator"); webrequest.Method = "POST"; PhoneValidation phoneValidation = new PhoneValidation(); phoneValidation.AuthenticatedLiveID = "*****@*****.**"; phoneValidation.Name = "Sarita Jain"; phoneValidation.PhoneNumber = "8106968383"; phoneValidation.RegionCode = "+91"; phoneValidation.SecurityToken = "12345"; string postData = JsonConvert.SerializeObject(phoneValidation); byte[] byteArray = Encoding.UTF8.GetBytes(postData); Stream dataStream = webrequest.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); webrequest.ContentType = "application/json"; webrequest.Headers.Add("AuthID", "eyJhbGciOiJIUzI1NiIsImtpZCI6IjEiLCJ0eXAiOiJKV1QifQ.eyJ2ZXIiOjEsImlzcyI6InVybjp3aW5kb3dzOmxpdmVpZCIsImV4cCI6MTQwOTU4OTQ4NywidWlkIjoiZjJhYTc2MTJjYTA1MGU1NmE4ODY5NDI0NGNlYmE2ZmEiLCJhdWQiOiJndWFyZGlhbnBvcnRhbC1kZXYuY2xvdWRhcHAubmV0IiwidXJuOm1pY3Jvc29mdDphcHB1cmkiOiJhcHBpZDovLzAwMDAwMDAwNDAxMEE2MjciLCJ1cm46bWljcm9zb2Z0OmFwcGlkIjoiMDAwMDAwMDA0MDEwQTYyNyJ9.zcpf0Y5HoAggrhx0x7Gq_x_TE69YOSkCAjzlFqKIpC0"); webrequest.Headers.Add("LiveUserID", "7a7078ea9439d2f7ed0cf35cf0ffa167"); var response = webrequest.GetResponse() as HttpWebResponse; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void ValidateMobileNumber_Test9() { string phoneNumber = null; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual(null, actual); }
public void ValidateMobileNumber_Test6() { string phoneNumber = "034016 06888"; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual(null, actual); }
public static AnyType Create(string Type) { // Design pattern :- Lazy loading. Eager loading if (ObjectsofOurProjects == null) { ObjectsofOurProjects = new UnityContainer(); IValidation <ICustomer> custValidation = new PhoneValidation(new CustomerBasicValidation()); ObjectsofOurProjects.RegisterType <CustomerBase, Customer> ("Lead", new InjectionConstructor(custValidation, "Lead")); custValidation = new CustomerBasicValidation(); ObjectsofOurProjects.RegisterType <CustomerBase, Customer> ("SelfService", new InjectionConstructor(custValidation, "SelfService")); custValidation = new CustomerAddressValidation(new CustomerBasicValidation()); ObjectsofOurProjects.RegisterType <CustomerBase, Customer> ("HomeDelivery", new InjectionConstructor(custValidation, "HomeDelivery")); custValidation = new PhoneValidation( new CustomerBillValidation( new CustomerAddressValidation( new CustomerBasicValidation()))); ObjectsofOurProjects.RegisterType <CustomerBase, Customer> ("Customer" , new InjectionConstructor( custValidation, "Customer")); } //Design pattern :- RIP Replace If with Poly return(ObjectsofOurProjects.Resolve <AnyType>(Type)); }
private static IUnityContainer LoadCustDict() { IUnityContainer cust = new UnityContainer(); IValidation <ICustomer> custValidation = new PhoneValidation( new CustomerBasicValidation()); cust.RegisterType <CustomerBase, Customer>("Lead", new InjectionConstructor(custValidation, "Lead")); custValidation = new CustomerBasicValidation(); cust.RegisterType <CustomerBase, Customer>("SelfService", new InjectionConstructor(custValidation, "SelfService")); custValidation = new CustomerAddressValidation( new CustomerBasicValidation()); cust.RegisterType <CustomerBase, Customer>("HomeDelivery", new InjectionConstructor(custValidation, "HomeDelivery")); custValidation = new PhoneValidation( new CustomerBillValidation( new CustomerAddressValidation( new CustomerBasicValidation()))); cust.RegisterType <CustomerBase, Customer>("Customer", new InjectionConstructor(custValidation, "Customer")); return(cust); }
public Phone(int number, int areaCode, string countryCode) { Number = number; AreaCode = areaCode; CountryCode = countryCode; Validation = new PhoneValidation().Validate(this); }
public void Validate() { if (CanValidate()) { var test = PhoneValidation.Test(entry.Value); SetInvalidStatus(test); } }
public void Validate() { if (CanValidate()) { var test = PhoneValidation.Test(property.Value); SetStatus(test, ERROR_CODE.INVALID); } }
//private AppDbContext db;// = new AppDbContext(); #endregion #region PhoneValidation /// <summary> /// Inserts a new row in the MdmDQQue table. /// </summary> /// <param name="mdmque">A MdmDQQue object.</param> /// <returns>An updated MdmDQQue object.</returns> public PhoneValidation InsertPhoneValidation(PhoneValidation mdmdque) { using (var db = new AppDbContext()) { db.Set <PhoneValidation>().Add(mdmdque); db.SaveChanges(); return(mdmdque); } }
public void SavePhoneValidationRecord(PhoneValidation PhValidator) { base.LoadEntityTable(Constants.PhoneValidationTableName); if (base.IsTableLoaded) { TableOperation insertUser = TableOperation.InsertOrReplace(PhValidator); base.EntityTable.Execute(insertUser); } }
/// <summary> /// Updates an existing row in the mdmdque table. /// </summary> /// <param name="mdmdque">A mdmdque entity object.</param> public void UpdatePhoneValidation(PhoneValidation mdmdque) { using (var db = new AppDbContext()) { var entry = db.Entry <PhoneValidation>(mdmdque); // Re-attach the entity. entry.State = EntityState.Modified; db.SaveChanges(); } }
/// <summary> /// Updates the queitem /// </summary> /// <param name="queitem">queitem</param> public virtual void UpdatePhoneValidation(PhoneValidation queitem) { if (queitem == null) { throw new ArgumentNullException("queitem"); } _pvDAC.UpdatePhoneValidation(queitem); //event notification //_eventPublisher.EntityUpdated(vendor); }
/// <summary> /// Delete an item /// </summary> /// <param name="queitem">QueItem</param> public virtual void DeleteQueItem(PhoneValidation queitem) { if (queitem == null) { throw new ArgumentNullException("queitem"); } UpdatePhoneValidations(queitem); //event notification //_eventPublisher.EntityDeleted(vendor); }
public void PhoneValidTest() { MemberService MS = new MemberService(); PhoneValidation ph = new PhoneValidation() { AuthenticatedLiveID = "*****@*****.**", Name = "sharath", RegionCode = "+91", PhoneNumber = "+917702690004" }; MS.CreatePhoneValidator(ph); }
public bool DeletePhoneValidationEntry(PhoneValidation PhValidationToDelete) { bool DeleteState = false; if (PhValidationToDelete != null && PhValidationToDelete.IsValiated) { if (base.LoadTableSilent(Constants.PhoneValidationTableName)) { TableOperation deleteOperation = TableOperation.Delete(PhValidationToDelete); base.EntityTable.Execute(deleteOperation); DeleteState = true; } } return(DeleteState); }
public async Task <ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model) { if (ModelState.IsValid && PhoneValidation.CheckPhone(model.Number)) { var code = await UserManager.GenerateChangePhoneNumberTokenAsync(model.Id, model.Number); if (UserManager.SmsService != null) { var message = new IdentityMessage { Destination = model.Number, Body = "Your security code is: " + code }; await UserManager.SmsService.SendAsync(message); } return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number, Id = model.Id })); } ViewBag.Error = "Phone Number is not valid"; return(View(model)); // Generate the token and send it }
public static T Create(string type) { if (projectObjects == null) { projectObjects = new UnityContainer(); IValidation <ICustomer> custValidation = new PhoneValidation(new CustomerBasicValidation()); //projectObjects.RegisterType<CustomerBase, Customer>("Customer", // new InjectionConstructor(new CustomerValidationAll())); projectObjects.RegisterType <CustomerBase, Customer>("Lead", new InjectionConstructor(custValidation, "Lead")); custValidation = new CustomerBasicValidation(); projectObjects.RegisterType <CustomerBase, Customer>("SelfService", new InjectionConstructor(custValidation, "SelfService")); custValidation = new CustomerAddressValidation(new CustomerBasicValidation()); projectObjects.RegisterType <CustomerBase, Customer>("HomeDelivery", new InjectionConstructor(custValidation, "HomeDelivery")); custValidation = new PhoneValidation( new CustomerBillValidation( new CustomerAddressValidation( new CustomerBasicValidation() ) ) ); projectObjects.RegisterType <CustomerBase, Customer>("Customer", new InjectionConstructor(custValidation, "Customer")); //projectObjects.RegisterType<IRepository<ICustomer>, CustomerDAL>("ADODal"); } return(projectObjects.Resolve <T>(type)); }
public ActionResult Add(RegisterUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } string errorMessage = "Unable to register. Please contact us for assistance."; try { if (Roles.IsUserInRole("Admin")) { model.IsAdmin = true; } string userLogin = model.Email.ToLower(); if (WebSecurity.UserExists(userLogin)) { ModelState.AddModelError("EmailAlreadyExists", "The Email address is already in use."); return(View(model)); } WebSecurity.CreateUserAndAccount(userLogin, model.Password); ApplicationUser user = model.ToApplicationUser(); user.ApplicationUserId = WebSecurity.GetUserId(userLogin); user.Email = userLogin; ResultEnum result = userService.CreateApplicationUser(user); switch (result) { case ResultEnum.Success: if (model.IsProvider && !Roles.IsUserInRole("Admin")) { Roles.AddUserToRoles(userLogin, new string[] { "Provider" }); } else if (model.IsProvider && Roles.IsUserInRole("Admin")) { Roles.AddUserToRoles(userLogin, new string[] { "Provider", "ActiveUser" }); } else if (!model.IsAdmin) { Roles.AddUserToRoles(userLogin, new string[] { "Customer", "ActiveUser" }); } if (!Roles.IsUserInRole("Admin")) { if (WebSecurity.Login(model.Email, model.Password)) { // Login successful // Send SMS message to confirm successful registration string phoneNumber = PhoneValidation.ValidateMobileNumber(model.Phone); if (phoneNumber != null) { string message = String.Format( "Hi {0}, We're just confirming your successful registration with Grande Travel.", model.FirstName); GrandeTravel.Utility.IPhoneService commClient = UtilityFactory.GetPhoneService(Authentication.GetTwilioAuthentication()); Task task = commClient.SendSMSAsync(phoneNumber, message); } // If the customer wants to order a package, redirect to Payment if (model.HasPackage) { return(RedirectToAction("CreateTransaction", "Payment", new { PackageId = model.PackageId })); } // If a provider, show confirmation message if (model.IsProvider && !Roles.IsUserInRole("Admin")) { model.AccountCreatedSuccessfully = true; model.isProviderConfirmed = true; WebSecurity.Logout(); return(View(model)); } return(RedirectToAction("Index", "Home")); } else { // Login unsuccessful ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } } else { // Admin user - Create user only. Show success message, but do not log in. model.AccountCreatedSuccessfully = true; return(View(model)); } case ResultEnum.Fail: break; } } catch (Exception) { ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } return(View(model)); }
public ActionResult CreateTransaction(FormCollection collection) { string resultMessage = "The transaction could not be processed."; // FormCollection is needed in order to use client-side encryption. if (collection.Count <= 1) { // Encryption failed / form not valid - go to failure page LogTransaction("Form fields not received.", false); return(RedirectToResult(resultMessage, false)); } var packageHolder = TempData["Package"]; if (packageHolder == null) { // Go to failure page - card not charged LogTransaction("No package information received.", false); return(RedirectToResult(resultMessage, false)); } Order order; Payment payment; package = (Package)packageHolder; try { // Get ApplicationUser Result <ApplicationUser> userResult = userService.GetApplicationUserById(WebSecurity.CurrentUserId); if (userResult.Status != ResultEnum.Success) { // Go to failure page - card not charged LogTransaction("Unable to get user details.", false); return(RedirectToResult(resultMessage, false)); } user = userResult.Data; // Create Order Result <Order> orderResult = orderService.AddOrder(new Order { PackageId = package.PackageId, Amount = package.Amount, CustomerId = WebSecurity.CurrentUserId, DateBooked = DateTime.Now, Paid = false }); if (orderResult.Status != ResultEnum.Success) { // Go to failure page - card not charged LogTransaction("Unable to get order details.", false); return(RedirectToResult(resultMessage, false)); } order = orderResult.Data; } catch (Exception e) { // Go to failure page - card not charged LogTransaction(e.Message, false); return(RedirectToResult(resultMessage, false)); } // Submit Payment try { payment = new Payment { CCNumber = collection["number"], CVV = collection["cvv"], ExpirationMonth = collection["month"], ExpirationYear = collection["year"], Amount = package.Amount, PackageId = package.PackageId, PackageName = package.Name }; IPaymentService paymentService = UtilityFactory.GetBrainTreeService(Authentication.GetBrainTreeAuthentication()); paymentResult = paymentService.SubmitPayment(payment); if (!paymentResult.IsSuccess) { LogTransaction("Error submitting payment.", false); return(RedirectToResult(resultMessage, false)); } } catch (Exception e) { LogTransaction(e.Message, false); return(RedirectToResult(resultMessage, false)); } // Payment Successful resultMessage = "Your transaction has been processed. Enjoy your holiday!"; try { // Update Order order.Paid = true; order.TransactionId = paymentResult.TransactionId; ResultEnum result = orderService.UpdateOrder(order); if (result != ResultEnum.Success) { // Payment succeeded, but database update failed. LogTransaction("Failed to update database.", true); } } catch (Exception e) { // Payment succeeded, but database update failed. LogTransaction(e.Message, true); resultMessage = "Your transaction has been processed. Please contact us about your trip."; } try { // Send SMS string phoneNumber = PhoneValidation.ValidateMobileNumber(user.Phone); if (phoneNumber != null) { string smsMessage = String.Format( "Hi {0}, Congratulations on your successful order of our {1} package. Enjoy your trip!", user.FirstName, package.Name); GrandeTravel.Utility.IPhoneService commClient = UtilityFactory.GetPhoneService(Authentication.GetTwilioAuthentication()); commClient.SendSMSAsync(phoneNumber, smsMessage); } // Send Email IEmailService emailService = UtilityFactory.GetEmailService(Authentication.GetDefaultEmailAuthentication()); string crlf = "<br />"; DateTime expiryDate = DateTime.Today.AddMonths(3); Email email = new Email { // Unique voucher code, package details, and expiry date which are 3 months from the date of payment. From = Authentication.GetDefaultEmailSenderAddress(), To = WebSecurity.CurrentUserName, Subject = "Grande Travel Package Details", Body = String.Format( "Hi {1}, {0}{0}" + "Your payment of {2} for our {3} package has been successful. {0}" + "Your credit card transaction code is {4}. {0}{0}" + "Your Grande Travel voucher code is {5}, which is redeemable until {6}.{0}", crlf, user.FirstName, String.Format("{0:c}", package.Amount), package.Name, order.TransactionId, order.VoucherCode.ToString("00000000"), expiryDate.ToLongDateString()) }; emailService.SendEmailAsync(email); } catch (Exception e) { // Email or Sms failed - but this will not catch async errors. LogTransaction(e.Message, true); resultMessage = "Your transaction has been processed. <br /> Please contact us about your trip."; return(RedirectToResult(resultMessage, true)); } LogTransaction("Successful Purchase.", true); return(RedirectToResult(resultMessage, true)); }
public void Setup() { validator = new PhoneValidation(); }