fixes null ref for new users at managing

This commit is contained in:
2019-09-27 03:26:58 +01:00
parent a7df4288f6
commit 5c4f61c3c7

View File

@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -24,7 +23,6 @@ namespace Yavsc.Controllers
using Yavsc.ViewModels.Manage; using Yavsc.ViewModels.Manage;
using System.IO; using System.IO;
[Authorize]
public class ManageController : Controller public class ManageController : Controller
{ {
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
@ -122,8 +120,9 @@ namespace Yavsc.Controllers
EMail = user.Email, EMail = user.Email,
EmailConfirmed = await _userManager.IsEmailConfirmedAsync(user), EmailConfirmed = await _userManager.IsEmailConfirmedAsync(user),
AllowMonthlyEmail = user.AllowMonthlyEmail, AllowMonthlyEmail = user.AllowMonthlyEmail,
Address = user.PostalAddress.Address Address = user.PostalAddress?.Address
}; };
model.HaveProfessionalSettings = _dbContext.Performers.Any(x => x.PerformerId == user.Id); model.HaveProfessionalSettings = _dbContext.Performers.Any(x => x.PerformerId == user.Id);
var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id).ToArray(); var usrActs = _dbContext.UserActivities.Include(a=>a.Does).Where(a=> a.UserId == user.Id).ToArray();
// TODO remember me who this magical a.Settings is built // TODO remember me who this magical a.Settings is built
@ -229,6 +228,7 @@ namespace Yavsc.Controllers
await _userManager.SetTwoFactorEnabledAsync(user, false); await _userManager.SetTwoFactorEnabledAsync(user, false);
await _signInManager.SignInAsync(user, isPersistent: false); await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation(2, "User disabled two-factor authentication."); _logger.LogInformation(2, "User disabled two-factor authentication.");
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.UnsetTwoFactorSuccess });
} }
return RedirectToAction(nameof(Index), "Manage"); return RedirectToAction(nameof(Index), "Manage");
} }
@ -427,7 +427,7 @@ namespace Yavsc.Controllers
model.NewUserName); model.NewUserName);
if (userdirinfo.Exists) if (userdirinfo.Exists)
userdirinfo.MoveTo(newdir); userdirinfo.MoveTo(newdir);
// Renames the Avatars // Renames the Avatars files
foreach (string s in new string [] { ".png", ".s.png", ".xs.png" }) foreach (string s in new string [] { ".png", ".s.png", ".xs.png" })
{ {
FileInfo fi = new FileInfo( FileInfo fi = new FileInfo(
@ -694,6 +694,7 @@ namespace Yavsc.Controllers
ChangePasswordSuccess, ChangePasswordSuccess,
ChangeNameSuccess, ChangeNameSuccess,
SetTwoFactorSuccess, SetTwoFactorSuccess,
UnsetTwoFactorSuccess,
SetPasswordSuccess, SetPasswordSuccess,
RemoveLoginSuccess, RemoveLoginSuccess,
RemovePhoneSuccess, RemovePhoneSuccess,