<commit_before>package gov.nih.nci.cma.web.ajax;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.json.simple.JSONObject;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;

import gov.nih.nci.caintegrator.application.mail.Mail;
import gov.nih.nci.caintegrator.application.mail.MailProps;
import gov.nih.nci.caintegrator.exceptions.ValidationException;

public class RegHelper {
	
	private static Logger logger = Logger.getLogger(RegHelper.class);

	public static String pReg(String ln, String fn, String em, String in, String ca, String ph, String de)	{
       	//look @ the captcha
		JSONObject jso = new JSONObject();
		String status = "pass";
		String msg = "";
		WebContext webContext = WebContextFactory.get();
		HttpSession session = webContext.getSession();
		
		String k = session.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) != null ? (String) session.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) : null;
		
		if(k!=null && k.equals(ca.trim()))	{

			try	{
	        	//need to clean the generalFeedback field, also put this in the props as a template
	        	MailProps mp = new MailProps();
	        	
	        	//make sure its only 1 email
	        	em = em.replace(",", "").replace(";","");
	        	//send the mail to APP support
	        	/*
	        	String fdbk = fn + " " + ln + " is requesting an account for the CMA Application. \n\n";
	        	fdbk += "Their email is: " + em + " \n";
	        	fdbk += "Their institution is: " + in + " \n";
	        	fdbk += "\n\nThis is an automated email sent from the CMA Application.\n";
	        	*/
	        	String fdbk = System.getProperty("cma.register.template.support");
	        	fdbk = fdbk.replace("{last_name}", (ln!=null)? ln : "None");
	        	fdbk = fdbk.replace("{first_name}", (fn!=null)? fn : "None");
	        	fdbk = fdbk.replace("{email}", (em!=null)? em : "None");
	        	fdbk = fdbk.replace("{phone}", (ph!=null)? ph : "None");
	        	fdbk = fdbk.replace("{department}", (de!=null)? de : "None");
	        	fdbk = fdbk.replace("{institution}", (in!=null)? in : "None");
	        	
	        	mp.setBody(fdbk);
	        	//the fields below should be in a props file
	         	mp.setSmtp(System.getProperty("cma.feedback.mailSMPT"));
	        	mp.setSubject(System.getProperty("cma.register.mailSubject.support"));
	        	mp.setMailTo(System.getProperty("cma.register.mailTo.support"));
	        	mp.setMailFrom(System.getProperty("cma.feedback.mailFrom"));

				// TODO UNCOMMENT!
	    		//Mail.sendMail(mp);
	    		
	    		//send the mail to the user
	    		mp = new MailProps();
	    		fdbk = System.getProperty("cma.register.template.user");
	        	fdbk = fdbk.replace("{last_name}", (ln!=null)? ln : "None");
	        	fdbk = fdbk.replace("{first_name}", (fn!=null)? fn : "None");
	    		/*
	        	fdbk = "Dear " + fn + " " + ln + ",\n Thanks for registering for access to the CMA Application.  You will receive your official account information via email shortly.  Please contact <EMAIL> for further assistance.\n";
	    		fdbk += "\n\nSincerely,\n-The CMA Team";
	    		*/
	    		mp.setBody(fdbk);
	    		mp.setSmtp(System.getProperty("cma.feedback.mailSMPT"));
	        	mp.setSubject(System.getProperty("cma.register.mailSubject.user"));
	        	mp.setMailTo(em.trim());
	        	mp.setMailFrom(System.getProperty("cma.feedback.mailFrom"));

	        	// TODO UNCOMMENT!
	        	//Mail.sendMail(mp);
	    	}
// TODO UNCOMMENT catch below when Mail.sendMail is uncommented!
			
//	    	catch (ValidationException e) {
//System.out.println("In first catch. e = " + e.toString());
//	    		logger.error("mail did not send from regHelper");
//	    		logger.error(e);
//	    		status = "failed";
//	    		msg = "SEND_FAILED";
//	    	}
	    	catch (Exception e) {
	    		logger.error("mail did not send from regHelper");
	    		logger.error(e);
	    		status = "failed";
	    		msg = "SEND_FAILED_GENERIC";
	    	}
		}
		else	{
			status = "fail";
			msg = "BAD_CAPTCHA";
		}
		
		jso.put("status", status);
		jso.put("msg", msg);
		
		if(status.equals("pass"))	{
			// Uncomment the two lines below to enable login after registration (more steps are needed).
			// Should change the login parameters too
			//jso.put("un", "RBTuser");
			//jso.put("ps", "RBTpass");
		}
		
		return jso.toString();
	}
}<commit_msg>Re-enabled the Mail.sendMail()s.<commit_after>package gov.nih.nci.cma.web.ajax;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.json.simple.JSONObject;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;

