shopizer-memoizeit

Customer login fix

12/22/2016 4:44:09 PM

Details

diff --git a/shopizer-canadapost/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-canadapost-module/pom.properties b/shopizer-canadapost/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-canadapost-module/pom.properties
index 3d754ca..00dd120 100644
--- a/shopizer-canadapost/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-canadapost-module/pom.properties
+++ b/shopizer-canadapost/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-canadapost-module/pom.properties
@@ -1,5 +1,5 @@
 #Generated by Maven Integration for Eclipse
-#Wed Dec 21 13:14:22 EST 2016
+#Thu Dec 22 09:09:24 EST 2016
 version=2.0.5-SNAPSHOT
 groupId=com.shopizer
 m2e.projectName=shopizer-canadapost
diff --git a/shopizer-shipping-distance-module/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-distance-processor/pom.properties b/shopizer-shipping-distance-module/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-distance-processor/pom.properties
index 953895d..773018a 100644
--- a/shopizer-shipping-distance-module/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-distance-processor/pom.properties
+++ b/shopizer-shipping-distance-module/target/classes/META-INF/maven/com.shopizer/shopizer-shipping-distance-processor/pom.properties
@@ -1,5 +1,5 @@
 #Generated by Maven Integration for Eclipse
-#Wed Dec 21 13:14:23 EST 2016
+#Thu Dec 22 09:09:26 EST 2016
 version=2.0.5-SNAPSHOT
 groupId=com.shopizer
 m2e.projectName=shopizer-shipping-distance-processor
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/repositories/customer/CustomerRepository.java b/sm-core/src/main/java/com/salesmanager/core/business/repositories/customer/CustomerRepository.java
index 6af00ab..a595b8c 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/repositories/customer/CustomerRepository.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/repositories/customer/CustomerRepository.java
@@ -10,18 +10,18 @@ import com.salesmanager.core.model.customer.Customer;
 public interface CustomerRepository extends JpaRepository<Customer, Long>, CustomerRepositoryCustom {
 
 	
-	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions where c.id = ?1")
+	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions left join fetch c.groups where c.id = ?1")
 	Customer findOne(Long id);
 	
-	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions where c.billing.firstName = ?1")
+	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions left join fetch c.groups  where c.billing.firstName = ?1")
 	List<Customer> findByName(String name);
 	
-	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions where c.nick = ?1")
+	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions left join fetch c.groups  where c.nick = ?1")
 	Customer findByNick(String nick);
 	
-	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions where c.nick = ?1 and cm.id = ?2")
+	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions  left join fetch c.groups  where c.nick = ?1 and cm.id = ?2")
 	Customer findByNick(String nick, int storeId);
 	
-	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions where cm.id = ?1")
+	@Query("select c from Customer c join fetch c.merchantStore cm left join fetch c.defaultLanguage cl left join fetch c.attributes ca left join fetch ca.customerOption cao left join fetch ca.customerOptionValue cav left join fetch cao.descriptions caod left join fetch cav.descriptions  left join fetch c.groups  where cm.id = ?1")
 	List<Customer> findByStore(int storeId);
 }
diff --git a/sm-search/target/classes/META-INF/maven/com.shopizer/sm-search/pom.properties b/sm-search/target/classes/META-INF/maven/com.shopizer/sm-search/pom.properties
index 71976b6..861ba85 100644
--- a/sm-search/target/classes/META-INF/maven/com.shopizer/sm-search/pom.properties
+++ b/sm-search/target/classes/META-INF/maven/com.shopizer/sm-search/pom.properties
@@ -1,5 +1,5 @@
 #Generated by Maven Integration for Eclipse
-#Wed Dec 21 13:14:28 EST 2016
+#Thu Dec 22 09:09:30 EST 2016
 version=2.0.5-SNAPSHOT
 groupId=com.shopizer
 m2e.projectName=sm-search
