#435 Started the wizard

pull/1029/head
Jamie.Rees 8 years ago
parent bd3df2c1b8
commit 1f4ece8b5b

@ -517,3 +517,11 @@ label {
background-color: #3e3e3e;
border: 1px solid transparent; }
.wizard-heading {
text-align: center; }
.wizard-img {
width: 300px;
display: block !important;
margin: 0 auto !important; }

File diff suppressed because one or more lines are too long

@ -641,4 +641,13 @@ $border-radius: 10px;
margin-bottom: -1px;
background-color: #3e3e3e;
border: 1px solid transparent;
}
.wizard-heading{
text-align: center;
}
.wizard-img{
width: 300px;
display: block $i;
margin: 0 auto $i;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@ -3,9 +3,39 @@
// Step 1
$('#firstNext')
.click(function () {
loadArea("plexAuthArea");
loadArea("mediaApplicationChoice");
});
// Plex click
$('#contentBody')
.on("click", "#plexImg", function(e) {
e.preventDefault();
return loadArea("plexAuthArea");
});
$('#contentBody')
.on("click", "#embyImg", function (e) {
e.preventDefault();
return loadArea("embyApiKey");
});
$('#contentBody').on('click', '#embyApiKeySave', function (e) {
e.preventDefault();
var $form = $("#embyAuthForm");
$.post($form.prop("action"), $form.serialize(), function (response) {
if (response.result === true) {
loadArea("authArea");
} else {
generateNotify(response.message, "warning");
}
});
});
// Step 2 - Get the auth token
$('#contentBody').on('click', '#requestToken', function (e) {
e.preventDefault();

@ -1,4 +1,5 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UserWizardModule.cs
@ -23,6 +24,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
@ -50,8 +52,11 @@ namespace Ombi.UI.Modules
{
public class UserWizardModule : BaseModule
{
public UserWizardModule(ISettingsService<PlexRequestSettings> pr, ISettingsService<PlexSettings> plex, IPlexApi plexApi,
ISettingsService<AuthenticationSettings> auth, ICustomUserMapper m, IAnalytics a, ISecurityExtensions security) : base("wizard", pr, security)
public UserWizardModule(ISettingsService<PlexRequestSettings> pr, ISettingsService<PlexSettings> plex,
IPlexApi plexApi,
ISettingsService<AuthenticationSettings> auth, ICustomUserMapper m, IAnalytics a,
ISecurityExtensions security, IEmbyApi embyApi,
ISettingsService<EmbySettings> embySettings) : base("wizard", pr, security)
{
PlexSettings = plex;
PlexApi = plexApi;
@ -59,10 +64,13 @@ namespace Ombi.UI.Modules
Auth = auth;
Mapper = m;
Analytics = a;
EmbySettings = embySettings;
EmbyApi = embyApi;
Get["/", true] = async (x, ct) =>
{
a.TrackEventAsync(Category.Wizard, Action.Start, "Started the wizard", Username, CookieHelper.GetAnalyticClientId(Cookies));
a.TrackEventAsync(Category.Wizard, Action.Start, "Started the wizard", Username,
CookieHelper.GetAnalyticClientId(Cookies));
var settings = await PlexRequestSettings.GetSettingsAsync();
@ -76,7 +84,10 @@ namespace Ombi.UI.Modules
Post["/plex", true] = async (x, ct) => await Plex();
Post["/plexrequest", true] = async (x, ct) => await PlexRequest();
Post["/auth", true] = async (x, ct) => await Authentication();
Post["/createuser",true] = async (x,ct) => await CreateUser();
Post["/createuser", true] = async (x, ct) => await CreateUser();
Post["/embyauth", true] = async (x, ct) => await EmbyAuth();
}
private ISettingsService<PlexSettings> PlexSettings { get; }
@ -85,6 +96,8 @@ namespace Ombi.UI.Modules
private ISettingsService<AuthenticationSettings> Auth { get; }
private ICustomUserMapper Mapper { get; }
private IAnalytics Analytics { get; }
private IEmbyApi EmbyApi { get; }
private ISettingsService<EmbySettings> EmbySettings { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
@ -95,23 +108,31 @@ namespace Ombi.UI.Modules
if (string.IsNullOrEmpty(user.username) || string.IsNullOrEmpty(user.password))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Please provide a valid username and password" });
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Please provide a valid username and password"
});
}
var model = PlexApi.SignIn(user.username, user.password);
if (model?.user == null)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Incorrect username or password!" });
return
Response.AsJson(new JsonResponseModel {Result = false, Message = "Incorrect username or password!"});
}
// Set the auth token in the session so we can use it in the next form
Session[SessionKeys.UserWizardPlexAuth] = model.user.authentication_token;
var servers = PlexApi.GetServer(model.user.authentication_token);
var firstServer = servers.Server.FirstOrDefault();
return Response.AsJson(new { Result = true, firstServer?.Port, Ip = firstServer?.LocalAddresses, firstServer?.Scheme });
return
Response.AsJson(
new {Result = true, firstServer?.Port, Ip = firstServer?.LocalAddresses, firstServer?.Scheme});
}
private async Task<Response> Plex()
@ -122,7 +143,8 @@ namespace Ombi.UI.Modules
{
return Response.AsJson(valid.SendJsonError());
}
form.PlexAuthToken = Session[SessionKeys.UserWizardPlexAuth].ToString(); // Set the auth token from the previous form
form.PlexAuthToken = Session[SessionKeys.UserWizardPlexAuth].ToString();
// Set the auth token from the previous form
// Get the machine ID from the settings (This could have changed)
try
@ -141,9 +163,14 @@ namespace Ombi.UI.Modules
var result = await PlexSettings.SaveSettingsAsync(form);
if (result)
{
return Response.AsJson(new JsonResponseModel { Result = true });
return Response.AsJson(new JsonResponseModel {Result = true});
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save the settings to the database, please try again." });
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not save the settings to the database, please try again."
});
}
private async Task<Response> PlexRequest()
@ -158,14 +185,19 @@ namespace Ombi.UI.Modules
currentSettings.SearchForMovies = form.SearchForMovies;
currentSettings.SearchForTvShows = form.SearchForTvShows;
currentSettings.SearchForMusic = form.SearchForMusic;
var result = await PlexRequestSettings.SaveSettingsAsync(currentSettings);
if (result)
{
return Response.AsJson(new { Result = true });
return Response.AsJson(new {Result = true});
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save the settings to the database, please try again." });
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not save the settings to the database, please try again."
});
}
private async Task<Response> Authentication()
@ -175,16 +207,23 @@ namespace Ombi.UI.Modules
var result = await Auth.SaveSettingsAsync(form);
if (result)
{
return Response.AsJson(new JsonResponseModel { Result = true });
return Response.AsJson(new JsonResponseModel {Result = true});
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save the settings to the database, please try again." });
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not save the settings to the database, please try again."
});
}
private async Task<Response> CreateUser()
{
var username = (string)Request.Form.Username;
var userId = Mapper.CreateUser(username, Request.Form.Password, EnumHelper<Permissions>.All() - (int)Permissions.ReadOnlyUser, 0);
Analytics.TrackEventAsync(Category.Wizard, Action.Finish, "Finished the wizard", username, CookieHelper.GetAnalyticClientId(Cookies));
var username = (string) Request.Form.Username;
var userId = Mapper.CreateUser(username, Request.Form.Password,
EnumHelper<Permissions>.All() - (int) Permissions.ReadOnlyUser, 0);
Analytics.TrackEventAsync(Category.Wizard, Action.Finish, "Finished the wizard", username,
CookieHelper.GetAnalyticClientId(Cookies));
Session[SessionKeys.UsernameKey] = username;
// Destroy the Plex Auth Token
@ -197,7 +236,55 @@ namespace Ombi.UI.Modules
var baseUrl = string.IsNullOrEmpty(settings.BaseUrl) ? string.Empty : $"/{settings.BaseUrl}";
return CustomModuleExtensions.LoginAndRedirect(this,(Guid)userId, fallbackRedirectUrl: $"{baseUrl}/search");
return CustomModuleExtensions.LoginAndRedirect(this, (Guid) userId, fallbackRedirectUrl: $"{baseUrl}/search");
}
private async Task<Response> EmbyAuth()
{
var ip = (string) Request.Form.Ip;
var port = (int) Request.Form.Port;
var apiKey = (string) Request.Form.ApiKey;
var ssl = (bool) Request.Form.Ssl;
var settings = new EmbySettings
{
ApiKey = apiKey,
Enable = true,
Ip = ip,
Port = port,
Ssl = ssl,
};
try
{
// Test that we can connect
var result = EmbyApi.GetUsers(settings.FullUri, apiKey);
if (result != null && result.Any())
{
await EmbySettings.SaveSettingsAsync(settings);
return Response.AsJson(new JsonResponseModel
{
Result = true
});
}
}
catch (Exception e)
{
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = $"Could not connect to Emby, please check your settings. Error: {e.Message}"
});
}
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not connect to Emby, please check your settings."
});
}
}
}

