From: <ssk...@vh...> - 2005-12-16 18:03:47
|
Author: sskracic Date: 2005-12-16 19:01:03 +0100 (Fri, 16 Dec 2005) New Revision: 1061 Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationResources.properties contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationUtil.java contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/MobifiSMSProvider.java contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/SMSEmailProvider.java contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ui/ConsultationAlertForm.java Log: Another interim commit ... Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationResources.properties =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationResources.properties 2005-12-16 17:21:53 UTC (rev 1060) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationResources.properties 2005-12-16 18:01:03 UTC (rev 1061) @@ -313,6 +313,11 @@ \n\ {3} +sms.pin.subject=PIN +# {0}: PIN for mobile number verification +# {1}: public URL of the server +sms.pin.text=Your PIN is {0}. Used for mob. number verification for {1} + sms.alert.subject=New consultations # {0}: number of newly published consultations # {1}: public URL of the server Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationUtil.java =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationUtil.java 2005-12-16 17:21:53 UTC (rev 1060) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ConsultationUtil.java 2005-12-16 18:01:03 UTC (rev 1061) @@ -18,15 +18,6 @@ */ package com.arsdigita.camden.cms.contenttypes; -import java.math.BigDecimal; -import java.util.Iterator; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.TreeMap; - -import org.apache.log4j.Logger; - import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.form.Option; @@ -36,9 +27,19 @@ import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.Kernel; import com.arsdigita.london.rss.RSS; +import com.arsdigita.mail.Mail; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.SessionManager; import com.arsdigita.web.Application; +import com.arsdigita.web.URL; +import java.math.BigDecimal; +import java.util.Iterator; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.TreeMap; +import javax.mail.MessagingException; +import org.apache.log4j.Logger; /** * Miscellaneous utility methods for the Consultation content type. @@ -49,7 +50,7 @@ public class ConsultationUtil { private static final Logger s_log = - Logger.getLogger(ConsultationUtil.class.getName()); + Logger.getLogger(ConsultationUtil.class); public static final String APPLICATION_X_BINARY = "application/x-binary"; @@ -161,4 +162,23 @@ return m_rssCategoryID; } + + public static void sendPin(String mobileNumber, String pin) { + Locale locale = Locale.getDefault(); + String siteURL = URL.root().getURL(); + String[] args = { pin, siteURL }; + String from = getConfig().getAlertsSenderEmail(); + String smsSubject = (String) globalize("sms.pin.body").localize(locale); + String smsText = (String) globalize("sms.pin.text", args).localize(locale); + String smsEmail = getConfig().getSMSProvider().getEmail(mobileNumber); + try { + s_log.debug("About to send PIN to " + mobileNumber + " using email: " + smsEmail); + Mail.send(smsEmail, from, smsSubject, smsText); + } catch (MessagingException ex) { + s_log.warn("Exception while sending pin to " + + smsEmail + ": " + ex.getMessage()); + } + } + + } Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/MobifiSMSProvider.java =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/MobifiSMSProvider.java 2005-12-16 17:21:53 UTC (rev 1060) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/MobifiSMSProvider.java 2005-12-16 18:01:03 UTC (rev 1061) @@ -1,5 +1,6 @@ package com.arsdigita.camden.cms.contenttypes; +import com.arsdigita.bebop.parameters.ParameterData; import com.arsdigita.util.Assert; public class MobifiSMSProvider implements SMSEmailProvider { @@ -18,5 +19,29 @@ return trimmedNumber + "@sms.mobifi.com"; } + /** + * Performs a mobile number validation for the supplied number. + * Errors, if any, will be attached to the supplied ParameterData object. + * The number will be normalised, ie. will start with +44 + * @param data ParameterData for the mobile number UI widget + */ + public void validateNumber(ParameterData data) { + String number = data.getValue().toString().replaceAll("[^0-9]", ""); + // number is valid if it starts with 447 or 07 or 7 + // First strip the leading country prefix, if exists + number = number.replaceFirst("^44", ""); + // then strip the leading zero + number = number.replaceFirst("^0", ""); + // We now have to have a number starting with 7 to denote UK mobile networks. + // It must be at least (or exactly?) 10 digits in length + // 7789 xxx xxx + if (!number.startsWith("7") || number.length() < 10) { + data.addError((String)ConsultationUtil. + globalize("invalid_mobile").localize()); + } else { + data.setValue("+44" + number); + } + } + } Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/SMSEmailProvider.java =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/SMSEmailProvider.java 2005-12-16 17:21:53 UTC (rev 1060) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/SMSEmailProvider.java 2005-12-16 18:01:03 UTC (rev 1061) @@ -1,11 +1,23 @@ package com.arsdigita.camden.cms.contenttypes; -interface SMSEmailProvider { +import com.arsdigita.bebop.parameters.ParameterData; +public interface SMSEmailProvider { + /** * Provides the email address that will be used as gateway * to the SMS for the supplied mobile number. + * @param mobileNumber mobile number we want to send an SMS to + * @return the email address of a email2SMS gateway for that mobile */ String getEmail(String mobileNumber); + + /** + * Performs a mobile number validation for the supplied number. + * Errors, if any, will be attached to the supplied ParameterData object. + * @param data ParameterData for the mobile number UI widget + */ + void validateNumber(ParameterData data); + } Modified: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ui/ConsultationAlertForm.java =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ui/ConsultationAlertForm.java 2005-12-16 17:21:53 UTC (rev 1060) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/ui/ConsultationAlertForm.java 2005-12-16 18:01:03 UTC (rev 1061) @@ -179,22 +179,7 @@ if (data == null || data.getValue().toString().trim().length() == 0) { return; } - // strip everything but digits - String number = data.getValue().toString().replaceAll("[^0-9]", ""); - // number is valid if it starts with 447 or 07 or 7 - // First strip the leading country prefix, if exists - number = number.replaceFirst("^44", ""); - // then strip the leading zero - number = number.replaceFirst("^0", ""); - // We now have to have a number starting with 7 to denote UK mobile network. - // It must be at least (or exactly?) 10 digits in length - // 7789 xxx xxx - if (!number.startsWith("7") || number.length() < 10) { - data.addError((String)ConsultationUtil. - globalize("invalid_mobile").localize()); - } else { - data.setValue("+44" + number); - } + ConsultationUtil.getConfig().getSMSProvider().validateNumber(data); } }); addField(ConsultationUtil.globalize("mobile"), m_mobile); @@ -282,10 +267,11 @@ if (mobile != null && mobile.trim().length() > 0) { alert.setMobileNumber(mobile); alert.randomizePin(4); + alert.setMobileConfirmed(Boolean.FALSE); alert.save(); m_pinLabel.setVisible(state, true); m_pin.setVisible(state, true); - fireInit(event); + ConsultationUtil.sendPin(mobile, alert.getMobilePin()); return; } else { // clear the mobile number that might have been submitted previously |