Updated the way we create the wizard user, errors show now be fed back to the user.

pull/2411/head^2
Jamie 6 years ago
parent 69cb8a17ab
commit ec84c27a46

@ -134,11 +134,11 @@
<li [ngClass]="{'active': 'no' === translate.currentLang}">
<a (click)="translate.use('no')" [translate]="'NavigationBar.Language.Norwegian'"></a>
</li>
<li [ngClass]="{'active': 'pt-br' === translate.currentLang}">
<a (click)="translate.use('no')" [translate]="'NavigationBar.Language.BrazillianPortuguese'"></a>
<li [ngClass]="{'active': 'pt' === translate.currentLang}">
<a (click)="translate.use('pt')" [translate]="'NavigationBar.Language.BrazillianPortuguese'"></a>
</li>
<li [ngClass]="{'active': 'po' === translate.currentLang}">
<a (click)="translate.use('no')" [translate]="'NavigationBar.Language.Polish'"></a>
<li [ngClass]="{'active': 'pl' === translate.currentLang}">
<a (click)="translate.use('pl')" [translate]="'NavigationBar.Language.Polish'"></a>
</li>
</ul>
</li>

@ -40,13 +40,13 @@ export class AppComponent implements OnInit {
__webpack_public_path__ = base + "/dist/";
}
this.translate.addLangs(["en", "de", "fr","da","es","it","nl","sv","no", "po", "pt-br"]);
this.translate.addLangs(["en", "de", "fr","da","es","it","nl","sv","no", "pl", "pt"]);
// this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang("en");
// See if we can match the supported langs with the current browser lang
const browserLang: string = translate.getBrowserLang();
this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sv|no|po|pt-br/) ? browserLang : "en");
this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sv|no|pl|pt/) ? browserLang : "en");
}
public ngOnInit() {

@ -23,6 +23,11 @@ export interface ICreateWizardUser {
usePlexAdminAccount: boolean;
}
export interface IWizardUserResult {
result: boolean;
errors: string[];
}
export enum UserType {
LocalUser = 1,
PlexUser = 2,

@ -4,7 +4,7 @@ import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs/Rx";
import { ICheckbox, ICreateWizardUser, IIdentityResult, IResetPasswordToken, IUpdateLocalUser, IUser } from "../interfaces";
import { ICheckbox, ICreateWizardUser, IIdentityResult, IResetPasswordToken, IUpdateLocalUser, IUser, IWizardUserResult } from "../interfaces";
import { ServiceHelpers } from "./service.helpers";
@Injectable()
@ -12,8 +12,8 @@ export class IdentityService extends ServiceHelpers {
constructor(http: HttpClient, public platformLocation: PlatformLocation) {
super(http, "/api/v1/Identity/", platformLocation);
}
public createWizardUser(user: ICreateWizardUser): Observable<boolean> {
return this.http.post<boolean>(`${this.url}Wizard/`, JSON.stringify(user), {headers: this.headers});
public createWizardUser(user: ICreateWizardUser): Observable<IWizardUserResult> {
return this.http.post<IWizardUserResult>(`${this.url}Wizard/`, JSON.stringify(user), {headers: this.headers});
}
public getUser(): Observable<IUser> {

@ -17,10 +17,12 @@ export class CreateAdminComponent {
public createUser() {
this.identityService.createWizardUser({username: this.username, password: this.password, usePlexAdminAccount: false}).subscribe(x => {
if (x) {
if (x.result) {
this.router.navigate(["login"]);
} else {
this.notificationService.error("There was an error... You might want to put this on Github...");
if(x.errors.length > 0) {
this.notificationService.error(x.errors[0]);
}
}
});
}

@ -35,10 +35,13 @@ export class PlexComponent implements OnInit {
password: "",
usePlexAdminAccount: true,
}).subscribe(y => {
if (y) {
if (y.result) {
this.router.navigate(["login"]);
} else {
this.notificationService.error("Could not get the Plex Admin Information");
if(y.errors.length > 0) {
this.notificationService.error(y.errors[0]);
}
return;
}
});

@ -1,7 +1,7 @@
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { IdentityService, PlexOAuthService, SettingsService } from "../../services";
import { IdentityService, PlexOAuthService } from "../../services";
import { AuthService } from "./../../auth/auth.service";
@Component({
@ -13,7 +13,6 @@ export class PlexOAuthComponent implements OnInit {
constructor(private route: ActivatedRoute,
private plexOauth: PlexOAuthService,
private identityService: IdentityService,
private settings: SettingsService,
private router: Router,
private auth: AuthService) {
@ -35,28 +34,16 @@ export class PlexOAuthComponent implements OnInit {
password: "",
usePlexAdminAccount: true,
}).subscribe(u => {
if (u) {
if (u.result) {
this.auth.oAuth(this.pinId).subscribe(c => {
localStorage.setItem("id_token", c.access_token);
// Mark that we have done the settings now
this.settings.getOmbi().subscribe(ombi => {
ombi.wizard = true;
this.settings.saveOmbi(ombi).subscribe(s => {
this.settings.getUserManagementSettings().subscribe(usr => {
usr.importPlexAdmin = true;
this.settings.saveUserManagementSettings(usr).subscribe(saved => {
this.router.navigate(["login"]);
});
});
});
});
});
this.router.navigate(["login"]);
});
} else {
//this.notificationService.error("Could not get the Plex Admin Information");
if(u.errors.length > 0) {
console.log(u.errors[0]);
}
return;
}
});

@ -59,7 +59,8 @@ namespace Ombi.Controllers
IRepository<Issues> issues,
IRepository<IssueComments> issueComments,
IRepository<NotificationUserId> notificationRepository,
IRepository<RequestSubscription> subscriptionRepository)
IRepository<RequestSubscription> subscriptionRepository,
ISettingsService<UserManagementSettings> umSettings)
{
UserManager = user;
Mapper = mapper;
@ -79,6 +80,7 @@ namespace Ombi.Controllers
OmbiSettings = ombiSettings;
_requestSubscriptionRepository = subscriptionRepository;
_notificationRepository = notificationRepository;
_userManagementSettings = umSettings;
}
private OmbiUserManager UserManager { get; }
@ -87,6 +89,7 @@ namespace Ombi.Controllers
private IEmailProvider EmailProvider { get; }
private ISettingsService<EmailNotificationSettings> EmailSettings { get; }
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;
private ISettingsService<OmbiSettings> OmbiSettings { get; }
private IWelcomeEmail WelcomeEmail { get; }
private IMovieRequestRepository MovieRepo { get; }
@ -113,13 +116,13 @@ namespace Ombi.Controllers
[HttpPost("Wizard")]
[ApiExplorerSettings(IgnoreApi = true)]
[AllowAnonymous]
public async Task<bool> CreateWizardUser([FromBody] CreateUserWizardModel user)
public async Task<SaveWizardResult> CreateWizardUser([FromBody] CreateUserWizardModel user)
{
var users = UserManager.Users;
if (users.Any(x => !x.UserName.Equals("api", StringComparison.CurrentCultureIgnoreCase)))
{
// No one should be calling this. Only the wizard
return false;
return new SaveWizardResult{ Result = false };
}
if (user.UsePlexAdminAccount)
@ -129,7 +132,7 @@ namespace Ombi.Controllers
if (authToken.IsNullOrEmpty())
{
_log.LogWarning("Could not find an auth token to create the plex user with");
return false;
return new SaveWizardResult { Result = false };
}
var plexUser = await _plexApi.GetAccount(authToken);
var adminUser = new OmbiUser
@ -140,6 +143,11 @@ namespace Ombi.Controllers
ProviderUserId = plexUser.user.id
};
await _userManagementSettings.SaveSettingsAsync(new UserManagementSettings
{
ImportPlexAdmin = true
});
return await SaveWizardUser(user, adminUser);
}
@ -152,9 +160,10 @@ namespace Ombi.Controllers
return await SaveWizardUser(user, userToCreate);
}
private async Task<bool> SaveWizardUser(CreateUserWizardModel user, OmbiUser userToCreate)
private async Task<SaveWizardResult> SaveWizardUser(CreateUserWizardModel user, OmbiUser userToCreate)
{
IdentityResult result;
var retVal = new SaveWizardResult();
// When creating the admin as the plex user, we do not pass in the password.
if (user.Password.HasValue())
{
@ -182,6 +191,7 @@ namespace Ombi.Controllers
if (!result.Succeeded)
{
LogErrors(result);
retVal.Errors.AddRange(result.Errors.Select(x => x.Description));
}
// Update the wizard flag
@ -189,7 +199,8 @@ namespace Ombi.Controllers
settings.Wizard = true;
await OmbiSettings.SaveSettingsAsync(settings);
return result.Succeeded;
retVal.Result = result.Succeeded;
return retVal;
}
private void LogErrors(IdentityResult result)

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Ombi.Models.Identity
{
public class SaveWizardResult
{
public bool Result { get; set; }
public List<string> Errors { get; set; } = new List<string>();
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save