@ -393,6 +393,24 @@
<Content Include="Content\helpers\bootbox.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\emby-logo-dark.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\emby-logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\logo original.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\logo-cropped.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\plex-logo-reversed.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\images\plex-logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\issue-details.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

@ -10,10 +10,9 @@
}
@Html.LoadWizardAssets()
<img class="landing-header" src="@formAction/Content/images/logo.png" width="300" />
<img class="landing-header" src="@formAction/Content/images/logo-cropped.png" width="300" />
<div id="area" class="landing-block shadow">
<div class="media">
<div id="contentBody" class="media-body">
<h4 class="media-heading landing-title" id="statusTitle">Welcome to Ombi</h4>
@ -31,6 +30,60 @@
<!--Templates-->
<script id="mediaApplicationChoice" type="text/html">
<div>
<h4 class="media-heading landing-title wizard-heading" id="statusTitle">Please choose your media server</h4>
<div class="form-group">
<div class="row">
<a href="#" id="embyImg">
<img class="wizard-img" src="@formAction/Content/images/emby-logo-dark.jpg" />
</a>
</div>
<div class="row">
<a href="#" id="plexImg">
<img class="wizard-img" src="@formAction/Content/images/plex-logo-reversed.png" />
</a>
</div>
</div>
</div>
</script>
<script id="embyApiKey" type="text/html">
<form method="post" action="@formAction/wizard/embyAuth" id="embyAuthForm">
<h4 class="media-heading landing-title">Emby Authentication</h4>
<div class="form-group">
<label for="Ip" class="control-label">Emby Hostname or IP Address</label>
<div>
<input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="192.168.1.1">
</div>
</div>
<div class="form-group">
<label for="portNumber" class="control-label">Port</label>
<div>
<input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="8069">
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="Ssl" name="Ssl"><label for="Ssl">SSL</label>
</div>
</div>
<div class="form-group">
<label for="username" class="control-label">Api Key</label>
<div>
<input type="text" class="form-control form-control-custom" id="apiKey" name="ApiKey" placeholder="ApiKey">
</div>
</div>
<div style="text-align: center; margin-top: 20px">
<a href="#" id="embyApiKeySave" class="btn btn-primary-outline">Next</a>
</div>
</form>
</script>
<script id="plexAuthArea" type="text/html">
<form method="post" action="@formAction/wizard/plexAuth" id="plexAuthForm">
<h4 class="media-heading landing-title">Plex Authentication</h4>
@ -103,7 +156,7 @@
<input type="checkbox" id="SearchForMusic" name="SearchForMusic"><label id="SearchForMusicLabel" for="SearchForMusic">Allow searching for Music</label>
</div>
</div>
<div class="form-group">
<div style="text-align: center; margin-top: 20px">
<a href="#" id="submitPlexRequest" class="btn btn-primary-outline">Next</a>

Loading…
Cancel
Save