2010 December, 20 (Guerric)

    Table of contents
    No headers
    // Paste PHP Code
    Index: mindtouch.portal.site/Controllers/RegistrationController.cs
    ===================================================================
    --- mindtouch.portal.site/Controllers/RegistrationController.cs(revision 24301)
    +++ mindtouch.portal.site/Controllers/RegistrationController.cs(working copy)
    @@ -51,6 +51,7 @@
             //--- Constants ---
             protected const string DEFAULT_ADMIN_USERNAME = "Admin";
             protected const string CREATE_SITE_SALT = "5955sjkxzsdjdk18374d";
    +        protected const string DEFAULT_SITE_LICENSE = "tcs-trial";
     
             //--- Class Fields ---
             protected static readonly ILog _log = LogUtils.CreateLog();
    @@ -106,51 +107,14 @@
     
             public ActionResult Trial() {
                 var newSite = new RegistrationModel();
    -            newSite.DefaultDomain = _siteConfig.DefaultDomain;
    +            PopulateRegistrationModel(newSite);
                 return View(newSite);
             }
     
             [HttpPost]
             public ActionResult Trial(RegistrationModel newSite, FormCollection formCollection) {
    -            var errors = false;
    -            if (String.IsNullOrEmpty(newSite.AdminEmail)) {
    -                ModelState.AddModelError("AdminEmail", "Email address cannot be empty");
    -                errors = true;
    -            }
    -            if(!_userBL.IsEmailAvailable(newSite.AdminEmail)) {
    -                ModelState.AddModelError("AdminEmail", "That email address is already in use");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(newSite.AdminFirstName)) {
    -                ModelState.AddModelError("AdminFirstName", "First name cannot be empty");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(newSite.AdminLastName)) {
    -                ModelState.AddModelError("AdminLastName", "Last name cannot be empty");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(newSite.AdminPassword) || !newSite.AdminPassword.EqualsInvariantIgnoreCase(newSite.AdminPasswordConfirm)) {
    -                ModelState.AddModelError("AdminPassword", "Password must not be empty, and must match confirmation");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(newSite.HostName)) {
    -                ModelState.AddModelError("Hostname", "Host name cannot be empty");
    -                errors = true;
    -            }
    -            if (_siteBL.GetHostnameAvailability(GetFullHostName(newSite.HostName)) != HostnameAvailabilityType.AVAILABLE) {
    -                ModelState.AddModelError("Hostname", "That name is not available");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(newSite.SiteTitle)) {
    -                ModelState.AddModelError("SiteTitle", "Site name cannot be empty");
    -                errors = true;
    -            }
    -            if(String.IsNullOrEmpty(formCollection["terms"])) {
    -                ModelState.AddModelError("terms", "You must accept the terms of service before signing up");
    -                errors = true;
    -            }
    -            if(errors) {
    -                newSite.DefaultDomain = _siteConfig.DefaultDomain;
    +            if(ValidateRegistrationModel(newSite)) {
    +                PopulateRegistrationModel(newSite);
                     return View(newSite);
                 }
     
    @@ -169,31 +133,30 @@
             }
             
             [AuthActionFilter]
    -        public ActionResult CreateSite(string hostname, string title, string authcode)
    -        {
    +        public ActionResult CreateSite(string hostname, string title, string authcode) {
                 if(authcode != GetAuthCode(hostname)) {
    +                this.SetMessage(MessageType.Warning, "Your registration code is expired or invalid. Please start over.");
                     return RedirectToAction("Trial");
                 }
                 var user = _authInfo.User;
    -            string password = (string) this.TempData["password"];
    +            string password = (string)this.TempData["password"];
                 
                 // setup the hostname
                 string canonicalHostname = GetFullHostName(hostname);
     
                 // Get default deployment server
                 DeploymentBE deployment = _deploymentBL.FindOpenDeploymentsForVersion(_deploymentConfig.ActiveApiVersion, null, null).First();
    -            var license = _licenseBL.CreateLicense("tcs-trial");
    +            var license = _licenseBL.CreateLicense(DEFAULT_SITE_LICENSE);
                 license.Hosts.Add(canonicalHostname);
                 var siteBE = _siteBL.CreateSite(canonicalHostname, title, SiteAvailabilityType.Public, user, password, license, deployment);
     
                 // send registration email
    -            var email = new WelcomeEmail
    -            {
    +            var email = new WelcomeEmail {
                     FirstName = user.FirstName,
                     UserName = DEFAULT_ADMIN_USERNAME,
                     ExpirationDate = license.Expires.Value.ToString("M"),
                     MindTouchUrl = siteBE.CanonicalHostName.HostName,
    -                PortalUrl = "http://" + _siteConfig.PortalHost
    +                PortalUrl = _requestContext.PortalBaseUri.ToString()
                 };
                 var welcomeConfig = _configurationFactory.GetConfig<TemplatedEmailConfig>("Welcome");
                 var settings = Helpers.Common.GetEmailSettings(welcomeConfig);
    @@ -203,8 +166,9 @@
             
             [AuthActionFilter]
             public ActionResult Confirmation() {
    -            var model = new AccountMasterModel
    -            {
    +
    +            // (guerrics): should have explicit indication on what site is confirmed. not first site.
    +            var model = new AccountMasterModel {
                     CurrentSite = _mapper.BuildSiteModel(_siteBL.FindSitesByOwner(_authInfo.User).First()),
                     CurrentUser = Mapper.Map<UserBE, UserModel>(_authInfo.User)
                 };
    @@ -233,6 +197,51 @@
                 }
                 return this.Json(new { message = message, valid = valid }, JsonRequestBehavior.AllowGet);
             }
    +
    +        private void PopulateRegistrationModel(RegistrationModel model) {
    +            model.DefaultDomain = _siteConfig.DefaultDomain;
    +        }
    +
    +        private bool ValidateRegistrationModel(RegistrationModel newSite) {
    +            var errors = false;
    +            if(String.IsNullOrEmpty(newSite.AdminEmail)) {
    +                ModelState.AddModelError("AdminEmail", "Email address cannot be empty");
    +                errors = true;
    +            }
    +            if(!_userBL.IsEmailAvailable(newSite.AdminEmail)) {
    +                ModelState.AddModelError("AdminEmail", "That email address is already in use");
    +                errors = true;
    +            }
    +            if(string.IsNullOrEmpty(newSite.AdminFirstName)) {
    +                ModelState.AddModelError("AdminFirstName", "First name cannot be empty");
    +                errors = true;
    +            }
    +            if(string.IsNullOrEmpty(newSite.AdminLastName)) {
    +                ModelState.AddModelError("AdminLastName", "Last name cannot be empty");
    +                errors = true;
    +            }
    +            if(string.IsNullOrEmpty(newSite.AdminPassword) || !newSite.AdminPassword.EqualsInvariantIgnoreCase(newSite.AdminPasswordConfirm)) {
    +                ModelState.AddModelError("AdminPassword", "Password must not be empty, and must match confirmation");
    +                errors = true;
    +            }
    +            if(string.IsNullOrEmpty(newSite.HostName)) {
    +                ModelState.AddModelError("Hostname", "Host name cannot be empty");
    +                errors = true;
    +            }
    +            if(_siteBL.GetHostnameAvailability(GetFullHostName(newSite.HostName)) != HostnameAvailabilityType.AVAILABLE) {
    +                ModelState.AddModelError("Hostname", "That name is not available");
    +                errors = true;
    +            }
    +            if(string.IsNullOrEmpty(newSite.SiteTitle)) {
    +                ModelState.AddModelError("SiteTitle", "Site name cannot be empty");
    +                errors = true;
    +            }
    +            if(!newSite.AcceptTerms) {
    +                ModelState.AddModelError("AcceptTerms", "You must accept the terms of service before signing up");
    +                errors = true;
    +            }
    +            return errors;
    +        }
             
             private string GetAuthCode(string hostname) {
                 return StringUtil.ComputeHashString(hostname + CREATE_SITE_SALT);
    Index: mindtouch.portal.site/Models/RegistrationModel.cs
    ===================================================================
    --- mindtouch.portal.site/Models/RegistrationModel.cs(revision 24301)
    +++ mindtouch.portal.site/Models/RegistrationModel.cs(working copy)
    @@ -56,6 +56,9 @@
             public string AdminPassword { get; set; }
             public string AdminPasswordConfirm { get; set; }
     
    +        // terms of service
    +        public bool AcceptTerms { get; set; }
    +
             // metadata
             public string DefaultDomain { get; set; }
     
    @@ -85,7 +88,8 @@
                         list.Add(new KeyValuePair<string, string>(item[0], item[1]));
                     }
                     return list;
    -        }}
    +            }
    +        }
             public List<KeyValuePair<string, string>> RegistrarCount {
                 get {
                     string[][] items = {
    Index: mindtouch.portal.site/Views/Registration/Trial.aspx
    ===================================================================
    --- mindtouch.portal.site/Views/Registration/Trial.aspx(revision 24301)
    +++ mindtouch.portal.site/Views/Registration/Trial.aspx(working copy)
    @@ -1,7 +1,17 @@
    -<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Registration.Master" Inherits="System.Web.Mvc.ViewPage<MindTouch.Portal.Site.Models.RegistrationModel>" %>
    +<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Registration.Master" Inherits="System.Web.Mvc.ViewPage<MindTouch.Portal.Site.Models.RegistrationModel>" %>
     
    -<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    -Trial
    +<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    +    <script type="text/javascript" src="<%= Url.Content("~/Content/Scripts/registration.js") %>"></script>
    +    <script type="text/javascript">
    +        $(function() {
    +            $('form').validate({
    +                rules: {
    +                    AdminPassword: { required: true },
    +                    AdminPasswordConfirm: { required: true, equalTo: "#AdminPassword" }
    +                }
    +            });
    +        });
    +    </script>
     </asp:Content>
     
     <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    @@ -12,139 +22,126 @@
             <div class="subtitle-arrow"></div>
         </div>
         
    -    <% using (Html.BeginForm()) {%>
    -    <%=Html.ValidationSummary(true) %>
    -    <%=Html.ValidationMessage("Site") %>
    -      
    -    <fieldset id="form-site-setup"> 
    -<h2 class="first"><div class="setup-step">1</div>Site Info</h2>
    -<div class="table">
    -<div class="field">
    -    <label for="SiteTitle" class="label-text-Sitename">Site name</label>
    -    <div class="input-wrap">
    -        <%= Html.TextBoxFor(model => model.SiteTitle, new {@class="input-text required"}) %>
    -        <%= Html.ValidationMessage("SiteTitle") %>
    -        <div class="description">Enter your company or project name here.</div>
    +    <% Html.BeginForm(); %>
    +        <%=Html.ValidationSummary(true) %>
    +        <%=Html.ValidationMessage("Site") %>
    +          
    +        <fieldset id="form-site-setup"> 
    +    <h2 class="first"><div class="setup-step">1</div>Site Info</h2>
    +    <div class="table">
    +    <div class="field">
    +        <label for="SiteTitle" class="label-text-Sitename">Site name</label>
    +        <div class="input-wrap">
    +            <%= Html.TextBoxFor(model => model.SiteTitle, new {@class="input-text required"}) %>
    +            <%= Html.ValidationMessage("SiteTitle") %>
    +            <div class="description">Enter your company or project name here.</div>
    +        </div>
         </div>
    -</div>
    -
    -<div class="field">
    -    <label for="hostname" class="label-text-url">Choose your URL</label>
    -    <div class="input-wrap">
    -        https:// <%=Html.TextBoxFor(model => model.HostName, new {@class="input-text required"}) %>.<%= Model.DefaultDomain %>
    -        <%= Html.ValidationMessage("Hostname") %>
    -        <div id="hostname-status"></div>
    +    
    +    <div class="field">
    +        <label for="hostname" class="label-text-url">Choose your URL</label>
    +        <div class="input-wrap">
    +            https:// <%=Html.TextBoxFor(model => model.HostName, new {@class="input-text required"}) %>.<%= Model.DefaultDomain %>
    +            <%= Html.ValidationMessage("Hostname") %>
    +            <div id="hostname-status"></div>
    +        </div>
         </div>
    -</div>
    -    </div>
    -
    -<h2><div class="setup-step">2</div>Admin Info</h2>
    -<div class="table">
    -<div class="field">
    -    <label for="AdminEmail">Admin e-mail</label>
    -    <div class="input-wrap">
    -        <%= Html.TextBoxFor(model => model.AdminEmail, new { @class = "input-text required email" })%>
    -        <%= Html.ValidationMessage("AdminEmail") %>
    -        <div class="description">An email will be sent to this address with info on accessing your account.</div>
    +        </div>
    +    
    +    <h2><div class="setup-step">2</div>Admin Info</h2>
    +    <div class="table">
    +    <div class="field">
    +        <label for="AdminEmail">Admin e-mail</label>
    +        <div class="input-wrap">
    +            <%= Html.TextBoxFor(model => model.AdminEmail, new { @class = "input-text required email" })%>
    +            <%= Html.ValidationMessage("AdminEmail") %>
    +            <div class="description">An email will be sent to this address with info on accessing your account.</div>
    +        </div>
         </div>
    -</div>
    -
    -<div class="field">
    -    <label for="AdminFirstName">First name</label>
    -    <div class="input-wrap">
    -        <%= Html.TextBoxFor(model => model.AdminFirstName, new {@class="input-text required"})%>
    -        <%= Html.ValidationMessage("AdminFirstName")%>
    +    
    +    <div class="field">
    +        <label for="AdminFirstName">First name</label>
    +        <div class="input-wrap">
    +            <%= Html.TextBoxFor(model => model.AdminFirstName, new {@class="input-text required"})%>
    +            <%= Html.ValidationMessage("AdminFirstName")%>
    +        </div>
         </div>
    -</div>
    -
    -<div class="field">
    -        <label for="AdminLastName">Last name</label>
    -        <div class="input-wrap">
    -        <%= Html.TextBoxFor(model => model.AdminLastName, new {@class="input-text required"})%>
    -        <%= Html.ValidationMessage("AdminLastName")%>
    +    
    +    <div class="field">
    +            <label for="AdminLastName">Last name</label>
    +            <div class="input-wrap">
    +            <%= Html.TextBoxFor(model => model.AdminLastName, new {@class="input-text required"})%>
    +            <%= Html.ValidationMessage("AdminLastName")%>
    +        </div>
         </div>
    -</div>
    -<div class="field">
    -    <label for="AdminPassword">Password</label>
    -    <div class="input-wrap">
    -    <%= Html.PasswordFor(model => Model.AdminPassword, new { @class = "input-text required" })%>
    -    <%= Html.ValidationMessage("AdminPassword")%>
    +    <div class="field">
    +        <label for="AdminPassword">Password</label>
    +        <div class="input-wrap">
    +        <%= Html.PasswordFor(model => Model.AdminPassword, new { @class = "input-text required" })%>
    +        <%= Html.ValidationMessage("AdminPassword")%>
    +        </div>
         </div>
    -</div>
    -<div class="field">
    -    <label for="AdminPasswordConfirm">Password confirm</label>
    -    <div class="input-wrap">
    -        <%= Html.PasswordFor(model => Model.AdminPasswordConfirm, new {@class="input-text required"}) %>
    -        <%= Html.ValidationMessage("AdminPasswordConfirm") %>
    +    <div class="field">
    +        <label for="AdminPasswordConfirm">Password confirm</label>
    +        <div class="input-wrap">
    +            <%= Html.PasswordFor(model => Model.AdminPasswordConfirm, new {@class="input-text required"}) %>
    +            <%= Html.ValidationMessage("AdminPasswordConfirm") %>
    +        </div>
         </div>
    -</div>
    -</div>
    -
    -<h2><div class="setup-step">3</div>Tell us a little about you.</h2> 
    -<div class="table registration-survey">
    -<div class="field">
    -    <label for="select-RegistrarCount" class="label-select-RegistrarCount">Number of people in your organization</label>
    -    <div class="input-wrap">
    -        <select name="RegistrarCount"  class="input-select" id="select-RegistrarCount">
    -        <% for(int i = 0; i < Model.RegistrarCount.Count; i++) {
    -                        var item = Model.RegistrarCount[i];              %>
    -                <option value="<%= item.Key %>" <%= i == 0 ? "selected=\"selected\"" : "" %>><%= item.Value %></option> 
    -        <% } %>
    -        </select>
    +    </div>
    +    
    +    <h2><div class="setup-step">3</div>Tell us a little about you.</h2> 
    +    <div class="table registration-survey">
    +    <div class="field">
    +        <label for="select-RegistrarCount" class="label-select-RegistrarCount">Number of people in your organization</label>
    +        <div class="input-wrap">
    +            <select name="RegistrarCount"  class="input-select" id="select-RegistrarCount">
    +            <% for(int i = 0; i < Model.RegistrarCount.Count; i++) {
    +                            var item = Model.RegistrarCount[i];              %>
    +                    <option value="<%= item.Key %>" <%= i == 0 ? "selected=\"selected\"" : "" %>><%= item.Value %></option> 
    +            <% } %>
    +            </select>
    +        </div>
         </div>
    -</div>
    -<div class="field">
    -    <label for="select-RegistrarDept" class="label-select-RegistrarDept">Your Department</label>
    -    <div class="input-wrap">
    -        <select name="RegistrarDept"  class="input-select" id="select-RegistrarDept">
    -        <% for(int i = 0; i < Model.RegistrarDepartment.Count; i++) {
    -                        var item = Model.RegistrarDepartment[i];              %>
    -                <option value="<%= item.Key %>" <%= i == 0 ? "selected=\"selected\"" : "" %>><%= item.Value %></option> 
    -        <% } %>
    -        </select>
    -    </div>
    - </div>
    -</div>
    -
    -<div class="table registration-usage"> 
    -<label class="label-select-RegistrarUsage">How will you use MindTouch? Check all that apply:</label>
    -        <ul class="usagelist">
    -        <% foreach(var item in Model.RegistrarUsage) { %>
    -            <li>
    -                <input type="checkbox" value="<%= item.Key %>" name="RegistrarUsage[<%= item.Key %>]" class="input-checkbox" id="checkbox-RegistrarUsage[<%= item.Key %>]" />
    -                <label for="checkbox-RegistrarUsage[<%= item.Key %>]" class="label-checkbox-RegistrarUsage[<%= item.Key %>]"><%= item.Value%></label>   
    -            </li>
    -        <% } %>
    -        </ul>
    -</div>
    -
    -<div class="table mindtouch-terms">
    -    <%= Html.ValidationMessage("terms") %>
    -    <label for="terms">
    -        <%/* TODO: final link to terms (http://youtrack.developer.mindtouch.com/issue/CL-178) */ %>
    -            <input id="terms" type="checkbox" value="1" name="terms" class="required" /> I have read and agree to the <a href="/" target="_blank">Terms of Use</a> for MindTouch
    -        </label>
    -    </div>
    -    
    -    <div class="navButtons"> 
    -<div> 
    -<input type="submit" value="Start MindTouch Trial" class="submit_form"> 
    -</div> 
    -</div>
    -</fieldset>
    -<% } %>
    +    <div class="field">
    +        <label for="select-RegistrarDept" class="label-select-RegistrarDept">Your Department</label>
    +        <div class="input-wrap">
    +            <select name="RegistrarDept"  class="input-select" id="select-RegistrarDept">
    +            <% for(int i = 0; i < Model.RegistrarDepartment.Count; i++) {
    +                            var item = Model.RegistrarDepartment[i];              %>
    +                    <option value="<%= item.Key %>" <%= i == 0 ? "selected=\"selected\"" : "" %>><%= item.Value %></option> 
    +            <% } %>
    +            </select>
    +        </div>
    +     </div>
    +    </div>
    +    
    +    <div class="table registration-usage"> 
    +    <label class="label-select-RegistrarUsage">How will you use MindTouch? Check all that apply:</label>
    +            <ul class="usagelist">
    +            <% foreach(var item in Model.RegistrarUsage) { %>
    +                <li>
    +                    <input type="checkbox" value="<%= item.Key %>" name="RegistrarUsage[<%= item.Key %>]" class="input-checkbox" id="checkbox-RegistrarUsage[<%= item.Key %>]" />
    +                    <label for="checkbox-RegistrarUsage[<%= item.Key %>]" class="label-checkbox-RegistrarUsage[<%= item.Key %>]"><%= item.Value%></label>   
    +                </li>
    +            <% } %>
    +            </ul>
    +    </div>
    +    
    +    <div class="table mindtouch-terms">
    +        <%= Html.ValidationMessage("AcceptTerms") %>
    +        <label for="terms">
    +            <%/* TODO: final link to terms (http://youtrack.developer.mindtouch.com/issue/CL-178) */ %>
    +            <%= Html.CheckBoxFor(model => model.AcceptTerms, new { @id = "terms", @class = "required" }) %>
    +                I have read and agree to the <a href="/" target="_blank">Terms of Use</a> for MindTouch
    +            </label>
    +        </div>
    +        
    +        <div class="navButtons"> 
    +    <div> 
    +    <input type="submit" value="Start MindTouch Trial" class="submit_form"> 
    +    </div> 
    +    </div>
    +    </fieldset>
    +<% Html.EndForm(); %>
     </asp:Content>
    -
    -<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    -    <script type="text/javascript" src="<%= Url.Content("~/Content/Scripts/registration.js") %>"></script>
    -    <script type="text/javascript">
    -        $(function() {
    -            $('form').validate({
    -                rules: {
    -                    AdminPassword: { required: true },
    -                    AdminPasswordConfirm: { required: true, equalTo: "#AdminPassword" }
    -                }
    -            });
    -        });
    -    </script>
    -</asp:Content>
    Index: mindtouch.portal.site/Views/Shared/Registration.Master
    ===================================================================
    --- mindtouch.portal.site/Views/Shared/Registration.Master(revision 24301)
    +++ mindtouch.portal.site/Views/Shared/Registration.Master(working copy)
    @@ -2,8 +2,35 @@
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
    -<head id="Head1" runat="server">
    -    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    +<head id="HtmlHead" runat="server">
    +    <asp:ContentPlaceHolder ID="HtmlTitle" runat="server">
    +        <title> <%
    +            string masterTitle = "MindTouch Cloud";
    +            if (string.IsNullOrEmpty(this.Page.Title)) {
    +                
    +                // autogenerate a title
    +                string controller = Url.RequestContext.RouteData.GetRequiredString("Controller");
    +                switch (controller) {
    +                case "Account":
    +                    break;
    +                default:
    +                    masterTitle += " - " + controller;
    +                    break;
    +                }
    +                string action = Url.RequestContext.RouteData.GetRequiredString("Action");
    +                switch (action) {
    +                case "Index":
    +                    break;
    +                default:
    +                    masterTitle += " - " + action;
    +                    break;
    +                }
    +            } else {
    +                masterTitle += " - " + this.Page.Title;
    +            }
    +            Response.Write(Html.Encode(masterTitle));
    +        %> </title>
    +    </asp:ContentPlaceHolder>
         <link rel="stylesheet" type="text/css" media="screen" href="<%= Url.Content("~/Content/Redist/reset-min.css") %>" />
     <link media="all" type="text/css" rel="stylesheet" href="<%= Url.Content("~/Content/account.master.css") %>" />
         <link rel="stylesheet" type="text/css" media="screen" href="<%= Url.Content("~/Content/registration.css") %>" />
    Index: tests/mindtouch.portal.data.mock/Logic/MockUserBL.cs
    ===================================================================
    --- tests/mindtouch.portal.data.mock/Logic/MockUserBL.cs(revision 24301)
    +++ tests/mindtouch.portal.data.mock/Logic/MockUserBL.cs(working copy)
    @@ -98,7 +98,7 @@
             }
     
             public bool IsEmailAvailable(string email) {
    -            throw new NotImplementedException();
    +            return (email ?? "").Length % 2 == 0;
             }
         }
     }
    \ No newline at end of file
     
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by