Changeset 3706 in main


Ignore:
Timestamp:
04/11/12 00:20:19 (10 years ago)
Author:
Garth Braithwaite
Message:

java and view - user profile verification.

Location:
trunk/src/main
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main/java/org/ibisph/user/modelmap/VerifyUserProfile.java

    r3699 r3706  
    11package org.ibisph.user.modelmap;
    22
    3 import java.text.DateFormat;
    43import java.util.Date;
    54import java.util.Map;
    65
    7 import javax.mail.Message;
    8 import javax.mail.internet.InternetAddress;
    9 import javax.mail.internet.MimeMessage;
     6import javax.mail.internet.AddressException;
    107import javax.servlet.http.HttpServletRequest;
    118
     
    1310import org.dom4j.Element;
    1411import org.ibisph.modelmap.ProcessModelMapFromHTTPRequest;
     12import org.ibisph.user.service.EmailVerification;
    1513import org.ibisph.user.service.UserProfileXML;
    1614import org.ibisph.util.StrLib;
    1715import org.ibisph.util.XMLLib;
    1816import org.ibisph.web.servlet.AWTCaptchaServlet;
    19 import org.springframework.mail.MailMessage;
    20 import org.springframework.mail.javamail.JavaMailSender;
    21 import org.springframework.mail.javamail.MimeMessageHelper;
    2217
    2318
     
    3732  protected String userProfileExistsStatusCode     = "USER_PROFILE_EXISTS";
    3833  protected String invalidCaptchaStatusCode        = "INVALID_CAPTCHA";
    39   protected String invalidEmailStatusCode          = "INVALID_EMAIL_ADDRESS";
     34  protected String invalidEmailAddressStatusCode   = "INVALID_EMAIL_ADDRESS";
     35  protected String emailErrorStatusCode            = "EMAIL_ERROR";
    4036  protected String verificationEmailSentStatusCode = "VERIFICATION_EMAIL_SENT";
    41  
    42   protected UserProfileXML userProfileService = null;
    43   protected JavaMailSender mailSender      = null;
    44   protected MailMessage baseMailMessage;
    45   protected String mailMessageFrom = "From";
    46   protected String mailSubject     = "Subject";
    47   protected DateFormat registrationValidationSerialNumberDateFormat = null;
    4837
     38  protected UserProfileXML    userProfileService       = null;
     39  protected EmailVerification emailVerificationService = null;
     40
     41  protected String defaultHTTPRequestVerificationURLPrefix = null;
    4942
    5043
     
    5548    this.userProfileService = userProfileService;
    5649  }
    57   public void setJavaMailSender(JavaMailSender mailSender) {
    58     this.mailSender = mailSender;
    59   }
    60   public void setBaseMailMessage(MailMessage baseMailMessage) {
    61     this.baseMailMessage = baseMailMessage;
     50  public void setEmailVerificationService(EmailVerification emailVerificationService) {
     51    this.emailVerificationService = emailVerificationService;
    6252  }
    6353
     
    7262  public void processModelMap(Map<String, Object>modelMap, HttpServletRequest request) throws Exception {
    7363    Element userProfileElement = (Element)modelMap.get(this.userProfileModelMapKey);
     64
     65    // the xslt parameter can't deal with Element objects - convert to document.
     66    Document userProfileDocument = XMLLib.newDocument(userProfileElement);
     67    modelMap.put(this.userProfileModelMapKey, userProfileDocument);
     68
    7469    String id = XMLLib.getText(userProfileElement, "ID");
    7570
     
    10196    if(!StrLib.isSomething(emailAddress)) {
    10297      logger.error(".processModelMap - MISSING EMAIL ADDRESS, User's IP: {}", request.getRemoteAddr());
    103       setStatusCode(userProfileElement, this.invalidEmailStatusCode);
     98      setStatusCode(userProfileElement, this.invalidEmailAddressStatusCode);
    10499      return;
    105100    }
    106101
    107     String verificationValue = "12345";
     102    String verificationCode = request.getSession().getId();
    108103    try {
    109       MimeMessage mimeMessage = mailSender.createMimeMessage();
    110       mimeMessage.setFrom(new InternetAddress(this.mailMessageFrom));
    111       mimeMessage.setSubject(this.mailSubject);
    112       mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(emailAddress));
    113       mimeMessage.setSentDate(new Date());
    114  
    115       MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
    116       helper.setTo(emailAddress);
    117       helper.setFrom(this.mailMessageFrom);
    118       helper.setText("<html><body>Please respond to this message to activate your account "
    119             + "by clicking on <a href='http://ibis.health.utah.gov/'>Activate Your Account</a></body></html>", true
     104      if(!StrLib.isSomething(defaultHTTPRequestVerificationURLPrefix)) {
     105        String s = request.getRequestURL().toString();
     106        this.defaultHTTPRequestVerificationURLPrefix =
     107          s.substring(0, s.indexOf(request.getServletPath()));
     108      }
     109      request.getRequestURL();
     110      emailVerificationService.sendEmailMessage(
     111        this.defaultHTTPRequestVerificationURLPrefix,
     112        emailAddress,
     113        verificationCode
    120114      );
    121  
    122       this.mailSender.send(mimeMessage);
     115    }
     116    catch(AddressException ae) {
     117      logger.error(".processModelMap - Email Address error, Address: {}", emailAddress);
     118      setStatusCode(userProfileElement, this.invalidEmailAddressStatusCode);
     119      return;
    123120    }
    124121    catch(Exception e) {
    125       logger.error(".processModelMap - Email error.", e);
    126       setStatusCode(userProfileElement, this.invalidEmailStatusCode);
     122      logger.error(".processModelMap - General Email Error. Address: {}", emailAddress, e);
     123      setStatusCode(userProfileElement, this.emailErrorStatusCode);
    127124      return;
    128125    }
    129126
    130127    // if here then all was normal.  set the status code.
    131     Element verificationElement = XMLLib.newElement("VERIFICATION", verificationValue);
     128    Element verificationElement = XMLLib.newElement("VERIFICATION", verificationCode);
    132129    XMLLib.replaceElement(userProfileElement, verificationElement);
    133130    setStatusCode(userProfileElement, this.verificationEmailSentStatusCode);
    134     this.userProfileService.saveUser(XMLLib.newDocument(userProfileElement), id);
     131    this.userProfileService.saveUser(userProfileDocument);
    135132  } //-------------------------- End of Method ------------------------------
    136133
     
    143140  protected void setStatusCode(Element userProfileElement, String statusCode) {
    144141    Element statusCodeElement = XMLLib.newElement("STATUS_CODE", statusCode);
     142    Element dateElement       = XMLLib.newElement("DATE", (new Date()).toString());
    145143    XMLLib.replaceElement(userProfileElement, statusCodeElement);
     144    XMLLib.replaceElement(userProfileElement, dateElement);
    146145  } //-------------------------- End of Method ------------------------------
    147146
  • trunk/src/main/java/org/ibisph/user/service/UserProfileXML.java

    r3535 r3706  
    5757  } //-------------------------- End of Method ------------------------------
    5858
    59   public void saveUser(Document userDocument, String   userName) throws IOException {
    60     XMLLib.setElementText(userDocument.getRootElement(), "NAME", userName);
    61     String filename = getXMLPathAndFilename(userName);
     59  public void saveUser(Document userDocument) throws IOException {
     60    String id = XMLLib.getText(userDocument, "/USER/ID");
     61    String filename = getXMLPathAndFilename(id);
    6262    this.documentDAO.save(userDocument, filename);
    6363  } //-------------------------- End of Method ------------------------------
  • trunk/src/main/java/org/ibisph/util/StrLib.java

    r3535 r3706  
    175175
    176176    int searchFoundAt;
    177     int start = 0, end;  // start search position - so you don't start at the beginning everytime.
     177    int start = 0, end;  // start search position - so you don't start at the beginning every time.
    178178    int lenghtOfSearch  = search.length();
    179179    int lenghtOfReplace = replace.length();
  • trunk/src/main/webapps/ibisph-view/WEB-INF/config/spring/user.xml

    r3699 r3706  
    1313>
    1414
    15 
    16 
    1715        <!--  M O D E L S   /   C O N T R O L L E R   R E S O R U C E S -->
    1816        <bean id="User.UserProfile.ModelMapKey" class="java.lang.String">
     
    3634                <constructor-arg value="Status.xml"/>
    3735        </bean>
    38 
    39         <bean id="User.RegistrationValidationSerialNumber.DateFormat" class="java.text.SimpleDateFormat">
    40                 <constructor-arg value="yyyy-MM-dd-HH-mm-ss-SS"/>
    41                 <constructor-arg type="java.util.Locale" ref="Common.Locale"/>
    42         </bean>
    43 
    4436
    4537        <!-- MAIL NOTES:
     
    128120        </bean>
    129121
    130         <bean id="User.MailMessage" class="org.springframework.mail.SimpleMailMessage">
    131                 <property name="from">
    132                         <value><![CDATA[Simple Application Monitor <noreply@somehost.com>]]></value>
    133                 </property>
    134                 <property name="to">
    135                         <value><![CDATA[System Administrator <sysadmin@somehost.com>]]></value>
    136                 </property>
    137                 <property name="subject" value="SAM Alert"/>
    138         </bean>
    139122
    140123
     
    163146        </bean>
    164147
    165         <bean id="User.NewRegistrationFromHTTPRequest.ModelMap" class="org.ibisph.web.modelmap.HTTPRequestParametersToXML">
     148        <bean id="User.EmailVerification.Service" class="org.ibisph.user.service.EmailVerification">
     149                <property name="javaMailSender"  ref="User.MailSender"/>
     150                <property name="mailMessageFrom" value="user.verification@ibisph.org"/>
     151                <property name="mailSubject"     value="User Account Verification"/>
     152                <property name="mailMessageVerificationRequestURLSearchReplaceSignature" value="[URL_SearchSignature]"/>
     153                <property name="mailMessageHTML">
     154                        <value><![CDATA[
     155                                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     156                                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     157                                <html>
     158                                        <head>
     159                                                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     160                                                <title>Verification Email</title>
     161                                        </head>
     162                                <body>
     163                                                To complete your account registration you must verify your
     164                                                email by clicking on the <a href="[URL_SearchSignature]">
     165                                                Activate Your Account</a> link.
     166                                        </body>
     167                                </html>
     168                        ]]></value>
     169                </property>
     170                <property name="verificationRequestURLPath" value="verify/user/registration"/>
     171        </bean>
     172
     173
     174
     175        <!-- X M L   M O D E L S -->
     176        <bean id="User.DefaultHTMLContent.ModelMap" class="org.ibisph.modelmap.DefaultModelIfNullModel" parent="Common.XMLModelMap.CommonProperties">
     177        </bean>
     178        <bean id="User.HTMLContent.ModelMap" class="org.ibisph.systemid.modelmap.SystemIDFromHTTPRequestEndOfPathInfo" parent="Common.XMLModelMap.CommonProperties">
     179                <property name="XMLPath" ref="User.HTMLContent.XML.Path"/>
     180        </bean>
     181
     182        <bean id="User.UserRegistrationFromHTTPRequest.ModelMap" class="org.ibisph.web.modelmap.HTTPRequestParametersToXML">
    166183                <description>
    167184                        Loads the HTTP Request Parameters into a base USER XML container
     
    173190        </bean>
    174191
    175 
    176         <!-- X M L   M O D E L S -->
    177         <bean id="User.DefaultHTMLContent.ModelMap" class="org.ibisph.modelmap.DefaultModelIfNullModel" parent="Common.XMLModelMap.CommonProperties">
    178         </bean>
    179         <bean id="User.HTMLContent.ModelMap" class="org.ibisph.systemid.modelmap.SystemIDFromHTTPRequestEndOfPathInfo" parent="Common.XMLModelMap.CommonProperties">
    180                 <property name="XMLPath" ref="User.HTMLContent.XML.Path"/>
     192        <bean id="User.VerifyUserRegistration.ModelMap" class="org.ibisph.user.modelmap.VerifyUserProfile">
     193                <property name="userProfileModelMapKey" ref="User.UserProfile.ModelMapKey"/>
     194                <property name="userProfileService"     ref="User.XML.Service"/>
     195                <property name="emailVerificationService" ref="User.EmailVerification.Service"/>
    181196        </bean>
    182197
     
    184199                <property name="model" ref="User.RegistartionStatus.HTMLContent.XML.SystemID"/>
    185200        </bean>
    186 
    187         <bean id="User.UserRegistrationFromHTTPRequest.ModelMap"
    188                 class="org.ibisph.querydefinition.modelmap.QueryDefinitionFromHTTPRequest"
    189         >
    190                 <description>
    191                         Used to get the qd name from the request (param or end of path) and
    192                         loads it from the XML based on the user details.  This is used  by
    193                         the CriteriaBuilder, DefinitionBuilder, and DefinitionResult type
    194                         requests.  A following modelmap call to load this definition to the
    195                         query module.
    196                 </description>
    197                 <property name="queryDefinitionNameHTTPRequestParameterName" ref="QueryDefinition.QueryDefinition.HTTPRequestParameterName"/>
    198                 <property name="queryDefinitionsService" ref="QueryDefinition.XML.Service"/>
    199                 <property name="modelMapKey" ref="QueryDefinition.QueryDefinition.ModelMapKey"/>
    200         </bean>
    201 
    202 <bean id="User.VerifyUserRegistration.ModelMap" class="org.ibisph.user.modelmap.VerifyUserProfile">
    203         <property name="userProfileModelMapKey" ref="User.UserProfile.ModelMapKey"/>
    204         <property name="userProfileService" ref="User.XML.Service"/>
    205         <property name="javaMailSender"     ref="User.MailSender"/>
    206 </bean>
    207201
    208202
     
    261255                <property name="modelMapList">
    262256                        <list>
    263                                 <ref bean="User.NewRegistrationFromHTTPRequest.ModelMap"/>
     257                                <ref bean="User.UserRegistrationFromHTTPRequest.ModelMap"/>
    264258                                <ref bean="User.VerifyUserRegistration.ModelMap"/>
    265259                                <ref bean="User.StatusHTMLContent.ModelMap"/>
     260                                <ref bean="Common.ModifiedDateFromFileSystemID.ModelMap"/>
     261                                <ref bean="Common.WebAppURLContextPrefixFromHTTPRequest.ModelMap"/>
    266262                        </list>
    267263                </property>
     
    269265        </bean>
    270266
    271         <bean id="User.VerifyRegistration.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
    272         </bean>
    273 
    274         <bean id="User.EditProfile.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
    275         </bean>
    276 
    277         <bean id="User.SaveProfile.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
     267<bean id="User.VerifyRegistration.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
     268        </bean>
     269
     270<bean id="User.EditProfile.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
     271        </bean>
     272
     273<bean id="User.SaveProfile.Controller" class="org.ibisph.web.springmvc.ModelMapListProcessingController">
    278274        </bean>
    279275
  • trunk/src/main/webapps/ibisph-view/xml/user/html_content/Registration.xml

    r3699 r3706  
    7676                                        <td><label for="captcha">Captcha Code*</label></td>
    7777                                        <td>
    78                                                 <input type="text" name="captcha" id="captcha" size="30" maxlength="10"/><br/>
    79                                                 <img ibis:src="captcha/code.png" alt="captcha image" title="Captcha - Non Machine Verification."/>
     78                                                <img ibis:src="captcha/code.png" alt="captcha image" title="Captcha - Non Machine Verification."/><br/>
     79                                                <input type="text" name="captcha" id="captcha" size="30" maxlength="10"/>
    8080                                        </td>
    8181                                </tr>
    8282                                <tr>
    8383                                        <td colspan="2">
    84                                                 <input name="submit" type="submit" value=" Submit " class="Button"/>
     84                                                <input name="save"  type="button" value=" Submit " class="Button" onclick="submitRegistration()"/>
    8585                                                &#160;
    86                                                 <input name="clear"  type="reset"  value=" Clear " class="Button"/>
     86                                                <input name="clear" type="reset"  value=" Clear " class="Button"/>
    8787                                        </td>
    8888                                </tr>
  • trunk/src/main/webapps/ibisph-view/xml/user/html_content/Status.xml

    r3699 r3706  
    5252                </ibis:ContiditionalSection>
    5353
     54                <ibis:ContiditionalSection id="EMAIL_ERROR">
     55                        <h2>Email Error</h2>
     56                </ibis:ContiditionalSection>
     57
    5458                <ibis:ContiditionalSection id="VERIFICATION_EMAIL_SENT">
    5559                        <h2>Verification Email Sent</h2>
  • trunk/src/main/webapps/ibisph-view/xslt/html/user/status/Page.xslt

    r3699 r3706  
    2121
    2222
     23        <xsl:template match="HTML_CONTENT/CONTENT//ibis:ContiditionalSection" mode="ibis.copy"
     24                ibis:doc="Provides ability include/exclude certain sections of HTML
     25                        CONTENT.  For this to work, an overriden callback type template
     26                        is used.  This template is passed the section's ID.  The template
     27                        must then determine if the section should be included.  The template
     28                        determines this by XML, the passed in ID, and any other parameters
     29                        that have been passed into the transformer process. 
     30                "
     31        >
     32                <xsl:param name="test">
     33                        <xsl:call-template name="HTMLContent.includeConditionalSection">
     34                                <xsl:with-param name="sectionID" select="@id"/>
     35                        </xsl:call-template>
     36                </xsl:param>
     37USER PROFILE: <xsl:copy-of select="$UserProfile/USER/STATUS_CODE"/>, ID: <xsl:value-of select="@id"/><br/>
     38
     39                <xsl:if test="ibis:isFirstLetter_T_or_Y_or_X($test)">
     40                        <xsl:apply-templates select="(text() | *)" mode="ibis.copy"/>
     41                </xsl:if>
     42        </xsl:template>
     43
    2344        <xsl:template name="HTMLContent.includeConditionalSection"
    2445                ibis:doc="Callback type template that controls if the section should be
     
    3152        >
    3253                <xsl:param name="sectionID"/>
    33                 <xsl:value-of select="boolean($UserProfile/STATUS_CODE = $sectionID)"/>
    34                 <xsl:message select="$UserProfile"/>
     54                <xsl:value-of select="boolean($UserProfile/USER/STATUS_CODE = $sectionID)"/>
    3555        </xsl:template>
    3656
Note: See TracChangeset for help on using the changeset viewer.