/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Customer == null) { throw new ArgumentException("Can't load current customer"); } var result = new CustomerRegistrationResult(); //if (request.Customer.IsSearchEngineAccount()) //{ // result.AddError("Search engine can't be registered"); // return result; //} //if (request.Customer.IsBackgroundTaskAccount()) //{ // result.AddError("Background task account can't be registered"); // return result; //} //if (request.Customer.IsRegistered()) //{ // // result.AddError("Current customer is already registered"); // return result; //} if (string.IsNullOrEmpty(request.Email)) { // result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailIsNotProvided")); return(result); } //if (!CommonHelper.IsValidEmail(request.Email)) //{ // //result.AddError(_localizationService.GetResource("Common.WrongEmail")); // return result; //} if (string.IsNullOrWhiteSpace(request.Password)) { // result.AddError(_localizationService.GetResource("Account.Register.Errors.PasswordIsNotProvided")); return(result); } //if (_customerSettings.UsernamesEnabled) //{ // if (string.IsNullOrEmpty(request.Username)) // { // result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameIsNotProvided")); // return result; // } //} //validate unique user if (_customerService.GetCustomerByEmail(request.Email) != null) { // result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailAlreadyExists")); return(result); } //if (_customerSettings.UsernamesEnabled) //{ // if (_customerService.GetCustomerByUsername(request.Username) != null) // { // result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameAlreadyExists")); // return result; // } //} //at this point request is valid request.Customer.Username = request.Username; request.Customer.Email = request.Email; var customerPassword = new CustomerPassword { Customer = request.Customer, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(SALT_KEY_SIZE); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, ""); } break; } _customerService.InsertCustomerPassword(customerPassword); request.Customer.Active = request.IsApproved; //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered); if (registeredRole == null) { throw new Exception("'Registered' role could not be loaded"); } request.Customer.CustomerRoles.Add(registeredRole); //remove from 'Guests' role var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests); if (guestRole != null) { request.Customer.CustomerRoles.Remove(guestRole); } _customerService.UpdateCustomer(request.Customer); return(result); }
/// <summary> /// Change password /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new ChangePasswordResult(); if (string.IsNullOrWhiteSpace(request.Email)) { result.AddError("EmailIsNotProvided"); return(result); } if (string.IsNullOrWhiteSpace(request.NewPassword)) { result.AddError("PasswordIsNotProvided"); return(result); } var customer = _customerService.GetCustomerByEmail(request.Email); if (customer == null) { result.AddError("EmailNotFound"); return(result); } if (request.ValidateRequest) { //request isn't valid if (!PasswordsMatch(_customerService.GetCurrentPassword(customer.Id), request.OldPassword)) { result.AddError("OldPasswordDoesntMatch"); return(result); } } //check for duplicates if (/*_customerSettings.UnduplicatedPasswordsNumber*/ 0 > 0) { //get some of previous passwords var previousPasswords = _customerService.GetCustomerPasswords(customer.Id, passwordsToReturn: 0); var newPasswordMatchesWithPrevious = previousPasswords.Any(password => PasswordsMatch(password, request.NewPassword)); if (newPasswordMatchesWithPrevious) { result.AddError(""); return(result); } } //at this point request is valid var customerPassword = new CustomerPassword { Customer = customer, PasswordFormat = request.NewPasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.NewPasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.NewPassword; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.NewPassword); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(SALT_KEY_SIZE); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey, ""); } break; } _customerService.InsertCustomerPassword(customerPassword); return(result); }
public CustomerRegistrationServiceTests() { #region customers var customer1 = new Customer { Id = 1, Username = "******", Email = "*****@*****.**", Active = true }; var customer2 = new Customer { Id = 2, Username = "******", Email = "*****@*****.**", Active = true }; var customer3 = new Customer { Id = 3, Username = "******", Email = "*****@*****.**", Active = true }; var customer4 = new Customer { Id = 4, Username = "******", Email = "*****@*****.**", Active = true }; #endregion #region passwords _securitySettings = new SecuritySettings { EncryptionKey = "273ece6f97dd844d" }; _encryptionService = new EncryptionService(_securitySettings); var saltKey = _encryptionService.CreateSaltKey(5); var password = _encryptionService.CreatePasswordHash("password", saltKey, "SHA512"); var password1 = new CustomerPassword { CustomerId = customer1.Id, PasswordFormat = PasswordFormat.Hashed, PasswordSalt = saltKey, Password = password, CreatedOnUtc = DateTime.UtcNow }; var password2 = new CustomerPassword { CustomerId = customer2.Id, PasswordFormat = PasswordFormat.Clear, Password = "******", CreatedOnUtc = DateTime.UtcNow }; var password3 = new CustomerPassword { CustomerId = customer3.Id, PasswordFormat = PasswordFormat.Encrypted, Password = _encryptionService.EncryptText("password"), CreatedOnUtc = DateTime.UtcNow }; var password4 = new CustomerPassword { CustomerId = customer4.Id, PasswordFormat = PasswordFormat.Clear, Password = "******", CreatedOnUtc = DateTime.UtcNow }; #endregion _customerRoleRepo = _fakeDataStore.RegRepository(new[] { new CustomerRole { Id = 1, Active = true, IsSystemRole = true, SystemName = NopCustomerDefaults.RegisteredRoleName } }); _customerRepo = _fakeDataStore.RegRepository(new[] { customer1, customer2, customer3, customer4 }); _customerPasswordRepo = _fakeDataStore.RegRepository(new[] { password1, password2, password3, password4 }); _customerCustomerRoleMappingRepository = _fakeDataStore.RegRepository <CustomerCustomerRoleMapping>(); _customerService = new FakeCustomerService( customerCustomerRoleMappingRepository: _customerCustomerRoleMappingRepository, customerRepository: _customerRepo, customerPasswordRepository: _customerPasswordRepo, customerRoleRepository: _customerRoleRepo); //AddCustomerToRegisteredRole(customer1); //AddCustomerToRegisteredRole(customer2); //AddCustomerToRegisteredRole(customer3); //AddCustomerToRegisteredRole(customer4); _rewardPointsSettings = new RewardPointsSettings { Enabled = false }; _customerSettings = new CustomerSettings { UnduplicatedPasswordsNumber = 1, HashedPasswordFormat = "SHA512" }; _storeService = new Mock <IStoreService>(); _genericAttributeService = new Mock <IGenericAttributeService>(); _newsLetterSubscriptionService = new Mock <INewsLetterSubscriptionService>(); _rewardPointService = new Mock <IRewardPointService>(); _localizationService = new Mock <ILocalizationService>(); _workContext = new Mock <IWorkContext>(); _workflowMessageService = new Mock <IWorkflowMessageService>(); _eventPublisher = new Mock <IEventPublisher>(); _eventPublisher.Setup(x => x.Publish(It.IsAny <object>())); _customerRegistrationService = new CustomerRegistrationService(_customerSettings, _customerService, _encryptionService, _eventPublisher.Object, _genericAttributeService.Object, _localizationService.Object, _newsLetterSubscriptionService.Object, _rewardPointService.Object, _storeService.Object, _workContext.Object, _workflowMessageService.Object, _rewardPointsSettings); }
/// <summary> /// Ctor /// </summary> /// <param name="password">Password</param> public CustomerPasswordChangedEvent(CustomerPassword password) { this.Password = password; }
public IActionResult Create(CustomerModel model, bool continueEditing) { ViewBag.FormName = "User :#" + model.Id; //permissions if (SharedData.isManageUserMenuAccessible == false) { return(AccessDeniedView()); } try { var formData = this.Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); //defult Customer role var customerrole = _customerService.GetAllCustomerRoles().Where(a => a.Name == "Customer").FirstOrDefault(); Customer customer = null; CustomerPassword password = null; if (model.Id == 0) { if (!string.IsNullOrWhiteSpace(model.BillingAddress.Email)) { model.Phone = model.BillingAddress.PhoneNumber; var customerList = _customerService.GetAllCustomers(); var customerData = new Customer(); foreach (var cust in customerList) { var email = _encryptionService.DecryptText(cust.BillingAddress.Email); if (email == model.BillingAddress.Email) { customerData = cust; break; } } if (customerData.BillingAddress != null) { if (model.Id == 0) { AddNotification(NotificationMessage.TitleError, NotificationMessage.Emailisalreadyregistered, NotificationMessage.TypeError); return(RedirectToAction("Create")); } } } } else { customer = _customerService.GetCustomerById(model.Id); AddNotification(NotificationMessage.TitleError, NotificationMessage.UserAlreadyRegistered, NotificationMessage.TypeError); return(RedirectToAction("Index")); } if (ModelState.IsValid) { if (model.Id == 0) { var Baddress = new Address(); Baddress.FirstName = _encryptionService.EncryptText(model.BillingAddress.FirstName); Baddress.LastName = _encryptionService.EncryptText(model.BillingAddress.LastName); Baddress.PhoneNumber = _encryptionService.EncryptText(model.BillingAddress.PhoneNumber); Baddress.StateProvince = _encryptionService.EncryptText(model.BillingAddress.StateProvince); Baddress.ZipPostalCode = _encryptionService.EncryptText(model.BillingAddress.ZipPostalCode); Baddress.Email = _encryptionService.EncryptText(model.BillingAddress.Email); Baddress.City = _encryptionService.EncryptText(model.BillingAddress.City); Baddress.Address1 = _encryptionService.EncryptText(model.BillingAddress.Address1); Baddress.Address2 = _encryptionService.EncryptText(model.BillingAddress.Address2); Baddress.CreatedOnUtc = DateTime.UtcNow; customer = new Customer(); customer.CustomerGuid = Guid.NewGuid(); customer.Email = _encryptionService.EncryptText(model.BillingAddress.Email); customer.Username = _encryptionService.EncryptText(model.BillingAddress.Email); customer.CustomerRoleId = model.CustomerRole.Id; customer.Active = true; customer.CreatedOnUtc = DateTime.UtcNow; customer.LastActivityDateUtc = DateTime.UtcNow; _customerService.InsertCustomer(customer); //customer.CustomerRoles.Add(); customer.Addresses.Add(Baddress); customer.BillingAddress = Baddress; _customerService.UpdateCustomer(customer); // password if (!string.IsNullOrWhiteSpace(model.CustomerPassword.Password)) { password = new CustomerPassword { CustomerId = customer.Id, Password = _encryptionService.EncryptText(model.CustomerPassword.Password), CreatedOnUtc = DateTime.UtcNow, //default passwordFormat PasswordFormat = PasswordFormat.Encrypted }; _customerpasswordservice.InsertCustomerPassword(password); } } AddNotification(NotificationMessage.TitleSuccess, NotificationMessage.msgAddUser, NotificationMessage.TypeSuccess); return(RedirectToAction("Index")); } else { PrepareCustomerDataModel(model); //defult Customer role model.CustomerRoleNames = customerrole.Name; return(View(model)); } } catch (Exception e) { AddNotification(NotificationMessage.TitleError, NotificationMessage.ErrorMsg, NotificationMessage.TypeError); return(RedirectToAction("Create")); } }
/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Errors if something goes wrong</returns> public virtual IEnumerable <string> RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Customer == null) { throw new ArgumentException("Can't load current customer"); } var result = new List <string>(); var validations = new Dictionary <Func <bool>, string>() { { request.Customer.IsSearchEngineAccount, "Customer.RegisterCustomer.SearchEngineAccount.Validation" }, { request.Customer.IsBackgroundTaskAccount, "Customer.RegisterCustomer.BackgroundTask.Validation" }, { () => _customerService.IsRegistered(request.Customer), "Customer.RegisterCustomer.IsRegistered.Validation" }, }; foreach (var validation in validations.Where(validation => validation.Key.Invoke())) { result.Add(_localizationService.GetResource(validation.Value)); return(result); } if (_customerSettings.UsernamesEnabled && string.IsNullOrEmpty(request.Customer?.Username)) { result.Add(_localizationService.GetResource("Account.Register.Errors.UsernameIsNotProvided.Validation")); return(result); } //validate unique user if (_customerService.GetCustomerByEmail(request.Customer?.Email) != null) { result.Add(_localizationService.GetResource("Customer.RegisterCustomer.EmailAlreadyExist.Validation")); return(result); } if (_customerSettings.UsernamesEnabled && _customerService.GetCustomerByUsername(request.Customer.Username) != null) { result.Add(_localizationService.GetResource("Account.Register.Errors.UsernameAlreadyExists.Validation")); return(result); } var customerPassword = new CustomerPassword { CustomerId = request.Customer.Id, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: var saltKey = _encryptionService.CreateSaltKey(NopCustomerServicesDefaults.PasswordSaltKeySize); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat); break; } _customerService.InsertCustomer(request.Customer); _customerService.InsertCustomerPassword(customerPassword); //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.RegisteredRoleName); if (registeredRole == null) { throw new NopException("'Registered' role could not be loaded"); } _customerService.AddCustomerRoleMapping(new CustomerCustomerRoleMapping { CustomerId = request.Customer.Id, CustomerRoleId = registeredRole.Id }); ////remove from 'Guests' role //if (_customerService.IsGuest(request.Customer)) //{ // var guestRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.GuestsRoleName); // _customerService.RemoveCustomerRoleMapping(request.Customer, guestRole); //} return(result); }
public bool UpdateCustomerPassword(CustomerPassword item) { return(customerDAL.UpdateCustomerPassword(item)); }
/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Customer == null) { throw new ArgumentException("Can't load current customer"); } var result = new CustomerRegistrationResult(); if (request.Customer.IsSearchEngineAccount()) { result.AddError("Search engine can't be registered"); return(result); } if (request.Customer.IsBackgroundTaskAccount()) { result.AddError("Background task account can't be registered"); return(result); } if (request.Customer.IsRegistered()) { result.AddError("Current customer is already registered"); return(result); } if (string.IsNullOrEmpty(request.Email)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailIsNotProvided")); return(result); } if (!CommonHelper.IsValidEmail(request.Email)) { result.AddError(_localizationService.GetResource("Common.WrongEmail")); return(result); } if (string.IsNullOrWhiteSpace(request.Password)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.PasswordIsNotProvided")); return(result); } if (_customerSettings.UsernamesEnabled && string.IsNullOrEmpty(request.Username)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameIsNotProvided")); return(result); } //validate unique user if (_customerService.GetCustomerByEmail(request.Email) != null) { result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailAlreadyExists")); return(result); } if (_customerSettings.UsernamesEnabled && _customerService.GetCustomerByUsername(request.Username) != null) { result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameAlreadyExists")); return(result); } //at this point request is valid request.Customer.Username = request.Username; request.Customer.Email = request.Email; var customerPassword = new CustomerPassword { Customer = request.Customer, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: var saltKey = _encryptionService.CreateSaltKey(NopCustomerServiceDefaults.PasswordSaltKeySize); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat); break; } _customerService.InsertCustomerPassword(customerPassword); request.Customer.Active = request.IsApproved; //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.RegisteredRoleName); if (registeredRole == null) { throw new NopException("'Registered' role could not be loaded"); } //request.Customer.CustomerRoles.Add(registeredRole); request.Customer.CustomerCustomerRoleMappings.Add(new CustomerCustomerRoleMapping { CustomerRole = registeredRole }); //remove from 'Guests' role var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == NopCustomerDefaults.GuestsRoleName); if (guestRole != null) { //request.Customer.CustomerRoles.Remove(guestRole); request.Customer.CustomerCustomerRoleMappings .Remove(request.Customer.CustomerCustomerRoleMappings.FirstOrDefault(mapping => mapping.CustomerRoleId == guestRole.Id)); } //add reward points for customer registration (if enabled) if (_rewardPointsSettings.Enabled && _rewardPointsSettings.PointsForRegistration > 0) { var endDate = _rewardPointsSettings.RegistrationPointsValidity > 0 ? (DateTime?)DateTime.UtcNow.AddDays(_rewardPointsSettings.RegistrationPointsValidity.Value) : null; _rewardPointService.AddRewardPointsHistoryEntry(request.Customer, _rewardPointsSettings.PointsForRegistration, request.StoreId, _localizationService.GetResource("RewardPoints.Message.EarnedForRegistration"), endDate: endDate); } _customerService.UpdateCustomer(request.Customer); return(result); }
public ActionResult Register(RegisterModel model) { if (!String.IsNullOrWhiteSpace(model.Username)) { var customer = new CustomerDao().GetCustomerByUserName(model.Username); if (customer != null) { ModelState.AddModelError("", "Username is already registered"); } } if (!String.IsNullOrWhiteSpace(model.Email)) { var customer = new CustomerDao().GetCustomerByEmail(model.Email); if (customer != null) { ModelState.AddModelError("", "Email is already registered"); } } if (ModelState.IsValid) { var customerDao = new CustomerDao(); var encryptedMd5 = OnlineShop.Common.Encryptor.MD5Hash(model.Password); var custommer = new Customer { Email = model.Email, Username = model.Username, FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender, DateOfBirth = model.DateOfBirth, Company = model.Company, CustomerGuid = Guid.NewGuid(), VendorId = 0, Active = true, AdminComment = "", LastIpAddress = PublicIPAddress(), CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow, }; var customerRole = customerDao.GetCustomerRoleById(1); if (customerRole != null) { custommer.CustomerRoles.Add(customerRole); } long id = customerDao.InsertCustomer(custommer); if (id > 0) { var customerPassord = new CustomerPassword { CustomerId = custommer.Id, Password = encryptedMd5, CreatedOnUtc = DateTime.UtcNow }; custommer.CustomerPasswords.Add(customerPassord); customerDao.UpdateCustomer(custommer); SetNotification("Đăng ký người dùng thành công .", "success"); return(RedirectToAction("Login", "User")); } else { ModelState.AddModelError("", "Đăng ký người dùng không thành công ."); } } else { return(View()); } return(RedirectToAction("Register", "User")); }
/// <summary> /// 更改密码 /// </summary> /// <param name="request">请求模型</param> /// <returns>结果</returns> public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new ChangePasswordResult(); if (string.IsNullOrWhiteSpace(request.Email)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.EmailIsNotProvided")); return(result); } if (string.IsNullOrWhiteSpace(request.NewPassword)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.PasswordIsNotProvided")); return(result); } var customer = _customerService.GetCustomerByEmail(request.Email); if (customer == null) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.EmailNotFound")); return(result); } if (request.ValidateRequest) { //验证输入的旧密码与保存的旧密码是否匹配 if (!PasswordsMatch(_customerService.GetCurrentPassword(customer.Id), request.OldPassword)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.OldPasswordDoesntMatch")); return(result); } } //检查重复密码 if (_customerSettings.UnduplicatedPasswordsNumber > 0) { //获取以前的一些密码 var previousPasswords = _customerService.GetCustomerPasswords(customer.Id, passwordsToReturn: _customerSettings.UnduplicatedPasswordsNumber); var newPasswordMatchesWithPrevious = previousPasswords.Any(password => PasswordsMatch(password, request.NewPassword)); if (newPasswordMatchesWithPrevious) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.PasswordMatchesWithPrevious")); return(result); } } var customerPassword = new CustomerPassword { Customer = customer, PasswordFormat = request.NewPasswordFormat }; switch (request.NewPasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.NewPassword; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.NewPassword); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(5); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey, _customerSettings.HashedPasswordFormat); } break; } _customerService.InsertCustomerPassword(customerPassword); _eventPublisher.Publish(new CustomerPasswordChangedEvent(customerPassword)); return(result); }
/// <summary> /// 用户注册 /// </summary> /// <param name="request">请求</param> /// <returns>结果</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.Customer == null) { throw new ArgumentException("无法加载当前客户"); } var result = new CustomerRegistrationResult(); if (request.Customer.IsSearchEngineAccount()) { result.AddError("无法注册搜索引擎"); return(result); } if (request.Customer.IsBackgroundTaskAccount()) { result.AddError("无法注册后台任务帐户"); return(result); } if (request.Customer.IsAdmin()) { result.AddError("当前用户已注册"); return(result); } if (String.IsNullOrEmpty(request.Username)) { result.AddError("Account.Register.Errors.UsernameIsNotProvided"); return(result); } if (String.IsNullOrWhiteSpace(request.Password)) { result.AddError("Password is not provided"); return(result); } //验证用户名唯一性 if (_customerService.GetCustomerByUsername(request.Username) != null) { result.AddError("The specified username already exists"); return(result); } //此时请求有效 request.Customer.Username = request.Username; var customerPassword = new CustomerPassword { Customer = request.Customer, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(5); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, "SHA1"); } break; } _customerService.InsertCustomerPassword(customerPassword); request.Customer.Active = request.IsApproved; //添加'Registered'权限 var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Administrators); if (registeredRole == null) { throw new ExploreException("'Registered' role could not be loaded"); } request.Customer.CustomerRoles.Add(registeredRole); //移除'Guests'权限 var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests); if (guestRole != null) { request.Customer.CustomerRoles.Remove(guestRole); } _customerService.UpdateCustomer(request.Customer); return(result); }
/// <summary> /// Change password /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new ChangePasswordResult(); if (string.IsNullOrWhiteSpace(request.Email)) { result.AddError("Email地址不能为空"); return(result); } if (string.IsNullOrWhiteSpace(request.NewPassword)) { result.AddError("密码不能为空"); return(result); } var customer = _customerService.GetCustomerByEmail(request.Email); if (customer == null) { result.AddError("此Email地址未在系统中注册,无法查询关联客户"); return(result); } if (request.ValidateRequest) { //request isn't valid if (!PasswordsMatch(_customerService.GetCurrentPassword(customer.Id), request.OldPassword)) { result.AddError("旧密码不正确"); return(result); } } //check for duplicates if (_customerSettings.UnduplicatedPasswordsNumber > 0) { //get some of previous passwords var previousPasswords = _customerService.GetCustomerPasswords(customer.Id, passwordsToReturn: _customerSettings.UnduplicatedPasswordsNumber); var newPasswordMatchesWithPrevious = previousPasswords.Any(password => PasswordsMatch(password, request.NewPassword)); if (newPasswordMatchesWithPrevious) { result.AddError("此密码已经使用过了,不能再次使用"); return(result); } } //at this point request is valid var customerPassword = new CustomerPassword { Customer = customer, PasswordFormat = request.NewPasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.NewPasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.NewPassword; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.NewPassword); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(SALT_KEY_SIZE); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey, _customerSettings.HashedPasswordFormat); } break; } _customerService.InsertCustomerPassword(customerPassword); //publish event _eventPublisher.Publish(new CustomerPasswordChangedEvent(customerPassword)); return(result); }
/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Customer == null) { throw new ArgumentException("Can't load current customer"); } var result = new CustomerRegistrationResult(); if (request.Customer.IsSearchEngineAccount()) { result.AddError("Search engine can't be registered"); return(result); } if (request.Customer.IsBackgroundTaskAccount()) { result.AddError("Background task account can't be registered"); return(result); } if (request.Customer.IsRegistered()) { result.AddError("Current customer is already registered"); return(result); } if (string.IsNullOrEmpty(request.Email)) { result.AddError("Email地址不能为空"); return(result); } if (!CommonHelper.IsValidEmail(request.Email)) { result.AddError("无效的Email地址"); return(result); } if (string.IsNullOrWhiteSpace(request.Password)) { result.AddError("密码不能为空"); return(result); } if (string.IsNullOrEmpty(request.Username)) { result.AddError("用户名不能为空"); return(result); } //validate unique user if (_customerService.GetCustomerByEmail(request.Email) != null) { result.AddError("Email地址已经存在"); return(result); } if (_customerService.GetCustomerByUsername(request.Username) != null) { result.AddError("用户名已经存在"); return(result); } if (_customerService.GetCustomerByPhoneNumber(request.PhoneNumber) != null) { result.AddError("手机号码已经存在"); return(result); } //at this point request is valid request.Customer.Username = request.Username; request.Customer.Email = request.Email; var customerPassword = new CustomerPassword { Customer = request.Customer, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(SALT_KEY_SIZE); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat); } break; } _customerService.InsertCustomerPassword(customerPassword); request.Customer.Active = request.IsApproved; //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered); if (registeredRole == null) { throw new GameException("'Registered' role could not be loaded"); } request.Customer.CustomerCustomerRoleMapping.Add(new CustomerCustomerRoleMapping(request.Customer.Id, registeredRole.Id)); //remove from 'Guests' role var guestRole = request.Customer.CustomerCustomerRoleMapping.FirstOrDefault(cr => cr.CustomerRole.SystemName == SystemCustomerRoleNames.Guests); if (guestRole != null) { request.Customer.CustomerCustomerRoleMapping.Remove(guestRole); } _customerService.UpdateCustomer(request.Customer); //publish event _eventPublisher.Publish(new CustomerPasswordChangedEvent(customerPassword)); return(result); }
public void SayHello(Object parameter) { CustomerName = CustomerName.Trim(); CustomerPassword = CustomerPassword.Trim(); MessageBox.Show("Hello " + CustomerName + "xx"); }
public new void SetUp() { _customerSettings = new CustomerSettings { UnduplicatedPasswordsNumber = 1, HashedPasswordFormat = "SHA512" }; _securitySettings = new SecuritySettings { EncryptionKey = "273ece6f97dd844d" }; _rewardPointsSettings = new RewardPointsSettings { Enabled = false, }; _encryptionService = new EncryptionService(_securitySettings); _customerRepo = MockRepository.GenerateMock <IRepository <Customer> >(); var customer1 = new Customer { Id = 1, Username = "******", Email = "*****@*****.**", Active = true }; AddCustomerToRegisteredRole(customer1); var customer2 = new Customer { Id = 2, Username = "******", Email = "*****@*****.**", Active = true }; AddCustomerToRegisteredRole(customer2); var customer3 = new Customer { Id = 3, Username = "******", Email = "*****@*****.**", Active = true }; AddCustomerToRegisteredRole(customer3); var customer4 = new Customer { Id = 4, Username = "******", Email = "*****@*****.**", Active = true }; AddCustomerToRegisteredRole(customer4); var customer5 = new Customer { Id = 5, Username = "******", Email = "*****@*****.**", Active = true }; _customerRepo.Expect(x => x.Table).Return(new List <Customer> { customer1, customer2, customer3, customer4, customer5 }.AsQueryable()); _customerPasswordRepo = MockRepository.GenerateMock <IRepository <CustomerPassword> >(); var saltKey = _encryptionService.CreateSaltKey(5); var password = _encryptionService.CreatePasswordHash("password", saltKey, "SHA512"); var password1 = new CustomerPassword { CustomerId = customer1.Id, PasswordFormat = PasswordFormat.Hashed, PasswordSalt = saltKey, Password = password, CreatedOnUtc = DateTime.UtcNow }; var password2 = new CustomerPassword { CustomerId = customer2.Id, PasswordFormat = PasswordFormat.Clear, Password = "******", CreatedOnUtc = DateTime.UtcNow }; var password3 = new CustomerPassword { CustomerId = customer3.Id, PasswordFormat = PasswordFormat.Encrypted, Password = _encryptionService.EncryptText("password"), CreatedOnUtc = DateTime.UtcNow }; var password4 = new CustomerPassword { CustomerId = customer4.Id, PasswordFormat = PasswordFormat.Clear, Password = "******", CreatedOnUtc = DateTime.UtcNow }; var password5 = new CustomerPassword { CustomerId = customer5.Id, PasswordFormat = PasswordFormat.Clear, Password = "******", CreatedOnUtc = DateTime.UtcNow }; _customerPasswordRepo.Expect(x => x.Table).Return(new[] { password1, password2, password3, password4, password5 }.AsQueryable()); _eventPublisher = MockRepository.GenerateMock <IEventPublisher>(); _eventPublisher.Expect(x => x.Publish(Arg <object> .Is.Anything)); _storeService = MockRepository.GenerateMock <IStoreService>(); _customerCustomerRoleMappingRepo = MockRepository.GenerateMock <IRepository <CustomerCustomerRoleMapping> >(); _customerRoleRepo = MockRepository.GenerateMock <IRepository <CustomerRole> >(); _genericAttributeRepo = MockRepository.GenerateMock <IRepository <GenericAttribute> >(); _orderRepo = MockRepository.GenerateMock <IRepository <Order> >(); _forumPostRepo = MockRepository.GenerateMock <IRepository <ForumPost> >(); _forumTopicRepo = MockRepository.GenerateMock <IRepository <ForumTopic> >(); _genericAttributeService = MockRepository.GenerateMock <IGenericAttributeService>(); _newsLetterSubscriptionService = MockRepository.GenerateMock <INewsLetterSubscriptionService>(); _rewardPointService = MockRepository.GenerateMock <IRewardPointService>(); _localizationService = MockRepository.GenerateMock <ILocalizationService>(); _workContext = MockRepository.GenerateMock <IWorkContext>(); _workflowMessageService = MockRepository.GenerateMock <IWorkflowMessageService>(); _customerService = new CustomerService(new NopNullCache(), _customerRepo, _customerCustomerRoleMappingRepo, _customerPasswordRepo, _customerRoleRepo, _genericAttributeRepo, _orderRepo, _forumPostRepo, _forumTopicRepo, null, null, null, null, null, _genericAttributeService, null, null, _eventPublisher, _customerSettings, null); _customerRegistrationService = new CustomerRegistrationService(_customerService, _encryptionService, _newsLetterSubscriptionService, _localizationService, _storeService, _rewardPointService, _workContext, _genericAttributeService, _workflowMessageService, _eventPublisher, _rewardPointsSettings, _customerSettings); }
/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.Customer == null) { throw new ArgumentException("Can't load current customer"); } var result = new CustomerRegistrationResult(); if (request.Customer.IsSearchEngineAccount()) { result.AddError("Search engine can't be registered"); return(result); } if (request.Customer.IsBackgroundTaskAccount()) { result.AddError("Background task account can't be registered"); return(result); } if (request.Customer.IsRegistered()) { result.AddError("Current customer is already registered"); return(result); } if (String.IsNullOrEmpty(request.Email)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailIsNotProvided")); return(result); } if (!CommonHelper.IsValidEmail(request.Email)) { result.AddError(_localizationService.GetResource("Common.WrongEmail")); return(result); } if (String.IsNullOrWhiteSpace(request.Password)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.PasswordIsNotProvided")); return(result); } if (_customerSettings.UsernamesEnabled) { if (String.IsNullOrEmpty(request.Username)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameIsNotProvided")); return(result); } } //validate unique user if (_customerService.GetCustomerByEmail(request.Email) != null) { result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailAlreadyExists")); return(result); } if (_customerSettings.UsernamesEnabled) { if (_customerService.GetCustomerByUsername(request.Username) != null) { result.AddError(_localizationService.GetResource("Account.Register.Errors.UsernameAlreadyExists")); return(result); } } //at this point request is valid request.Customer.Username = request.Username; request.Customer.Email = request.Email; var customerPassword = new CustomerPassword { Customer = request.Customer, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: { var saltKey = _encryptionService.CreateSaltKey(5); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat); } break; } _customerService.InsertCustomerPassword(customerPassword); request.Customer.Active = request.IsApproved; //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered); if (registeredRole == null) { throw new NopException("'Registered' role could not be loaded"); } request.Customer.CustomerRoles.Add(registeredRole); //add a vendor role if the user category type is Yoga Teacher/Studio/Trainer 08/01/2019 if (request.Customer.VendorId != 0) { var vendorRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Vendors); if (vendorRole != null) { request.Customer.CustomerRoles.Add(vendorRole); } request.Customer.Username = null; } //remove from 'Guests' role var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests); if (guestRole != null) { request.Customer.CustomerRoles.Remove(guestRole); } //Add reward points for customer registration (if enabled) if (_rewardPointsSettings.Enabled && _rewardPointsSettings.PointsForRegistration > 0) { _rewardPointService.AddRewardPointsHistoryEntry(request.Customer, _rewardPointsSettings.PointsForRegistration, request.StoreId, _localizationService.GetResource("RewardPoints.Message.EarnedForRegistration")); } _customerService.UpdateCustomer(request.Customer); //publish event _eventPublisher.Publish(new CustomerPasswordChangedEvent(customerPassword)); return(result); }
/// <summary> /// Register customer /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new CustomerRegistrationResult(); if (string.IsNullOrEmpty(request.Phone)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.EmailIsNotProvided")); return(result); } if (!CommonHelper.IsValidPhone(request.Phone)) { result.AddError(_localizationService.GetResource("Common.WrongEmail")); return(result); } if (string.IsNullOrWhiteSpace(request.Password)) { result.AddError(_localizationService.GetResource("Account.Register.Errors.PasswordIsNotProvided")); return(result); } //validate unique user if (_customerService.GetCustomerByPhone(request.Phone) != null) { result.AddError(_localizationService.GetResource("Account.Register.Errors.PhoneAlreadyExists")); return(result); } _customerService.InsertCustomer(request.Customer); var customerPassword = new CustomerPassword { CustomerId = request.Customer.Id, PasswordFormat = request.PasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.PasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.Password; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.Password); break; case PasswordFormat.Hashed: var saltKey = _encryptionService.CreateSaltKey(BopCustomerServiceDefaults.PasswordSaltKeySize); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey, _customerSettings.HashedPasswordFormat); break; } _customerService.InsertCustomerPassword(customerPassword); //add to 'Registered' role var registeredRole = _customerService.GetCustomerRoleBySystemName(BopCustomerDefaults.RegisteredRoleName); if (registeredRole == null) { throw new BopException("'Registered' role could not be loaded"); } _customerService.AddCustomerRoleMapping(new CustomerCustomerRoleMapping { CustomerId = request.Customer.Id, CustomerRoleId = registeredRole.Id }); return(result); }
/// <summary> /// Change password /// </summary> /// <param name="request">Request</param> /// <returns>Result</returns> public virtual ChangePasswordResult ChangePassword(ChangePasswordRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new ChangePasswordResult(); if (string.IsNullOrWhiteSpace(request.Email)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.EmailIsNotProvided")); return(result); } if (string.IsNullOrWhiteSpace(request.NewPassword)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.PasswordIsNotProvided")); return(result); } var customer = _customerService.GetCustomerByEmail(request.Email); if (customer == null) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.EmailNotFound")); return(result); } //request isn't valid if (request.ValidateRequest && !PasswordsMatch(_customerService.GetCurrentPassword(customer.Id), request.OldPassword)) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.OldPasswordDoesntMatch")); return(result); } //check for duplicates if (_customerSettings.UnduplicatedPasswordsNumber > 0) { //get some of previous passwords var previousPasswords = _customerService.GetCustomerPasswords(customer.Id, passwordsToReturn: _customerSettings.UnduplicatedPasswordsNumber); var newPasswordMatchesWithPrevious = previousPasswords.Any(password => PasswordsMatch(password, request.NewPassword)); if (newPasswordMatchesWithPrevious) { result.AddError(_localizationService.GetResource("Account.ChangePassword.Errors.PasswordMatchesWithPrevious")); return(result); } } //at this point request is valid var customerPassword = new CustomerPassword { Customer = customer, PasswordFormat = request.NewPasswordFormat, CreatedOnUtc = DateTime.UtcNow }; switch (request.NewPasswordFormat) { case PasswordFormat.Clear: customerPassword.Password = request.NewPassword; break; case PasswordFormat.Encrypted: customerPassword.Password = _encryptionService.EncryptText(request.NewPassword); break; case PasswordFormat.Hashed: var saltKey = _encryptionService.CreateSaltKey(NopCustomerServiceDefaults.PasswordSaltKeySize); customerPassword.PasswordSalt = saltKey; customerPassword.Password = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey, _customerSettings.HashedPasswordFormat); break; } _customerService.InsertCustomerPassword(customerPassword); //publish event _eventPublisher.Publish(new CustomerPasswordChangedEvent(customerPassword)); return(result); }
public IActionResult CreateNurse(NurseModel model) {//10/10/2019 aakansha ViewBag.FormName = "Nurse"; if (!(bool)SharedData.isNurseMenuAccessible) { return(AccessDeniedView()); } Customer customer = null; CustomerPassword password = null; if (model.Id == 0) { if (!string.IsNullOrWhiteSpace(model.BillingAddress.Email)) { model.Phone = model.BillingAddress.PhoneNumber; customer = _customerServices.GetCustomerByEmail(model.BillingAddress.Email); if (customer != null) { if (model.Id == 0) { AddNotification(NotificationMessage.TitleError, NotificationMessage.Emailisalreadyregistered, NotificationMessage.TypeError); return(RedirectToAction("Create")); } } } //Address Data var Baddress = new Address(); Baddress.FirstName = _encryptionService.EncryptText(model.BillingAddress.FirstName); Baddress.LastName = _encryptionService.EncryptText(model.BillingAddress.LastName); Baddress.PhoneNumber = _encryptionService.EncryptText(model.BillingAddress.PhoneNumber); Baddress.StateProvince = _encryptionService.EncryptText(model.BillingAddress.StateProvince); Baddress.ZipPostalCode = _encryptionService.EncryptText(model.BillingAddress.ZipPostalCode); Baddress.Email = _encryptionService.EncryptText(model.BillingAddress.Email); Baddress.City = _encryptionService.EncryptText(model.BillingAddress.City); Baddress.Address1 = _encryptionService.EncryptText(model.BillingAddress.Address1); Baddress.Address2 = _encryptionService.EncryptText(model.BillingAddress.Address2); Baddress.CreatedOnUtc = DateTime.UtcNow; //Inser Nurse Data In User Table customer = new Customer(); customer.CustomerGuid = Guid.NewGuid(); customer.Email = _encryptionService.EncryptText(model.BillingAddress.Email); customer.Username = _encryptionService.EncryptText(model.BillingAddress.Email); var nurseRoleData = _customerServices.GetAllCustomerRoles().Where(a => a.Name == "Nurse").FirstOrDefault(); customer.CustomerRoleId = nurseRoleData.Id; customer.Active = true; customer.CreatedOnUtc = DateTime.UtcNow; customer.LastActivityDateUtc = DateTime.UtcNow; _customerServices.InsertCustomer(customer); //customer.CustomerRoles.Add(); customer.Addresses.Add(Baddress); customer.BillingAddress = Baddress; _customerServices.UpdateCustomer(customer); // password if (!string.IsNullOrWhiteSpace(model.CustomerPassword.Password)) { password = new CustomerPassword { CustomerId = customer.Id, Password = model.CustomerPassword.Password, CreatedOnUtc = DateTime.UtcNow, //default passwordFormat PasswordFormat = PasswordFormat.Clear }; _customerpasswordservice.InsertCustomerPassword(password); } //General Data var data = new NurseMaster(); data.Email = _encryptionService.EncryptText(model.BillingAddress.Email); data.UserId = customer.Id; data.FirstName = _encryptionService.EncryptText(model.BillingAddress.FirstName); data.LastName = _encryptionService.EncryptText(model.BillingAddress.LastName); data.CreatedOn = DateTime.UtcNow; data.Deleted = false; _nurseServices.InsertNurse(data); return(Json(data.Id)); } else { var data = _nurseServices.GetNurseById(model.Id); customer = _customerServices.GetCustomerById((int)data.UserId); //Address Data var Baddress = _addressservice.GetAddressById(customer.BillingAddress.Id); Baddress.FirstName = _encryptionService.EncryptText(model.BillingAddress.FirstName); Baddress.LastName = _encryptionService.EncryptText(model.BillingAddress.LastName); Baddress.PhoneNumber = _encryptionService.EncryptText(model.BillingAddress.PhoneNumber); Baddress.StateProvince = _encryptionService.EncryptText(model.BillingAddress.StateProvince); Baddress.ZipPostalCode = _encryptionService.EncryptText(model.BillingAddress.ZipPostalCode); Baddress.Email = _encryptionService.EncryptText(model.BillingAddress.Email); Baddress.City = _encryptionService.EncryptText(model.BillingAddress.City); Baddress.Address1 = _encryptionService.EncryptText(model.BillingAddress.Address1); Baddress.Address2 = _encryptionService.EncryptText(model.BillingAddress.Address2); //Update address _addressservice.UpdateAddress(Baddress); //Inser Nurse Data In User Table customer.CustomerGuid = Guid.NewGuid(); customer.Email = _encryptionService.EncryptText(model.BillingAddress.Email); customer.Username = _encryptionService.EncryptText(model.BillingAddress.Email); var nurseRoleData = _customerServices.GetAllCustomerRoles().Where(a => a.Name == "Nurse").FirstOrDefault(); customer.CustomerRoleId = nurseRoleData.Id; customer.Active = true; customer.CreatedOnUtc = DateTime.UtcNow; customer.LastActivityDateUtc = DateTime.UtcNow; _customerServices.UpdateCustomer(customer); // password if (!string.IsNullOrWhiteSpace(model.CustomerPassword.Password)) { password = _customerpasswordservice.GetPasswordByCustomerId((int)data.UserId); password.Password = model.CustomerPassword.Password; _customerpasswordservice.UpdatePassword(password); } //Genereal Data data.Email = _encryptionService.EncryptText(model.BillingAddress.Email); data.FirstName = _encryptionService.EncryptText(model.BillingAddress.FirstName); data.LastName = _encryptionService.EncryptText(model.BillingAddress.LastName); data.Deleted = false; data.LastUpdated = DateTime.UtcNow; _nurseServices.UpdateNurse(data); return(Json(data.Id)); } }