Skip to content

Commit c3934fd

Browse files
committed
Implemented #5
1 parent d4d90f9 commit c3934fd

File tree

19 files changed

+137
-95
lines changed

19 files changed

+137
-95
lines changed

src/Server/Coderr.Server.App/Configuration/BaseConfiguration.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ namespace codeRR.Server.App.Configuration
99
/// </summary>
1010
public sealed class BaseConfiguration : IConfigurationSection
1111
{
12+
/// <summary>
13+
/// allow new users to register accounts.
14+
/// </summary>
15+
/// <remarks>
16+
/// <para>
17+
/// <c>null</c> = not configured = allow.
18+
/// </para>
19+
/// </remarks>
20+
public bool? AllowRegistrations { get; set; }
21+
1222
/// <summary>
1323
/// Base URL for the home page, including protocol (http:// or https://)
1424
/// </summary>
@@ -24,10 +34,7 @@ public sealed class BaseConfiguration : IConfigurationSection
2434
/// </summary>
2535
public string SupportEmail { get; set; }
2636

27-
string IConfigurationSection.SectionName
28-
{
29-
get { return "BaseConfig"; }
30-
}
37+
string IConfigurationSection.SectionName => "BaseConfig";
3138

3239
IDictionary<string, string> IConfigurationSection.ToDictionary()
3340
{

src/Server/Coderr.Server.Infrastructure/Configuration/ConfigurationCategoryExtensions.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,29 @@ public static void AssignProperties(this IConfigurationSection section, IDiction
2323
foreach (var kvp in settings)
2424
{
2525
var property = type.GetProperty(kvp.Key);
26-
if (property.PropertyType == typeof(Uri))
26+
var propertyType = property.PropertyType;
27+
if (propertyType == typeof(Uri))
2728
{
2829
var value = new Uri(kvp.Value);
2930
property.SetValue(section, value);
3031
}
31-
else if (!property.PropertyType.IsAssignableFrom(typeof(string)))
32+
else if (!propertyType.IsAssignableFrom(typeof(string)))
3233
{
33-
var value = Convert.ChangeType(kvp.Value, property.PropertyType);
34+
var realType = Nullable.GetUnderlyingType(propertyType);
35+
if (realType != null)
36+
{
37+
// we got a nullable type and the string represents
38+
// null, so just assign it.
39+
if (string.IsNullOrEmpty(kvp.Value))
40+
{
41+
property.SetValue(section, null);
42+
continue;
43+
}
44+
45+
propertyType = realType;
46+
}
47+
48+
var value = Convert.ChangeType(kvp.Value, propertyType);
3449
property.SetValue(section, value);
3550
}
3651
else

src/Server/Coderr.Server.Web/Areas/Admin/Controllers/HomeController.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public ActionResult Basics()
2525
{
2626
model.BaseUrl = config.BaseUrl.ToString();
2727
model.SupportEmail = config.SupportEmail;
28+
model.AllowRegistrations = config.AllowRegistrations != false;
2829
}
2930
else
3031
{
32+
model.AllowRegistrations = true;
3133
model.BaseUrl = Request.Url.ToString().Replace("installation/setup/basics/", "");
3234
ViewBag.NextLink = "";
3335
}
@@ -42,7 +44,8 @@ public ActionResult Basics(BasicsViewModel model)
4244
var settings = new BaseConfiguration
4345
{
4446
BaseUrl = new Uri(model.BaseUrl),
45-
SupportEmail = model.SupportEmail
47+
SupportEmail = model.SupportEmail,
48+
AllowRegistrations = model.AllowRegistrations
4649
};
4750
ConfigurationStore.Instance.Store(settings);
4851
return Redirect(Url.GetNextWizardStep());
@@ -54,9 +57,7 @@ public ActionResult Errors()
5457
var config = ConfigurationStore.Instance.Load<codeRRConfigSection>();
5558
if (config != null)
5659
{
57-
model.ActivateTracking = config.ActivateTracking;
5860
model.ContactEmail = config.ContactEmail;
59-
model.InstallationId = config.InstallationId;
6061
}
6162
else
6263
ViewBag.NextLink = "";
@@ -72,12 +73,9 @@ public ActionResult Errors(ErrorTrackingViewModel model)
7273

7374
var settings = new codeRRConfigSection
7475
{
75-
ActivateTracking = model.ActivateTracking,
7676
ContactEmail = model.ContactEmail,
77-
InstallationId = model.InstallationId
7877
};
7978
ConfigurationStore.Instance.Store(settings);
80-
WebApiApplication.ReportTocodeRR = model.ActivateTracking;
8179
return Redirect(Url.GetNextWizardStep());
8280
}
8381

src/Server/Coderr.Server.Web/Areas/Admin/Models/BasicsViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ namespace codeRR.Server.Web.Areas.Admin.Models
44
{
55
public class BasicsViewModel
66
{
7+
/// <summary>
8+
/// URL to coderr (typically "http://yourHostName/" or "http://somehost/coderr/")
9+
/// </summary>
710
[Required, MinLength(4)]
811
public string BaseUrl { get; set; }
912

13+
/// <summary>
14+
/// Email used when codeRR users ask for internal support
15+
/// </summary>
1016
[Required, EmailAddress]
1117
public string SupportEmail { get; set; }
18+
19+
/// <summary>
20+
/// Allow users to register new accounts
21+
/// </summary>
22+
public bool AllowRegistrations { get; set; }
1223
}
1324
}

src/Server/Coderr.Server.Web/Areas/Admin/Models/ErrorTrackingViewModel.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ namespace codeRR.Server.Web.Areas.Admin.Models
44
{
55
public class ErrorTrackingViewModel
66
{
7-
[Display(Name = "Activate tracking")]
8-
public bool ActivateTracking { get; set; }
9-
107
[Display(Name = "Contact email"), EmailAddress]
118
public string ContactEmail { get; set; }
12-
13-
/// <summary>
14-
/// A fixed identity which identifies this specific installation. You can generate a GUID and then store it.
15-
/// </summary>
16-
/// <remarks>
17-
/// <para>
18-
/// Used to identify the number of installations that have the same issue.
19-
/// </para>
20-
/// </remarks>
21-
public string InstallationId { get; set; }
229
}
2310
}
Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
@model codeRR.Server.Web.Areas.Admin.Models.BasicsViewModel
2-
@{
3-
ViewBag.Title = "Admin - Basics";
4-
}
5-
<div class="container">
6-
<div class="col-lg-6">
7-
8-
<h2>Base configuration</h2>
9-
<form method="post" action="@Url.Action("Basics")" style="width: 100%" class="form">
10-
@Html.ValidationSummary(false)
11-
<div class="form-group">
12-
<label class="control-label">
13-
Base URL
14-
</label>
15-
<input type="url"
16-
name="BaseUrl" class="form-control" value="@Model.BaseUrl" placeholder="http://yourhostName"/>
17-
<small>Address used when visiting this site.</small>
18-
</div>
19-
<div class="form-group">
20-
<label for="SupportEmail">
21-
Email address
22-
</label>
23-
<input type="email" id="SupportEmail" name="SupportEmail" class="form-control" value="@Model.SupportEmail"/>
24-
<small>Used by your users when they need support using codeRR, for instance for account troubles. Also used as sender in outbound emails.</small>
25-
</div>
26-
<br/>
27-
<input type="submit" class="btn btn-primary" value="Save"/>
28-
</form>
29-
</div>
30-
</div>
1+
@model codeRR.Server.Web.Areas.Admin.Models.BasicsViewModel
2+
@{
3+
ViewBag.Title = "Admin - Basics";
4+
}
5+
<div class="container">
6+
<div class="col-lg-6">
7+
<h2>Base configuration</h2>
8+
<form method="post" action="@Url.Action("Basics")" style="width: 100%" class="form">
9+
@Html.ValidationSummary(false)
10+
<div class="form-group">
11+
<label class="control-label">
12+
Base URL
13+
</label>
14+
<input type="url"
15+
name="BaseUrl" class="form-control" value="@Model.BaseUrl" placeholder="http://yourhostName" />
16+
<small class="form-text text-muted">Address used when visiting this site.</small>
17+
</div>
18+
<div class="form-group">
19+
<label for="SupportEmail">
20+
Email address
21+
</label>
22+
<input type="email" id="SupportEmail" name="SupportEmail" class="form-control" value="@Model.SupportEmail" />
23+
<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>
24+
</div>
25+
<div class="form-check">
26+
<label for="AllowRegistrations" class="form-check-label">
27+
<input type="checkbox" id="AllowRegistrations" name="AllowRegistrations" class="form-check-input" value="1" @(@Model.AllowRegistrations ? "checked=\"checked\"" : "") />
28+
Allow registrations
29+
</label>
30+
<br/>
31+
<small class="form-text text-muted">Allow users to create new accounts by using the registration page.</small>
32+
</div>
33+
34+
<br />
35+
<input type="submit" class="btn btn-primary" value="Save" />
36+
</form>
37+
</div>
38+
</div>

src/Server/Coderr.Server.Web/Areas/Admin/Views/Home/ErrorTracking.cshtml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,18 @@
77

88
<h2>Error tracking</h2>
99
<p>
10-
To correct bugs much faster we would like to activate codeRR for your installation. All exceptions
11-
will be uploaded to our own installation for further analysis.
10+
To correct bugs much faster we use codeRR to track errors in codeRR Community Server. All exceptions
11+
are uploaded to our own installation for further analysis.
1212
</p>
1313
<form method="post" action="@Url.Action("Errors")" style="width: 100%" class="form">
1414
@Html.ValidationSummary(false)
1515
<div class="form-group">
16-
@Html.CheckBoxFor(x => x.ActivateTracking, new {@class = "form-control", style = "display:inline;height:auto;width:inherit;"})
17-
@Html.LabelFor(x => x.ActivateTracking, new {@class = "control-label"})
18-
<br/>
19-
<small>Allow us to track errors.</small>
2016
</div>
2117
<div class="form-group disabled suboption">
2218
@Html.LabelFor(x => x.ContactEmail, new {@class = "control-label"})
2319
@Html.TextBoxFor(x => x.ContactEmail, new {@class = "form-control", disabled = ""})
2420
<small>Email address that we may contact if we need any further information (will also receive notifications when your errors have been corrected).</small>
2521
</div>
26-
<div class="form-group disabled suboption">
27-
@Html.LabelFor(x => x.InstallationId, new {@class = "control-label"})
28-
@Html.TextBoxFor(x => x.InstallationId, new {@class = "form-control", disabled = ""})
29-
<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>
30-
<br/>
31-
<small>A guid generated for your convencience if you want to enable this feature: @Guid.NewGuid().ToString("N")</small>
32-
</div>
3322
<br/>
3423
<input type="submit" class="btn btn-primary" value="Save"/>
3524
</form>

src/Server/Coderr.Server.Web/Areas/Admin/Views/Shared/_Layout.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
</div>
5454
</div>
5555
@Scripts.Render("~/bundles/jquery")
56-
@Scripts.Render("~/bundles/bootstrap")
5756
@RenderSection("scripts", false)
5857
</body>
5958
</html>

src/Server/Coderr.Server.Web/Areas/Installation/Views/Shared/_Layout.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
</div>
3434
</div>
3535
@Scripts.Render("~/bundles/jquery")
36-
@Scripts.Render("~/bundles/bootstrap")
3736
@RenderSection("scripts", false)
3837
</body>
3938
</html>

src/Server/Coderr.Server.Web/Content/Site.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
.ViewContainer {
1+
.validation-summary-errors ul li {
2+
color: red;
3+
list-style-type: none;
4+
margin-left: 0;
5+
padding-left: 0;
6+
}
7+
.ViewContainer {
28
width: 100%;
39
}
410
.morris-hover {

src/Server/Coderr.Server.Web/Content/Site.less

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
.ViewContainer {
1+
.validation-summary-errors ul li{
2+
color: red;
3+
list-style-type: none;
4+
margin-left: 0;
5+
padding-left: 0;
6+
}
7+
8+
.ViewContainer {
29
width: 100%;
310
}
411
.morris-hover {

src/Server/Coderr.Server.Web/Content/Site.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Server/Coderr.Server.Web/Controllers/AccountController.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,25 @@ public ActionResult Index()
151151

152152
public ActionResult Login()
153153
{
154+
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
155+
var model = new LoginViewModel
156+
{
157+
AllowRegistrations = config.AllowRegistrations != false
158+
};
159+
154160
var url = ConfigurationManager.AppSettings["LoginUrl"];
155161
if (url != null && url != Request.Url.AbsolutePath)
156162
return Redirect(url);
157163

158-
return View();
164+
return View(model);
159165
}
160166

161167
[HttpPost]
162168
public async Task<ActionResult> Login(LoginViewModel model)
163169
{
170+
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
171+
model.AllowRegistrations = config.AllowRegistrations != false;
172+
164173
if (!ModelState.IsValid)
165174
return View(model);
166175

@@ -228,6 +237,12 @@ public ActionResult Register()
228237
[HttpPost]
229238
public async Task<ActionResult> Register(RegisterViewModel model)
230239
{
240+
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
241+
if (config.AllowRegistrations == false)
242+
{
243+
ModelState.AddModelError("", "New registrations are not allowed.");
244+
}
245+
231246
if (!ModelState.IsValid)
232247
return View(model);
233248

src/Server/Coderr.Server.Web/Global.asax.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace codeRR.Server.Web
1717
public class WebApiApplication : HttpApplication
1818
{
1919
private static readonly ILog _logger;
20-
public static bool ReportTocodeRR;
2120

2221
static WebApiApplication()
2322
{
@@ -50,9 +49,6 @@ private void Application_Error(object sender, EventArgs e)
5049
}
5150
_logger.Error("Request + " + Request.Url + ", data" + data, exception);
5251

53-
if (!ReportTocodeRR)
54-
return;
55-
5652
var properties = new Dictionary<string, string>
5753
{
5854
{"Url", Request.Url.ToString()},

src/Server/Coderr.Server.Web/Infrastructure/Logging/WebApiLogger.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public override void Log(ExceptionLoggerContext context)
2323
_logger.Error("Request + " + context.Request.RequestUri + ", data" + data, context.Exception);
2424
_logger.Error(context.Exception);
2525

26-
if (!WebApiApplication.ReportTocodeRR)
27-
return;
28-
2926
var properties = new Dictionary<string, string>
3027
{
3128
{"Url", context.Request.RequestUri.ToString()},

src/Server/Coderr.Server.Web/Models/Account/LoginViewmodel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ public class LoginViewModel
1111

1212
[Required]
1313
public string UserName { get; set; }
14+
15+
/// <summary>
16+
/// Allow new users to register.
17+
/// </summary>
18+
public bool AllowRegistrations { get; set; }
1419
}
1520
}

0 commit comments

Comments
 (0)