diff --git a/sm-shop/SALESMANAGER.h2.db b/sm-shop/SALESMANAGER.h2.db
index 155351f..c2aa508 100644
Binary files a/sm-shop/SALESMANAGER.h2.db and b/sm-shop/SALESMANAGER.h2.db differ
diff --git a/sm-shop/SALESMANAGER.lock.db b/sm-shop/SALESMANAGER.lock.db
index 6e1b92e..a747930 100644
--- a/sm-shop/SALESMANAGER.lock.db
+++ b/sm-shop/SALESMANAGER.lock.db
@@ -1,4 +1,4 @@
 #FileLock
-#Wed Dec 21 13:15:26 EST 2016
-id=1592298591ee30815598af25df5c0fccb63b8f5280a
+#Thu Dec 22 13:18:21 EST 2016
+id=15927c159aed307ae4a61a235c2e3a186a7debb7ebd
 method=file
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/customers/CustomerController.java b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/customers/CustomerController.java
index 77ad97d..f2f0f6f 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/customers/CustomerController.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/customers/CustomerController.java
@@ -717,6 +717,112 @@ public class CustomerController {
 		
 	}
 	
+	
+	@PreAuthorize("hasRole('CUSTOMER')")
+	@RequestMapping(value="/admin/customers/setCredentials.html", method=RequestMethod.POST)
+	public @ResponseBody
+	ResponseEntity<String> setCredentials(HttpServletRequest request,HttpServletResponse response) {
+		
+		String customerId = request.getParameter("customerId");
+		String userName = request.getParameter("userName");
+		String password = request.getParameter("password");
+		
+		MerchantStore store = (MerchantStore)request.getAttribute(Constants.ADMIN_STORE);
+		AjaxResponse resp = new AjaxResponse();
+		final HttpHeaders httpHeaders= new HttpHeaders();
+	    httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
+		
+		
+		
+		try {
+			
+			Long id = Long.parseLong(customerId);
+			
+			Customer customer = customerService.getById(id);
+			
+			if(customer==null) {
+				resp.setErrorString("Customer does not exist");
+				resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
+				String returnString = resp.toJSONString();
+				return new ResponseEntity<String>(returnString,httpHeaders,HttpStatus.OK);
+			}
+			
+			if(customer.getMerchantStore().getId().intValue()!=store.getId().intValue()) {
+				resp.setErrorString("Invalid customer id");
+				resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
+				String returnString = resp.toJSONString();
+				return new ResponseEntity<String>(returnString,httpHeaders,HttpStatus.OK);
+			}
+			
+			if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)) {
+				resp.setErrorString("Invalid username or password");
+				resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
+				String returnString = resp.toJSONString();
+				return new ResponseEntity<String>(returnString,httpHeaders,HttpStatus.OK);
+			}
+			
+			Language userLanguage = customer.getDefaultLanguage();
+			
+			Locale customerLocale = LocaleUtils.getLocale(userLanguage);
+
+			String encodedPassword = passwordEncoder.encode(password);
+			
+			customer.setPassword(encodedPassword);
+			customer.setNick(userName);
+			
+			customerService.saveOrUpdate(customer);
+			
+			//send email
+			
+/*			try {
+
+				//creation of a user, send an email
+				String[] storeEmail = {store.getStoreEmailAddress()};
+				
+				
+				Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(request.getContextPath(), store, messages, customerLocale);
+				templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
+		        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
+		        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
+				templateTokens.put(EmailConstants.EMAIL_RESET_PASSWORD_TXT, messages.getMessage("email.customer.resetpassword.text", customerLocale));
+				templateTokens.put(EmailConstants.EMAIL_CONTACT_OWNER, messages.getMessage("email.contactowner", storeEmail, customerLocale));
+				templateTokens.put(EmailConstants.EMAIL_PASSWORD_LABEL, messages.getMessage("label.generic.password",customerLocale));
+				templateTokens.put(EmailConstants.EMAIL_CUSTOMER_PASSWORD, password);
+
+
+				Email email = new Email();
+				email.setFrom(store.getStorename());
+				email.setFromEmail(store.getStoreEmailAddress());
+				email.setSubject(messages.getMessage("label.generic.changepassword",customerLocale));
+				email.setTo(customer.getEmailAddress());
+				email.setTemplateName(RESET_PASSWORD_TPL);
+				email.setTemplateTokens(templateTokens);
+	
+	
+				
+				emailService.sendHtmlEmail(store, email);
+				resp.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
+			
+			} catch (Exception e) {
+				LOGGER.error("Cannot send email to user",e);
+				resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
+			}*/
+			
+			
+			
+			
+		} catch (Exception e) {
+			LOGGER.error("An exception occured while changing password",e);
+			resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
+		}
+		
+		
+		String returnString = resp.toJSONString();
+		return new ResponseEntity<String>(returnString,httpHeaders,HttpStatus.OK);
+		
+		
+	}
+	
 	private void setMenu(Model model, HttpServletRequest request) throws Exception {
 		
 		//display menu
diff --git a/sm-shop/src/main/resources/bundles/messages.properties b/sm-shop/src/main/resources/bundles/messages.properties
index 9886cfa..a0c37a0 100644
--- a/sm-shop/src/main/resources/bundles/messages.properties
+++ b/sm-shop/src/main/resources/bundles/messages.properties
@@ -109,6 +109,7 @@ message.password.invalid=Invalid password
 message.password.length=Password must be at least 6 characters
 message.password.reset=Password has been reset
 message.password.checkpassword.identical=Both password must match
+message.credentials.reset=Credentials have been changed
 
 message.security.caanotremovesuperadmin=Can't remove super admin user
 
diff --git a/sm-shop/src/main/resources/bundles/messages_fr.properties b/sm-shop/src/main/resources/bundles/messages_fr.properties
index 1b3ef4e..37e3583 100644
--- a/sm-shop/src/main/resources/bundles/messages_fr.properties
+++ b/sm-shop/src/main/resources/bundles/messages_fr.properties
@@ -111,6 +111,7 @@ message.password.invalid=Mot de passe invalide
 message.password.length=Le mot de passe doit avoir au moins 6 caractéres
 message.password.reset=Le mot de passe a été ré-initialisé
 message.password.checkpassword.identical=Les deux mots de passe doivent être identiques
+message.credentials.reset=Le données d'authentification ont été changées
 
 message.security.caanotremovesuperadmin=Il n'est pas possible de détruire un usager super admin
 
diff --git a/sm-shop/src/main/resources/bundles/shopizer.properties b/sm-shop/src/main/resources/bundles/shopizer.properties
index 97d5408..e7344cb 100644
--- a/sm-shop/src/main/resources/bundles/shopizer.properties
+++ b/sm-shop/src/main/resources/bundles/shopizer.properties
@@ -665,6 +665,7 @@ button.label.printreport=Print report
 button.label.upload.images=Upload Images
 button.label.upload.files=Upload Files
 button.label.resetpassword=Reset Password
+button.label.setcredentials=Set credentials
 button.label.view=Details
 button.label.addToCart=Add to cart
 button.label.continue=Continue shopping
diff --git a/sm-shop/src/main/resources/bundles/shopizer_fr.properties b/sm-shop/src/main/resources/bundles/shopizer_fr.properties
index da9ee46..d412f81 100644
--- a/sm-shop/src/main/resources/bundles/shopizer_fr.properties
+++ b/sm-shop/src/main/resources/bundles/shopizer_fr.properties
@@ -661,6 +661,7 @@ button.label.subscribe = S'abonner
 button.label.printreport=Imprimer un rapport
 button.label.upload.images=Ajouter des fichiers
 button.label.resetpassword=Ré-initialiser le mot de passe
+button.label.setcredentials=Nom d'usager et mot de passe
 button.label.view=Détails
 button.label.addToCart=Ajouter au panier
 button.label.continue=Continuez votre magasinage
diff --git a/sm-shop/src/main/webapp/pages/admin/customers/customer.jsp b/sm-shop/src/main/webapp/pages/admin/customers/customer.jsp
index b173449..12deeea 100644
--- a/sm-shop/src/main/webapp/pages/admin/customers/customer.jsp
+++ b/sm-shop/src/main/webapp/pages/admin/customers/customer.jsp
@@ -102,11 +102,14 @@ $(document).ready(function() {
 	    
 	    //reset password link
 	    $('a[href="#resetPassword"]').click(function(){
-  			
 	    	var customerId = this.id;
-
 			$('#confirmModal').modal();
-
+		});
+		
+	    //set credentials link
+	    $('a[href="#setCredentials"]').click(function(){
+	    	var customerId = this.id;
+			$('#credentialsModal').modal();
 		});
 	    
 });
@@ -308,6 +311,47 @@ function resetCustomerPassword(customerId){
 }
 
 
+function setCredentials(customerId, userName, password){
+	$('#customerError').hide();
+	$('#customerSuccess').hide();
+	$('#crConfirmationInnerBox').showLoading({
+            'indicatorZIndex' : 1000001,
+            'overlayZIndex': 1000000
+	})
+	$.ajax({
+	  type: 'POST',
+	  url: '<c:url value="/admin/customers/setCredentials.html"/>',
+	  data: 'customerId=' + customerId + '&userName=' + userName + '&password=' + password,
+	  dataType: 'json',
+	  success: function(response){
+		   $('#crConfirmationInnerBox').hideLoading();
+		   $('#confirmModal').modal('hide');
+			var status = isc.XMLTools.selectObjects(response, "/response/status");
+			if(status==0 || status ==9999) {
+				
+				$('#customerSuccess').html('<s:message code="message.credentials.reset" text="Credentials have been changed" />');
+				$('#customerSuccess').show();
+				
+			} else {
+				$('#customerError').html('<s:message code="message.error" text="An error occured" />');
+				$('#customerError').show();
+			}
+
+
+	  
+	  },
+	  error: function(xhr, textStatus, errorThrown) {
+	  	//alert('error ' + errorThrown);
+	  	$('#confirmationInnerBox').hideLoading();
+		$('#confirmModal').modal('hide');
+	  	$('#customerError').html('<s:message code="message.error" text="An error occured" />');
+		$('#customerError').show();
+	  }
+	  
+	});
+}
+
+
 </script>
 
 
@@ -338,7 +382,8 @@ function resetCustomerPassword(customerId){
 				<div class="btn-group" style="z-index:400000;">
                     <button class="btn btn-info dropdown-toggle" data-toggle="dropdown"><s:message code="label.generic.moreoptions" text="More options"/> ... <span class="caret"></span></button>
                      <ul class="dropdown-menu">
-				    	<li><a id="${customer.id}" href="#resetPassword"><s:message code="button.label.resetpassword" text="Reset Password" /></a></li>
+				    	<li><a id="${customer.id}" href="#resetPassword"><s:message code="button.label.resetpassword" text="Reset password" /></a></li>
+				    	<li><a id="${customer.id}" href="#setCredentials"><s:message code="button.label.setcredentials" text="Set credentials" /></a></li>
                      </ul>
                 </div><!-- /btn-group -->
 			    <br/>
@@ -619,4 +664,36 @@ function resetCustomerPassword(customerId){
 </div>
 
 
+<div id="credentialsModal"  class="modal hide" style="z-index:650000" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+  <span id="crConfirmationInnerBox">
+  <div class="modal-header">
+          <button type="button" class="close close-modal" data-dismiss="modal" aria-hidden="true">X</button>
+          <h3 id="modalTitle"><s:message code="button.label.setcredentials" text="Set credentials" /></h3>
+  </div>
+  <div class="modal-body">
+
+           <p id="modalMessage">
+           		    <label>
+           		    	<s:message code="label.generic.username" text="User Name"/>
+           		    </label>&nbsp;<input type="text" id="crUserName" name="crUserName" class="input-small">            		    
+           </p>
+           <p id="modalMessage">
+                    <label>
+           		    	<s:message code="label.generic.password" text="Password"/>
+           		    </label>&nbsp;<input type="text" id="crPassword" name="crPassworde" class="input-small"> 
+           </p>
+  </div>  
+  <div class="modal-footer">
+  
+  		   <button class="btn btn-primary" aria-hidden="true"
+	  		   	onClick="setCredentials( $('#customerId').val(), $('#crUserName').val(), $('#crPassword').val() );" >
+	  		   	<s:message  code="button.label.submit2" text="Submit" />
+	  	   </button>
+  		   	
+  		   	
+           <button class="btn cancel-modal" data-dismiss="modal" aria-hidden="true"><s:message code="button.label.cancel" text="Cancel" /></button>
+           <button class="btn btn-success close-modal" id="closeModal" data-dismiss="modal" aria-hidden="true" style="display:none;"><s:message code="button.label.close" text="Close" /></button>
+  </div>
+  </span>
+</div>
 
diff --git a/sm-shop/target/classes/bundles/messages.properties b/sm-shop/target/classes/bundles/messages.properties
index 9886cfa..a0c37a0 100644
--- a/sm-shop/target/classes/bundles/messages.properties
+++ b/sm-shop/target/classes/bundles/messages.properties
@@ -109,6 +109,7 @@ message.password.invalid=Invalid password
 message.password.length=Password must be at least 6 characters
 message.password.reset=Password has been reset
 message.password.checkpassword.identical=Both password must match
+message.credentials.reset=Credentials have been changed
 
 message.security.caanotremovesuperadmin=Can't remove super admin user
 
diff --git a/sm-shop/target/classes/bundles/messages_fr.properties b/sm-shop/target/classes/bundles/messages_fr.properties
index 1b3ef4e..37e3583 100644
--- a/sm-shop/target/classes/bundles/messages_fr.properties
+++ b/sm-shop/target/classes/bundles/messages_fr.properties
@@ -111,6 +111,7 @@ message.password.invalid=Mot de passe invalide
 message.password.length=Le mot de passe doit avoir au moins 6 caractéres
 message.password.reset=Le mot de passe a été ré-initialisé
 message.password.checkpassword.identical=Les deux mots de passe doivent être identiques
+message.credentials.reset=Le données d'authentification ont été changées
 
 message.security.caanotremovesuperadmin=Il n'est pas possible de détruire un usager super admin
 
diff --git a/sm-shop/target/classes/bundles/shopizer.properties b/sm-shop/target/classes/bundles/shopizer.properties
index 97d5408..e7344cb 100644
--- a/sm-shop/target/classes/bundles/shopizer.properties
+++ b/sm-shop/target/classes/bundles/shopizer.properties
@@ -665,6 +665,7 @@ button.label.printreport=Print report
 button.label.upload.images=Upload Images
 button.label.upload.files=Upload Files
 button.label.resetpassword=Reset Password
+button.label.setcredentials=Set credentials
 button.label.view=Details
 button.label.addToCart=Add to cart
 button.label.continue=Continue shopping
diff --git a/sm-shop/target/classes/bundles/shopizer_fr.properties b/sm-shop/target/classes/bundles/shopizer_fr.properties
index da9ee46..d412f81 100644
--- a/sm-shop/target/classes/bundles/shopizer_fr.properties
+++ b/sm-shop/target/classes/bundles/shopizer_fr.properties
@@ -661,6 +661,7 @@ button.label.subscribe = S'abonner
 button.label.printreport=Imprimer un rapport
 button.label.upload.images=Ajouter des fichiers
 button.label.resetpassword=Ré-initialiser le mot de passe
+button.label.setcredentials=Nom d'usager et mot de passe
 button.label.view=Détails
 button.label.addToCart=Ajouter au panier
 button.label.continue=Continuez votre magasinage
diff --git a/sm-shop/target/m2e-wtp/web-resources/META-INF/maven/com.shopizer/sm-shop/pom.properties b/sm-shop/target/m2e-wtp/web-resources/META-INF/maven/com.shopizer/sm-shop/pom.properties
index bc7b63c..605cc05 100644
--- a/sm-shop/target/m2e-wtp/web-resources/META-INF/maven/com.shopizer/sm-shop/pom.properties
+++ b/sm-shop/target/m2e-wtp/web-resources/META-INF/maven/com.shopizer/sm-shop/pom.properties
@@ -1,5 +1,5 @@
 #Generated by Maven Integration for Eclipse
-#Wed Dec 21 13:14:31 EST 2016
+#Thu Dec 22 12:56:43 EST 2016
 version=2.0.5-SNAPSHOT
 groupId=com.shopizer
 m2e.projectName=sm-shop