Skip to content

Commit 704c648

Browse files
committed
Improved the config guide
1 parent b3aca08 commit 704c648

File tree

18 files changed

+300
-264
lines changed

18 files changed

+300
-264
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace codeRR.Server.Web.Areas.Installation.Controllers
2121
{
2222
[Area("Installation")]
23-
23+
2424
public class AccountController : Controller
2525
{
2626
public ActionResult Admin()
@@ -69,7 +69,7 @@ public async Task<ActionResult> Admin(AccountViewModel model)
6969

7070
var tm = new ApplicationTeamMember(app.Id, account.Id, "System")
7171
{
72-
Roles = new[] {ApplicationRole.Admin, ApplicationRole.Member},
72+
Roles = new[] { ApplicationRole.Admin, ApplicationRole.Member },
7373
UserName = account.UserName
7474
};
7575
await repos2.CreateAsync(tm);
@@ -86,7 +86,7 @@ public async Task<ActionResult> Admin(AccountViewModel model)
8686
new Claim(ClaimTypes.Role, CoderrRoles.SysAdmin, ClaimValueTypes.String)
8787
};
8888
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
89-
var properties = new AuthenticationProperties {IsPersistent = false};
89+
var properties = new AuthenticationProperties { IsPersistent = false };
9090
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
9191
new ClaimsPrincipal(identity), properties);
9292

@@ -104,18 +104,13 @@ private void SetStateFlag()
104104
{
105105
ViewBag.Exception = null;
106106
ViewBag.AlreadyCreated = false;
107-
if (User.Identity.IsAuthenticated)
108-
ViewBag.AlreadyCreated = true;
109-
else
107+
using (var con = SetupTools.DbTools.OpenConnection())
110108
{
111-
using (var con = SetupTools.DbTools.OpenConnection())
109+
using (var uow = new AdoNetUnitOfWork(con))
112110
{
113-
using (var uow = new AdoNetUnitOfWork(con))
114-
{
115-
var id = uow.ExecuteScalar("SELECT TOP 1 Id FROM Accounts");
116-
if (id != null)
117-
ViewBag.AlreadyCreated = true;
118-
}
111+
var id = uow.ExecuteScalar("SELECT TOP 1 Id FROM Accounts");
112+
if (id != null)
113+
ViewBag.AlreadyCreated = true;
119114
}
120115
}
121116

src/Server/Coderr.Server.Web/Areas/Installation/Controllers/SetupController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public ActionResult Basics(BasicsViewModel model)
104104
public ActionResult Completed(string displayError = null)
105105
{
106106
ViewBag.DisplayError = displayError == "1";
107+
InstallAuthorizationFilter.IsInstallationCompleted = true;
107108
return View();
108109
}
109110

src/Server/Coderr.Server.Web/Areas/Installation/FilterInstall.cs renamed to src/Server/Coderr.Server.Web/Areas/Installation/InstallAuthorizationFilter.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
32
using Microsoft.AspNetCore.Mvc.Filters;
43
using Microsoft.Extensions.Configuration;
54

@@ -17,8 +16,16 @@ public InstallAuthorizationFilter(IConfiguration configuration)
1716
_configuration = configuration;
1817
}
1918

