Hide the password field if it's not needed #1815

pull/1909/head^2
Jamie 7 years ago
parent e3685e5ea8
commit 62ee9d8cdb

@ -64,19 +64,11 @@ namespace Ombi.Core.Authentication
public override async Task<bool> CheckPasswordAsync(OmbiUser user, string password) public override async Task<bool> CheckPasswordAsync(OmbiUser user, string password)
{ {
var authSettings = await _authSettings.GetSettingsAsync(); var requiresPassword = await RequiresPassword(user);
if (authSettings.AllowNoPassword) if (!requiresPassword)
{ {
// Check their roles // Let them through!
var roles = await GetRolesAsync(user); return true;
if (roles.Contains(OmbiRoles.Admin) || roles.Contains(OmbiRoles.PowerUser))
{
// Do nothing, let it continue to check the password
}
else
{
return true;
}
} }
if (user.UserType == UserType.LocalUser) if (user.UserType == UserType.LocalUser)
{ {
@ -93,6 +85,22 @@ namespace Ombi.Core.Authentication
return false; return false;
} }
public async Task<bool> RequiresPassword(OmbiUser user)
{
var authSettings = await _authSettings.GetSettingsAsync();
if (authSettings.AllowNoPassword)
{
var roles = await GetRolesAsync(user);
if (roles.Contains(OmbiRoles.Admin) || roles.Contains(OmbiRoles.PowerUser))
{
// We require a password
return true;
}
return false;
}
return true;
}
/// <summary> /// <summary>
/// Sign the user into plex and make sure we can get the authentication token. /// Sign the user into plex and make sure we can get the authentication token.
/// <remarks>We do not check if the user is in the owners "friends" since they must have a local user account to get this far</remarks> /// <remarks>We do not check if the user is in the owners "friends" since they must have a local user account to get this far</remarks>

@ -18,6 +18,10 @@ export class AuthService extends ServiceHelpers {
return this.http.post(`${this.url}/`, JSON.stringify(login), {headers: this.headers}); return this.http.post(`${this.url}/`, JSON.stringify(login), {headers: this.headers});
} }
public requiresPassword(login: IUserLogin): Observable<boolean> {
return this.http.post<boolean>(`${this.url}/requirePassword`, JSON.stringify(login), {headers: this.headers});
}
public loggedIn() { public loggedIn() {
const token: string = this.jwtHelperService.tokenGetter(); const token: string = this.jwtHelperService.tokenGetter();

@ -12,11 +12,11 @@ include the remember me checkbox
<div *ngIf="customizationSettings.logo"><img id="profile-img" class="center" [src]="customizationSettings.logo" /></div> <div *ngIf="customizationSettings.logo"><img id="profile-img" class="center" [src]="customizationSettings.logo" /></div>
<p id="profile-name" class="profile-name-card"></p> <p id="profile-name" class="profile-name-card"></p>
<form class="form-signin" novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)"> <form *ngIf="authenticationSettings" class="form-signin" novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)">
<input type="email" id="inputEmail" class="form-control" formControlName="username" [attr.placeholder]="'Login.UsernamePlaceholder' | translate" autofocus> <input type="email" id="inputEmail" class="form-control" formControlName="username" [attr.placeholder]="'Login.UsernamePlaceholder' | translate" autofocus>
<input type="password" id="inputPassword" class="form-control" formControlName="password" [attr.placeholder]="'Login.PasswordPlaceholder' | translate"> <input *ngIf="!authenticationSettings.allowNoPassword" type="password" id="inputPassword" class="form-control" formControlName="password" [attr.placeholder]="'Login.PasswordPlaceholder' | translate">
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<input type="checkbox" id="RememberMe" formControlName="rememberMe" > <input type="checkbox" id="RememberMe" formControlName="rememberMe" >

@ -5,7 +5,7 @@ import { TranslateService } from "@ngx-translate/core";
import { PlatformLocation } from "@angular/common"; import { PlatformLocation } from "@angular/common";
import { AuthService } from "../auth/auth.service"; import { AuthService } from "../auth/auth.service";
import { ICustomizationSettings } from "../interfaces"; import { IAuthenticationSettings, ICustomizationSettings } from "../interfaces";
import { NotificationService } from "../services"; import { NotificationService } from "../services";
import { SettingsService } from "../services"; import { SettingsService } from "../services";
import { StatusService } from "../services"; import { StatusService } from "../services";
@ -21,6 +21,7 @@ export class LoginComponent implements OnInit {
public form: FormGroup; public form: FormGroup;
public customizationSettings: ICustomizationSettings; public customizationSettings: ICustomizationSettings;
public authenticationSettings: IAuthenticationSettings;
public background: any; public background: any;
public landingFlag: boolean; public landingFlag: boolean;
public baseUrl: string; public baseUrl: string;
@ -61,6 +62,7 @@ export class LoginComponent implements OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.settingsService.getAuthentication().subscribe(x => this.authenticationSettings = x);
this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x); this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x);
this.images.getRandomBackground().subscribe(x => { this.images.getRandomBackground().subscribe(x => {
this.background = this.sanitizer.bypassSecurityTrustStyle("linear-gradient(-10deg, transparent 20%, rgba(0,0,0,0.7) 20.0%, rgba(0,0,0,0.7) 80.0%, transparent 80%),url(" + x.url + ")"); this.background = this.sanitizer.bypassSecurityTrustStyle("linear-gradient(-10deg, transparent 20%, rgba(0,0,0,0.7) 20.0%, rgba(0,0,0,0.7) 80.0%, transparent 80%),url(" + x.url + ")");
@ -80,16 +82,24 @@ export class LoginComponent implements OnInit {
return; return;
} }
const value = form.value; const value = form.value;
this.authService.login({ password: value.password, username: value.username, rememberMe:value.rememberMe }) const user = { password: value.password, username: value.username, rememberMe:value.rememberMe };
.subscribe(x => { this.authService.requiresPassword(user).subscribe(x => {
localStorage.setItem("id_token", x.access_token); if(x && this.authenticationSettings.allowNoPassword) {
// Looks like this user requires a password
this.authenticationSettings.allowNoPassword = false;
return;
}
this.authService.login(user)
.subscribe(x => {
localStorage.setItem("id_token", x.access_token);
if (this.authService.loggedIn()) { if (this.authService.loggedIn()) {
this.router.navigate(["search"]); this.router.navigate(["search"]);
} else { } else {
this.notify.error(this.errorBody); this.notify.error(this.errorBody);
} }
}, err => this.notify.error(this.errorBody)); }, err => this.notify.error(this.errorBody));
});
} }
} }