import gov.nih.nci.caintegrator.application.mail.Mail;
import gov.nih.nci.caintegrator.application.mail.MailProps;
import gov.nih.nci.caintegrator.exceptions.ValidationException;

public class RegHelper {
	
	private static Logger logger = Logger.getLogger(RegHelper.class);

	public static String pReg(String ln, String fn, String em, String in, String ca, String ph, String de)	{
       	//look @ the captcha
		JSONObject jso = new JSONObject();
		String status = "pass";
		String msg = "";
		WebContext webContext = WebContextFactory.get();
		HttpSession session = webContext.getSession();
		
		String k = session.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) != null ? (String) session.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) : null;
		
		if(k!=null && k.equals(ca.trim()))	{

			try	{
	        	//need to clean the generalFeedback field, also put this in the props as a template
	        	MailProps mp = new MailProps();
	        	
	        	//make sure its only 1 email
	        	em = em.replace(",", "").replace(";","");
	        	//send the mail to APP support
	        	/*
	        	String fdbk = fn + " " + ln + " is requesting an account for the CMA Application. \n\n";
	        	fdbk += "Their email is: " + em + " \n";
	        	fdbk += "Their institution is: " + in + " \n";
	        	fdbk += "\n\nThis is an automated email sent from the CMA Application.\n";
	        	*/
	        	String fdbk = System.getProperty("cma.register.template.support");
	        	fdbk = fdbk.replace("{last_name}", (ln!=null)? ln : "None");
	        	fdbk = fdbk.replace("{first_name}", (fn!=null)? fn : "None");
	        	fdbk = fdbk.replace("{email}", (em!=null)? em : "None");
	        	fdbk = fdbk.replace("{phone}", (ph!=null)? ph : "None");
	        	fdbk = fdbk.replace("{department}", (de!=null)? de : "None");
	        	fdbk = fdbk.replace("{institution}", (in!=null)? in : "None");
	        	
	        	mp.setBody(fdbk);
	        	//the fields below should be in a props file
	         	mp.setSmtp(System.getProperty("cma.feedback.mailSMPT"));
	        	mp.setSubject(System.getProperty("cma.register.mailSubject.support"));
	        	mp.setMailTo(System.getProperty("cma.register.mailTo.support"));
	        	mp.setMailFrom(System.getProperty("cma.feedback.mailFrom"));

	    		Mail.sendMail(mp);
	    		
	    		//send the mail to the user
	    		mp = new MailProps();
	    		fdbk = System.getProperty("cma.register.template.user");
	        	fdbk = fdbk.replace("{last_name}", (ln!=null)? ln : "None");
	        	fdbk = fdbk.replace("{first_name}", (fn!=null)? fn : "None");
	    		/*
	        	fdbk = "Dear " + fn + " " + ln + ",\n Thanks for registering for access to the CMA Application.  You will receive your official account information via email shortly.  Please contact <EMAIL> for further assistance.\n";
	    		fdbk += "\n\nSincerely,\n-The CMA Team";
	    		*/
	    		mp.setBody(fdbk);
	    		mp.setSmtp(System.getProperty("cma.feedback.mailSMPT"));
	        	mp.setSubject(System.getProperty("cma.register.mailSubject.user"));
	        	mp.setMailTo(em.trim());
	        	mp.setMailFrom(System.getProperty("cma.feedback.mailFrom"));

	        	Mail.sendMail(mp);
	    	}
			
	    	catch (ValidationException e) {
	    		logger.error("mail did not send from regHelper");
	    		logger.error(e);
	    		status = "failed";
	    		msg = "SEND_FAILED";
	    	}
	    	catch (Exception e) {
	    		logger.error("mail did not send from regHelper");
	    		logger.error(e);
	    		status = "failed";
	    		msg = "SEND_FAILED_GENERIC";
	    	}
		}
		else	{
			status = "fail";
			msg = "BAD_CAPTCHA";
		}
		
		jso.put("status", status);
		jso.put("msg", msg);
		
		if(status.equals("pass"))	{
			// Uncomment the two lines below to enable login after registration (more steps are needed).
			// Should change the login parameters too
			//jso.put("un", "RBTuser");
			//jso.put("ps", "RBTpass");
		}
		
		return jso.toString();
	}
}
{'fraction_non_alphanumeric': 0.14867500286795915, 'fraction_numerical': 0.00045887346564184924, 'mean_word_length': 2.690939881456393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1783115', 'n_tokens_mistral': 3145, 'n_tokens_neox': 2907, 'n_words': 647}