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

This commit is contained in:
Jamie 2018-07-28 00:14:36 +01:00
parent 69cb8a17ab
commit ec84c27a46
10 changed files with 7623 additions and 39 deletions

View file

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

View file

@ -40,13 +40,13 @@ export class AppComponent implements OnInit {
__webpack_public_path__ = base + "/dist/"; __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 language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang("en"); this.translate.setDefaultLang("en");
// See if we can match the supported langs with the current browser lang // See if we can match the supported langs with the current browser lang
const browserLang: string = translate.getBrowserLang(); 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() { public ngOnInit() {

View file

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

View file

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

View file

@ -17,10 +17,12 @@ export class CreateAdminComponent {
public createUser() { public createUser() {
this.identityService.createWizardUser({username: this.username, password: this.password, usePlexAdminAccount: false}).subscribe(x => { this.identityService.createWizardUser({username: this.username, password: this.password, usePlexAdminAccount: false}).subscribe(x => {
if (x) { if (x.result) {
this.router.navigate(["login"]); this.router.navigate(["login"]);
} else { } 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]);
}
} }
}); });
} }

View file

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

View file

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

View file

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

View file

@ -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>();
}
}

7566
src/Ombi/yarn.lock Normal file

File diff suppressed because it is too large Load diff