@ -317,6 +317,7 @@ namespace Ombi.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet("authentication")] [HttpGet("authentication")]
[AllowAnonymous]
public async Task<AuthenticationSettings> AuthenticationsSettings() public async Task<AuthenticationSettings> AuthenticationsSettings()
{ {
return await Get<AuthenticationSettings>(); return await Get<AuthenticationSettings>();

@ -15,6 +15,7 @@ using Ombi.Models;
using Ombi.Models.Identity; using Ombi.Models.Identity;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using StackExchange.Profiling.Helpers;
namespace Ombi.Controllers namespace Ombi.Controllers
{ {
@ -129,6 +130,26 @@ namespace Ombi.Controllers
throw new NotImplementedException(); throw new NotImplementedException();
} }
[HttpPost("requirePassword")]
public async Task<bool> DoesUserRequireAPassword([FromBody] UserAuthModel model)
{
var user = await _userManager.FindByNameAsync(model.Username);
if (user == null)
{
// Could this be an email login?
user = await _userManager.FindByEmailAsync(model.Username);
if (user == null)
{
return true;
}
}
var requires = await _userManager.RequiresPassword(user);
return requires;
}
public class TokenRefresh public class TokenRefresh
{ {
public string Token { get; set; } public string Token { get; set; }

Loading…
Cancel
Save