// [ValidateInput(false)] public ActionResult Registration(RegisterViewModel register) { if (!ModelState.IsValid) { return(JsonValidationError()); } if (!string.IsNullOrEmpty(register.Password)) { if (!Regex.IsMatch(register.Password, SiteUtils.GetPasswordRegex())) { ModelState.AddModelError("Password", "Password does not meet policy!"); return(JsonValidationError()); } } var response = new BoolResponse(); //-- to check if user's Email Address already registered var existingUser = _customerRepository.GetExistingUser(Sanitizer.GetSafeHtmlFragment(register.Email)); if (existingUser.Result != null) { if (existingUser.Result.Count > 0 && existingUser.Result[0].UserSourceType != UserSourceTypes.Newsletter.GetHashCode().ToString()) { ModelState.AddModelError("Error", "Your email address is already registered with us."); return(JsonValidationError()); } var user = new CustomerModel { Email = Sanitizer.GetSafeHtmlFragment(register.Email), Password = Sanitizer.GetSafeHtmlFragment(register.Password), NotifyByEmail = register.NotifyByEmail, NotifyByPost = register.NotifyByPost, NotifyBySMS = register.NotifyBySMS, NewsLetterSubscribed = !register.NewsLetterSubscribed, SourceProcess = register.SourceProcess, IsRegistered = true }; var result = _customerRepository.Register(user); if (result.Result.IsValid) { var loginResult = _authenticationService.Login(Sanitizer.GetSafeHtmlFragment(register.Email), Sanitizer.GetSafeHtmlFragment(register.Password), true); response.IsValid = true; SiteUtils.SetBasketAction(resetAction: true); return(JsonSuccess(response, JsonRequestBehavior.AllowGet)); } else { ModelState.AddModelError("Error", "Registration failed!"); return(JsonValidationError()); } } else { ModelState.AddModelError("Error", " '+' Symbol is not allowed in Email!"); return(JsonValidationError()); } }
public ActionResult CreateRequest(CompanyRegisterModel model) { if (!ModelState.IsValid) { return(JsonValidationError()); } if (!string.IsNullOrEmpty(model.Password)) { if (!Regex.IsMatch(model.Password, SiteUtils.GetPasswordRegex())) { ModelState.AddModelError("Password", "Password does not meet policy!"); return(JsonValidationError()); } } model.Mobile = SiteUtils.GenerateEncodedString(model.Mobile); model.Telephone = SiteUtils.GenerateEncodedString(model.Telephone); var user = new CustomerModel { Email = Sanitizer.GetSafeHtmlFragment(model.Email), FirstName = Sanitizer.GetSafeHtmlFragment(model.FirstName), LastName = Sanitizer.GetSafeHtmlFragment(model.LastName), Mobile = model.Mobile, PostCode = Sanitizer.GetSafeHtmlFragment(model.PostCode), Telephone = model.Telephone, Title = Sanitizer.GetSafeHtmlFragment(model.Title), BusinessType = Sanitizer.GetSafeHtmlFragment(model.BusinessType), CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName), RegisteredNumber = Sanitizer.GetSafeHtmlFragment(model.RegisteredNumber), Password = Sanitizer.GetSafeHtmlFragment(model.Password), IsRegistered = true, Address = new CompanyAddress { Address1 = Sanitizer.GetSafeHtmlFragment(model.Address1), Address2 = Sanitizer.GetSafeHtmlFragment(model.Address2), City = Sanitizer.GetSafeHtmlFragment(model.City), State = Sanitizer.GetSafeHtmlFragment(model.State), Country = Sanitizer.GetSafeHtmlFragment(model.Country), PostCode = Sanitizer.GetSafeHtmlFragment(model.PostCode) }, }; user.Mobile = SiteUtils.GenerateDecodeString(user.Mobile); user.Telephone = SiteUtils.GenerateDecodeString(user.Telephone); var result = _customerRepository.Register(user); if (result.Result.IsValid) { return(JsonSuccess(result.Result, JsonRequestBehavior.AllowGet)); } else { ModelState.AddModelError("Error", "Registration Request failed!"); return(JsonValidationError()); } }
public ActionResult ConvertToOrder(CheckoutModel checkout) { if (!string.IsNullOrEmpty(checkout.CompanyId) && _sessionContext.CurrentUser == null && checkout.CompanyId != Guid.Empty.ToString()) { //execute when company user tries to place order via guest checkout. return(JsonSuccess("", JsonRequestBehavior.DenyGet)); } if (checkout.CustomerId == Guid.Empty.ToString() || checkout.CustomerId == null) { var user = new CustomerModel { Email = Sanitizer.GetSafeHtmlFragment(checkout.Email), Password = Sanitizer.GetSafeHtmlFragment(checkout.Password), SourceProcess = SourceProcessType.SITE_CHECKOUTGUEST.ToString() }; var responseTemp = _customerRepository.GetExistingUser(user.Email); if (responseTemp.Result.Count > 0) { checkout.CustomerId = responseTemp.Result[0].UserId.ToString(); } else { var result = _customerRepository.Register(user); if (result.Result.IsValid) { checkout.CustomerId = result.Result.RecordId; } } } checkout.Payment = new PaymentModel { PaymentGatewayId = checkout.SelectedPayment.Id, PaymentGateway = checkout.SelectedPayment.SystemName, OrderAmount = checkout.SelectedPayment.CardInfo.Amount, Status = PaymentStatus.Pending.GetHashCode() }; var response = _checkoutApi.ConvertToOrder(Sanitizer.GetSafeHtmlFragment(checkout.BasketId), checkout); if (response.Result == null) { return(JsonSuccess(response, JsonRequestBehavior.AllowGet)); } //_b2bRepository.RemoveQuoteBasket(); var order = response.Result; var paymentRequest = new ProcessPaymentRequest { BasketId = checkout.BasketId, CurrencyCode = order.CurrencyCode, CustomerId = checkout.CustomerId, LanuguageCode = _sessionContext.CurrentSiteConfig.RegionalSettings.DefaultLanguageCulture, OrderId = order.Id, OrderNo = order.OrderNo, PaymentId = order.Payment.Id, UserEmail = checkout.Email, OrderTotal = order.Payment.OrderAmount, Order = order }; if (!string.IsNullOrEmpty(checkout.SelectedPayment.CardInfo?.CardNo) && !string.IsNullOrEmpty(checkout.SelectedPayment.CardInfo.SecurityCode) && checkout.SelectedPayment.CardInfo.Amount > 0) { paymentRequest.CardNo = checkout.SelectedPayment.CardInfo.CardNo; paymentRequest.Cvv = checkout.SelectedPayment.CardInfo.SecurityCode; paymentRequest.OrderTotal = checkout.SelectedPayment.CardInfo.Amount; } if (checkout.SelectedPayment.SystemName != Convert.ToString(PaymentMethodTypes.AccountCredit)) { var payResponse = _checkoutApi.PaymentSetting(checkout.SelectedPayment.SystemName); checkout.SelectedPayment = payResponse.Result; } var paymentResponse = checkout.SelectedPayment.ProcessPayment(paymentRequest); if (paymentResponse.Success && paymentResponse.AuthorizedAmount > 0) { order.Payment.IsValid = true; order.Payment.Status = PaymentStatus.Authorized.GetHashCode(); order.Payment.OrderAmount = paymentResponse.AuthorizedAmount; order.Payment.AuthCode = paymentResponse.AuthorizationTransactionCode; order.Payment.CardNo = paymentRequest.CardNo; order.Payment.PspResponseCode = paymentRequest.PspSessionCookie; var paymentResult = _checkoutApi.UpdatePayment(order.Id, order.Payment); paymentResponse.BalanceAmount = paymentResult.Result?.BalanceAmount; if (paymentResponse.BalanceAmount.Raw.WithTax == 0) { SiteUtils.ResetBasketCookie(); } } else { order.Payment.IsValid = false; order.Payment.Status = PaymentStatus.Pending.GetHashCode(); order.Payment.AuthCode = paymentResponse.AuthorizationTransactionCode; order.Payment.PspSessionCookie = paymentResponse.PspSessionCookie; var paymentResult = _checkoutApi.UpdatePayment(order.Id, order.Payment); //paymentResponse.RefOrderId = order.Payment.Id; } return(JsonSuccess(paymentResponse, JsonRequestBehavior.AllowGet)); }