19+
public static bool IsInstallationCompleted { get; set; }
20+
2021
public void OnAuthorization(AuthorizationFilterContext context)
2122
{
23+
if (IsInstallationCompleted)
24+
{
25+
ValidatePostInstallation(context);
26+
return;
27+
}
28+
2229
if (!context.HttpContext.Request.Path.Value.Contains("/installation/"))
2330
return;
2431

@@ -27,13 +34,26 @@ public void OnAuthorization(AuthorizationFilterContext context)
2734
return;
2835

2936
var isConfigured = section.GetValue<bool>("IsConfigured");
30-
if (!isConfigured)
37+
if (!isConfigured) return;
38+
39+
context.Result = new ContentResult
40+
{
41+
StatusCode = 403,
42+
Content = "The installation wizard has been disabled. Goto the root of the website.",
43+
ContentType = "text/plain"
44+
};
45+
}
46+
47+
private void ValidatePostInstallation(AuthorizationFilterContext context)
48+
{
49+
if (context.HttpContext.Request.Path.Value.Contains("/installation/"))
3150
return;
3251

3352
context.Result = new ContentResult
3453
{
3554
StatusCode = 403,
36-
Content = "Installation wizard have been disabled",
55+
Content =
56+
"Configuration wizard have been active. You must therefore restart the application pool so that all background services can start properly.",
3757
ContentType = "text/plain"
3858
};
3959
}
Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,63 @@
1-
@model codeRR.Server.Web.Areas.Installation.Models.AccountViewModel
2-
@{
3-
ViewBag.Title = "Installation - Account";
4-
}
5-
<div class="container">
6-
<div class="col-lg-6">
7-
8-
<h2>Account creation</h2>
9-
<p>You need to create an account to be able to login. You can at a later point invite other users to codeRR.</p>
10-
@if (ViewBag.AlreadyCreated)
11-
{
12-
<div class="alert alert-info">
13-
Account have already been created.
14-
</div>
15-
@Html.Raw(ViewBag.PrevLink)
16-
@Html.Raw(ViewBag.NextLink)
17-
}
18-
else
19-
{
20-
<form method="post" action="@Url.Action("Admin")" style="width: 100%" class="form">
21-
@Html.ValidationSummary(false)
22-
<div class="form-group">
23-
<label class="control-label">
24-
Username
25-
</label>
26-
<input type="text"
27-
name="UserName" class="form-control" value="@Model.UserName" autocomplete="off"/>
28-
</div>
29-
<div class="form-group">
30-
<label for="EmailAddress">
31-
Email address
32-
</label>
33-
<input type="email" id="EmailAddress" name="EmailAddress" class="form-control" value="@Model.EmailAddress"/>
34-
</div>
35-
<div class="form-group">
36-
<label>Password</label>
37-
<input type="password" name="Password" id="Password" class="form-control" value="@Model.Password" autocomplete="off"/>
38-
</div>
39-
<div class="form-group">
40-
<label>Password verification</label>
41-
<input type="password" name="Password2" id="Password2" class="form-control" placeholder="Re-enter the password for verification." autocomplete="off"/>
42-
<div class="text-danger" id="PasswordError"></div>
43-
</div>
44-
<br/>
45-
@Html.Raw(ViewBag.PrevLink)
46-
<input type="submit" class="btn btn-primary" value="Save"/>
47-
@Html.Raw(ViewBag.NextLink)
48-
</form>
49-
}
50-
@if (ViewBag.Exception != null)
51-
{
52-
<h2>Error</h2>
53-
<pre>@ViewBag.Exception</pre>
54-
}
55-
</div>
56-
</div>
57-
58-
@section scripts
59-
{
60-
<script>
61-
$("#Password2")
62-
.keyup(function(e) {
63-
if ($('#Password').val() != $('#Password2').val()) {
64-
$('#PasswordError').html("Passwords to not match.");
65-
} else {
66-
$('#PasswordError').html("");
67-
}
68-
})
69-
</script>
1+
@model codeRR.Server.Web.Areas.Installation.Models.AccountViewModel
2+
@{
3+
ViewBag.Title = "Installation - Account";
4+
}
5+
<div class="container">
6+
<div class="col-lg-12">
7+
<h2>Account creation</h2>
8+
<p>You need to create an account to be able to login. You can at a later point invite other users to codeRR.</p>
9+
@if (ViewBag.AlreadyCreated)
10+
{
11+
<div class="alert alert-info">
12+
Account have already been created.
13+
</div>
14+
@Html.Raw(ViewBag.PrevLink)
15+
@Html.Raw(ViewBag.NextLink)
16+
}
17+
else
18+
{
19+
<form method="post" action="@Url.Action("Admin")" style="width: 100%" class="form">
20+
@Html.ValidationSummary(false)
21+
<div class="form-group">
22+
<label asp-for="UserName">Username</label>
23+
<input asp-for="UserName" class="form-control" autocomplete="off" autofocus="autofocus" required="required" />
24+
</div>
25+
<div class="form-group">
26+
<label asp-for="EmailAddress">Email address</label>
27+
<input type="email" asp-for="EmailAddress" class="form-control" required="required" />
28+
</div>
29+
<div class="form-group">
30+
<label asp-for="Password">Password</label>
31+
<input type="password" asp-for="Password" class="form-control" value="@Model.Password" autocomplete="off" required="required" />
32+
</div>
33+
<div class="form-group">
34+
<label>Password verification</label>
35+
<input type="password" name="Password2" id="Password2" class="form-control" placeholder="Re-enter the password for verification." autocomplete="off" />
36+
<div class="text-danger" id="PasswordError"></div>
37+
</div>
38+
<br />
39+
@Html.Raw(ViewBag.PrevLink)
40+
<input type="submit" class="btn btn-primary" value="Save" />
41+
@Html.Raw(ViewBag.NextLink)
42+
</form>
43+
}
44+
@if (ViewBag.Exception != null)
45+
{
46+
<h2>Error</h2>
47+
<pre>@ViewBag.Exception</pre>
48+
}
49+
</div>
50+
</div>
51+
@section scripts
52+
{
53+
<script>
54+
$("#Password2")
55+
.keyup(function (e) {
56+
if ($('#Password').val() != $('#Password2').val()) {
57+
$('#PasswordError').html("Passwords to not match.");
58+
} else {
59+
$('#PasswordError').html("");
60+
}
61+
})
62+
</script>
7063
}
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
@model codeRR.Server.Web.Areas.Installation.Models.EmailViewModel
2-
@{
3-
ViewBag.Title = "Installation - Email configuration";
4-
}
5-
<div class="container">
6-
<div class="col-lg-8 offset-lg-2 col-md-12">
7-
8-
<h2>Email configuration</h2>
9-
<p>
10-
codeRR can send email notifcations upon different types of events (and password resets etc). To do this, we need
11-
to have a SMTP account for mailing.
12-
</p>
13-
<form method="post" action="@Url.Action("Email")" class="form">
14-
@Html.ValidationSummary(false)
15-
<div class="form-group">
16-
@Html.LabelFor(x => x.SmtpHost, new {@class = "control-label"})
17-
@Html.TextBoxFor(x => x.SmtpHost, new {@class = "form-control", placeholder = "IP Address or host name"})
18-
@Html.CheckBoxFor(x => x.UseSSL) Use SSL
19-
</div>
20-
<div class="form-group">
21-
@Html.LabelFor(x => x.PortNumber, new {@class = "control-label"})
22-
@Html.TextBoxFor(x => x.PortNumber, new {@class = "form-control", placeholder = "Port number. Typically 25 for SMTP and 587 for ESMTPS. Consult your mail server configuration."})
23-
</div>
24-
<div class="form-group">
25-
@Html.LabelFor(x => x.AccountName, new {@class = "control-label"})
26-
@Html.TextBoxFor(x => x.AccountName, new {@class = "form-control", placeholder = "SMTP Server account name (empty = no authentication)", autocomplete = "new-password" })
27-
</div>
28-
<div class="form-group">
29-
@Html.LabelFor(x => x.AccountPassword, new {@class = "control-label"})
30-
@Html.TextBoxFor(x => x.AccountPassword, new {@class = "form-control", placeholder = "Password for the above account", autocomplete = "new-password" })
31-
</div>
32-
<div class="form-group">
33-
<label class="control-label">Password verification</label>
34-
<!--https://stackoverflow.com/questions/15738259/disabling-chrome-autofill-->
35-
<input type="password" placeholder="Re-enter the password for verification" id="Password2" class="form-control" autocomplete="new-password"/>
36-
<div class="text-danger" id="PasswordError"></div>
37-
</div>
38-
<br/>
39-
@Html.Raw(ViewBag.PrevLink)
40-
<input type="submit" class="btn btn-primary" value="Save"/>
41-
@Html.Raw(ViewBag.NextLink)
42-
</form>
43-
</div>
44-
</div>
45-
@section scripts
46-
{
47-
<script>
48-
$("#Password2")
49-
.keyup(function(e) {
50-
if ($('#AccountPassword').val() != $('#Password2').val()) {
51-
$('#PasswordError').html("Passwords to not match.");
52-
} else {
53-
$('#PasswordError').html("");
54-
}
55-
})
56-
</script>
1+
@model codeRR.Server.Web.Areas.Installation.Models.EmailViewModel
2+
@{
3+
ViewBag.Title = "Installation - Email configuration";
4+
}
5+
<div class="container">
6+
<div class="col-lg-8 offset-lg-2 col-md-12">
7+
8+
<h2>Email configuration</h2>
9+
<p>
10+
codeRR can send email notifcations upon different types of events (and password resets etc). To do this, we need
11+
to have a SMTP account for mailing.
12+
</p>
13+
<form method="post" action="@Url.Action("Email")" class="form">
14+
@Html.ValidationSummary(false)
15+
<div class="form-group">
16+
<label asp-for="SmtpHost">SMTP Server</label>
17+
<input asp-for="SmtpHost" placeholder="IP Address or host name" class="form-control" autofocus="autofocus"/>
18+
<input asp-for="UseSSL" type="checkbox"/> Use SSL
19+
</div>
20+
<div class="form-group">
21+
<label asp-for="PortNumber">Port number</label>
22+
<input asp-for="PortNumber" type="number" placeholder="Port number. Typically 25 for SMTP and 587 for ESMTPS. Consult your mail server configuration." class="form-control" />
23+
</div>
24+
<div class="form-group">
25+
<label asp-for="AccountName">SMTP Account name</label>
26+
<input asp-for="AccountName" placeholder="SMTP Server account name (empty = no authentication)" class="form-control" />
27+
</div>
28+
<div class="form-group">
29+
<label asp-for="AccountPassword">SMTP Account password</label>
30+
<input asp-for="AccountPassword" placeholder="Password for the above account" autocomplete="new-password" type="password" class="form-control" />
31+
</div>
32+
<div class="form-group">
33+
<label asp-for="AccountPassword">Password verification</label>
34+
<input asp-for="AccountPassword" placeholder="Password for the above account" autocomplete="new-password2" type="password" class="form-control" />
35+
<!--https://stackoverflow.com/questions/15738259/disabling-chrome-autofill-->
36+
<div class="text-danger" id="PasswordError"></div>
37+
</div>
38+
<br/>
39+
@Html.Raw(ViewBag.PrevLink)
40+
<input type="submit" class="btn btn-primary" value="Save"/>
41+
@Html.Raw(ViewBag.NextLink)
42+
</form>
43+
</div>
44+
</div>
45+
@section scripts
46+
{
47+
<script>
48+
$("#Password2")
49+
.keyup(function(e) {
50+
if ($('#AccountPassword').val() != $('#Password2').val()) {
51+
$('#PasswordError').html("Passwords to not match.");
52+
} else {
53+
$('#PasswordError').html("");
54+
}
55+
})
56+
</script>
5757
}

0 commit comments

Comments
 (0)