Skip to content

Commit

Permalink
Implemented #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauffin committed Oct 18, 2017
1 parent d4d90f9 commit c3934fd
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 95 deletions.
15 changes: 11 additions & 4 deletions src/Server/Coderr.Server.App/Configuration/BaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace codeRR.Server.App.Configuration
/// </summary>
public sealed class BaseConfiguration : IConfigurationSection
{
/// <summary>
/// allow new users to register accounts.
/// </summary>
/// <remarks>
/// <para>
/// <c>null</c> = not configured = allow.
/// </para>
/// </remarks>
public bool? AllowRegistrations { get; set; }

/// <summary>
/// Base URL for the home page, including protocol (http:// or https://)
/// </summary>
Expand All @@ -24,10 +34,7 @@ public sealed class BaseConfiguration : IConfigurationSection
/// </summary>
public string SupportEmail { get; set; }

string IConfigurationSection.SectionName
{
get { return "BaseConfig"; }
}
string IConfigurationSection.SectionName => "BaseConfig";

IDictionary<string, string> IConfigurationSection.ToDictionary()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,29 @@ public static void AssignProperties(this IConfigurationSection section, IDiction
foreach (var kvp in settings)
{
var property = type.GetProperty(kvp.Key);
if (property.PropertyType == typeof(Uri))
var propertyType = property.PropertyType;
if (propertyType == typeof(Uri))
{
var value = new Uri(kvp.Value);
property.SetValue(section, value);
}
else if (!property.PropertyType.IsAssignableFrom(typeof(string)))
else if (!propertyType.IsAssignableFrom(typeof(string)))
{
var value = Convert.ChangeType(kvp.Value, property.PropertyType);
var realType = Nullable.GetUnderlyingType(propertyType);
if (realType != null)
{
// we got a nullable type and the string represents
// null, so just assign it.
if (string.IsNullOrEmpty(kvp.Value))
{
property.SetValue(section, null);
continue;
}

propertyType = realType;
}

var value = Convert.ChangeType(kvp.Value, propertyType);
property.SetValue(section, value);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public ActionResult Basics()
{
model.BaseUrl = config.BaseUrl.ToString();
model.SupportEmail = config.SupportEmail;
model.AllowRegistrations = config.AllowRegistrations != false;
}
else
{
model.AllowRegistrations = true;
model.BaseUrl = Request.Url.ToString().Replace("installation/setup/basics/", "");
ViewBag.NextLink = "";
}
Expand All @@ -42,7 +44,8 @@ public ActionResult Basics(BasicsViewModel model)
var settings = new BaseConfiguration
{
BaseUrl = new Uri(model.BaseUrl),
SupportEmail = model.SupportEmail
SupportEmail = model.SupportEmail,
AllowRegistrations = model.AllowRegistrations
};
ConfigurationStore.Instance.Store(settings);
return Redirect(Url.GetNextWizardStep());
Expand All @@ -54,9 +57,7 @@ public ActionResult Errors()
var config = ConfigurationStore.Instance.Load<codeRRConfigSection>();
if (config != null)
{
model.ActivateTracking = config.ActivateTracking;
model.ContactEmail = config.ContactEmail;
model.InstallationId = config.InstallationId;
}
else
ViewBag.NextLink = "";
Expand All @@ -72,12 +73,9 @@ public ActionResult Errors(ErrorTrackingViewModel model)

var settings = new codeRRConfigSection
{
ActivateTracking = model.ActivateTracking,
ContactEmail = model.ContactEmail,
InstallationId = model.InstallationId
};
ConfigurationStore.Instance.Store(settings);
WebApiApplication.ReportTocodeRR = model.ActivateTracking;
return Redirect(Url.GetNextWizardStep());
}

Expand Down
11 changes: 11 additions & 0 deletions src/Server/Coderr.Server.Web/Areas/Admin/Models/BasicsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ namespace codeRR.Server.Web.Areas.Admin.Models
{
public class BasicsViewModel
{
/// <summary>
/// URL to coderr (typically "http://yourHostName/" or "http://somehost/coderr/")
/// </summary>
[Required, MinLength(4)]
public string BaseUrl { get; set; }

/// <summary>
/// Email used when codeRR users ask for internal support
/// </summary>
[Required, EmailAddress]
public string SupportEmail { get; set; }

/// <summary>
/// Allow users to register new accounts
/// </summary>
public bool AllowRegistrations { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@ namespace codeRR.Server.Web.Areas.Admin.Models
{
public class ErrorTrackingViewModel
{
[Display(Name = "Activate tracking")]
public bool ActivateTracking { get; set; }

[Display(Name = "Contact email"), EmailAddress]
public string ContactEmail { get; set; }

/// <summary>
/// A fixed identity which identifies this specific installation. You can generate a GUID and then store it.
/// </summary>
/// <remarks>
/// <para>
/// Used to identify the number of installations that have the same issue.
/// </para>
/// </remarks>
public string InstallationId { get; set; }
}
}
68 changes: 38 additions & 30 deletions src/Server/Coderr.Server.Web/Areas/Admin/Views/Home/Basics.cshtml
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
@model codeRR.Server.Web.Areas.Admin.Models.BasicsViewModel
@{
ViewBag.Title = "Admin - Basics";
}
<div class="container">
<div class="col-lg-6">

<h2>Base configuration</h2>
<form method="post" action="@Url.Action("Basics")" style="width: 100%" class="form">
@Html.ValidationSummary(false)
<div class="form-group">
<label class="control-label">
Base URL
</label>
<input type="url"
name="BaseUrl" class="form-control" value="@Model.BaseUrl" placeholder="http://yourhostName"/>
<small>Address used when visiting this site.</small>
</div>
<div class="form-group">
<label for="SupportEmail">
Email address
</label>
<input type="email" id="SupportEmail" name="SupportEmail" class="form-control" value="@Model.SupportEmail"/>
<small>Used by your users when they need support using codeRR, for instance for account troubles. Also used as sender in outbound emails.</small>
</div>
<br/>
<input type="submit" class="btn btn-primary" value="Save"/>
</form>
</div>
</div>
@model codeRR.Server.Web.Areas.Admin.Models.BasicsViewModel
@{
ViewBag.Title = "Admin - Basics";
}
<div class="container">
<div class="col-lg-6">
<h2>Base configuration</h2>
<form method="post" action="@Url.Action("Basics")" style="width: 100%" class="form">
@Html.ValidationSummary(false)
<div class="form-group">
<label class="control-label">
Base URL
</label>
<input type="url"
name="BaseUrl" class="form-control" value="@Model.BaseUrl" placeholder="http://yourhostName" />
<small class="form-text text-muted">Address used when visiting this site.</small>
</div>
<div class="form-group">
<label for="SupportEmail">
Email address
</label>
<input type="email" id="SupportEmail" name="SupportEmail" class="form-control" value="@Model.SupportEmail" />
<small class="form-text text-muted">Used by your users when they need support using codeRR, for instance for account troubles. Also used as sender in outbound emails.</small>
</div>
<div class="form-check">
<label for="AllowRegistrations" class="form-check-label">
<input type="checkbox" id="AllowRegistrations" name="AllowRegistrations" class="form-check-input" value="1" @(@Model.AllowRegistrations ? "checked=\"checked\"" : "") />
Allow registrations
</label>
<br/>
<small class="form-text text-muted">Allow users to create new accounts by using the registration page.</small>
</div>

<br />
<input type="submit" class="btn btn-primary" value="Save" />
</form>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,18 @@

<h2>Error tracking</h2>
<p>
To correct bugs much faster we would like to activate codeRR for your installation. All exceptions
will be uploaded to our own installation for further analysis.
To correct bugs much faster we use codeRR to track errors in codeRR Community Server. All exceptions
are uploaded to our own installation for further analysis.
</p>
<form method="post" action="@Url.Action("Errors")" style="width: 100%" class="form">
@Html.ValidationSummary(false)
<div class="form-group">
@Html.CheckBoxFor(x => x.ActivateTracking, new {@class = "form-control", style = "display:inline;height:auto;width:inherit;"})
@Html.LabelFor(x => x.ActivateTracking, new {@class = "control-label"})
<br/>
<small>Allow us to track errors.</small>
</div>
<div class="form-group disabled suboption">
@Html.LabelFor(x => x.ContactEmail, new {@class = "control-label"})
@Html.TextBoxFor(x => x.ContactEmail, new {@class = "form-control", disabled = ""})
<small>Email address that we may contact if we need any further information (will also receive notifications when your errors have been corrected).</small>
</div>
<div class="form-group disabled suboption">
@Html.LabelFor(x => x.InstallationId, new {@class = "control-label"})
@Html.TextBoxFor(x => x.InstallationId, new {@class = "form-control", disabled = ""})
<small>A fixed identity which identifies this specific installation. You can generate a GUID and then store it. Used to identify the number of installations that have the same issue.</small>
<br/>
<small>A guid generated for your convencience if you want to enable this feature: @Guid.NewGuid().ToString("N")</small>
</div>
<br/>
<input type="submit" class="btn btn-primary" value="Save"/>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", false)
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", false)
</body>
</html>
8 changes: 7 additions & 1 deletion src/Server/Coderr.Server.Web/Content/Site.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.ViewContainer {
.validation-summary-errors ul li {
color: red;
list-style-type: none;
margin-left: 0;
padding-left: 0;
}
.ViewContainer {
width: 100%;
}
.morris-hover {
Expand Down
9 changes: 8 additions & 1 deletion src/Server/Coderr.Server.Web/Content/Site.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.ViewContainer {
.validation-summary-errors ul li{
color: red;
list-style-type: none;
margin-left: 0;
padding-left: 0;
}

.ViewContainer {
width: 100%;
}
.morris-hover {
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Coderr.Server.Web/Content/Site.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/Server/Coderr.Server.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,25 @@ public ActionResult Index()

public ActionResult Login()
{
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
var model = new LoginViewModel
{
AllowRegistrations = config.AllowRegistrations != false
};

var url = ConfigurationManager.AppSettings["LoginUrl"];
if (url != null && url != Request.Url.AbsolutePath)
return Redirect(url);

return View();
return View(model);
}

[HttpPost]
public async Task<ActionResult> Login(LoginViewModel model)
{
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
model.AllowRegistrations = config.AllowRegistrations != false;

if (!ModelState.IsValid)
return View(model);

Expand Down Expand Up @@ -228,6 +237,12 @@ public ActionResult Register()
[HttpPost]
public async Task<ActionResult> Register(RegisterViewModel model)
{
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
if (config.AllowRegistrations == false)
{
ModelState.AddModelError("", "New registrations are not allowed.");
}

if (!ModelState.IsValid)
return View(model);

Expand Down
4 changes: 0 additions & 4 deletions src/Server/Coderr.Server.Web/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace codeRR.Server.Web
public class WebApiApplication : HttpApplication
{
private static readonly ILog _logger;
public static bool ReportTocodeRR;

static WebApiApplication()
{
Expand Down Expand Up @@ -50,9 +49,6 @@ private void Application_Error(object sender, EventArgs e)
}
_logger.Error("Request + " + Request.Url + ", data" + data, exception);

if (!ReportTocodeRR)
return;

var properties = new Dictionary<string, string>
{
{"Url", Request.Url.ToString()},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public override void Log(ExceptionLoggerContext context)
_logger.Error("Request + " + context.Request.RequestUri + ", data" + data, context.Exception);
_logger.Error(context.Exception);

if (!WebApiApplication.ReportTocodeRR)
return;

var properties = new Dictionary<string, string>
{
{"Url", context.Request.RequestUri.ToString()},
Expand Down
5 changes: 5 additions & 0 deletions src/Server/Coderr.Server.Web/Models/Account/LoginViewmodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ public class LoginViewModel

[Required]
public string UserName { get; set; }

/// <summary>
/// Allow new users to register.
/// </summary>
public bool AllowRegistrations { get; set; }
}
}
Loading

0 comments on commit c3934fd

Please sign in to comment.