Fix naming conventions for private fields

This commit is contained in:
Hisham Bin Ateya
2020-03-05 01:46:53 +03:00
parent e74f0d7644
commit a46235ea1e
75 changed files with 1219 additions and 1219 deletions

View File

@ -19,27 +19,27 @@ namespace Oqtane.Controllers
[Route("{site}/api/[controller]")]
public class UserController : Controller
{
private readonly IUserRepository Users;
private readonly IRoleRepository Roles;
private readonly IUserRoleRepository UserRoles;
private readonly UserManager<IdentityUser> IdentityUserManager;
private readonly SignInManager<IdentityUser> IdentitySignInManager;
private readonly ITenantResolver Tenants;
private readonly INotificationRepository Notifications;
private readonly IFolderRepository Folders;
private readonly ILogManager logger;
private readonly IUserRepository _users;
private readonly IRoleRepository _roles;
private readonly IUserRoleRepository _userRoles;
private readonly UserManager<IdentityUser> _identityUserManager;
private readonly SignInManager<IdentityUser> _identitySignInManager;
private readonly ITenantResolver _tenants;
private readonly INotificationRepository _notifications;
private readonly IFolderRepository _folders;
private readonly ILogManager _logger;
public UserController(IUserRepository Users, IRoleRepository Roles, IUserRoleRepository UserRoles, UserManager<IdentityUser> IdentityUserManager, SignInManager<IdentityUser> IdentitySignInManager, ITenantResolver Tenants, INotificationRepository Notifications, IFolderRepository Folders, ILogManager logger)
{
this.Users = Users;
this.Roles = Roles;
this.UserRoles = UserRoles;
this.IdentityUserManager = IdentityUserManager;
this.IdentitySignInManager = IdentitySignInManager;
this.Tenants = Tenants;
this.Folders = Folders;
this.Notifications = Notifications;
this.logger = logger;
this._users = Users;
this._roles = Roles;
this._userRoles = UserRoles;
this._identityUserManager = IdentityUserManager;
this._identitySignInManager = IdentitySignInManager;
this._tenants = Tenants;
this._folders = Folders;
this._notifications = Notifications;
this._logger = logger;
}
// GET api/<controller>/5?siteid=x
@ -47,7 +47,7 @@ namespace Oqtane.Controllers
[Authorize]
public User Get(int id, string siteid)
{
User user = Users.GetUser(id);
User user = _users.GetUser(id);
if (user != null)
{
user.SiteId = int.Parse(siteid);
@ -60,7 +60,7 @@ namespace Oqtane.Controllers
[HttpGet("name/{name}")]
public User Get(string name, string siteid)
{
User user = Users.GetUser(name);
User user = _users.GetUser(name);
if (user != null)
{
user.SiteId = int.Parse(siteid);
@ -84,19 +84,19 @@ namespace Oqtane.Controllers
verified = false;
}
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser == null)
{
identityuser = new IdentityUser();
identityuser.UserName = User.Username;
identityuser.Email = User.Email;
identityuser.EmailConfirmed = verified;
var result = await IdentityUserManager.CreateAsync(identityuser, User.Password);
var result = await _identityUserManager.CreateAsync(identityuser, User.Password);
if (result.Succeeded)
{
User.LastLoginOn = null;
User.LastIPAddress = "";
user = Users.AddUser(User);
user = _users.AddUser(User);
if (!verified)
{
Notification notification = new Notification();
@ -105,50 +105,50 @@ namespace Oqtane.Controllers
notification.ToUserId = user.UserId;
notification.ToEmail = "";
notification.Subject = "User Account Verification";
string token = await IdentityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + Tenants.GetAlias().Name + "/login?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
notification.Body = "Dear " + User.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
notification.ParentId = null;
notification.CreatedOn = DateTime.Now;
notification.IsDelivered = false;
notification.DeliveredOn = null;
Notifications.AddNotification(notification);
_notifications.AddNotification(notification);
}
// assign to host role if this is the host user ( initial installation )
if (User.Username == Constants.HostUser)
{
int hostroleid = Roles.GetRoles(User.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId;
int hostroleid = _roles.GetRoles(User.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId;
UserRole userrole = new UserRole();
userrole.UserId = user.UserId;
userrole.RoleId = hostroleid;
userrole.EffectiveDate = null;
userrole.ExpiryDate = null;
UserRoles.AddUserRole(userrole);
_userRoles.AddUserRole(userrole);
}
// add folder for user
Folder folder = Folders.GetFolder(User.SiteId, "Users\\");
Folder folder = _folders.GetFolder(User.SiteId, "Users\\");
if (folder != null)
{
Folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = folder.Path + user.UserId.ToString() + "\\", Order = 1, IsSystem = true,
_folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = folder.Path + user.UserId.ToString() + "\\", Order = 1, IsSystem = true,
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"}]" });
}
}
}
else
{
var result = await IdentitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
if (result.Succeeded)
{
user = Users.GetUser(User.Username);
user = _users.GetUser(User.Username);
}
}
if (user != null && User.Username != Constants.HostUser)
{
// add auto assigned roles to user for site
List<Role> roles = Roles.GetRoles(User.SiteId).Where(item => item.IsAutoAssigned == true).ToList();
List<Role> roles = _roles.GetRoles(User.SiteId).Where(item => item.IsAutoAssigned == true).ToList();
foreach (Role role in roles)
{
UserRole userrole = new UserRole();
@ -156,11 +156,11 @@ namespace Oqtane.Controllers
userrole.RoleId = role.RoleId;
userrole.EffectiveDate = null;
userrole.ExpiryDate = null;
UserRoles.AddUserRole(userrole);
_userRoles.AddUserRole(userrole);
}
}
user.Password = ""; // remove sensitive information
logger.Log(User.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", user);
_logger.Log(User.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", user);
}
return user;
@ -177,20 +177,20 @@ namespace Oqtane.Controllers
{
if (User.Password != "")
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser != null)
{
identityuser.PasswordHash = IdentityUserManager.PasswordHasher.HashPassword(identityuser, User.Password);
await IdentityUserManager.UpdateAsync(identityuser);
identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, User.Password);
await _identityUserManager.UpdateAsync(identityuser);
}
}
User = Users.UpdateUser(User);
User = _users.UpdateUser(User);
User.Password = ""; // remove sensitive information
logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", User);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", User);
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", User);
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", User);
HttpContext.Response.StatusCode = 401;
User = null;
}
@ -203,16 +203,16 @@ namespace Oqtane.Controllers
[Authorize(Roles = Constants.AdminRole)]
public async Task Delete(int id)
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(Users.GetUser(id).Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(_users.GetUser(id).Username);
if (identityuser != null)
{
var result = await IdentityUserManager.DeleteAsync(identityuser);
var result = await _identityUserManager.DeleteAsync(identityuser);
if (result != null)
{
Users.DeleteUser(id);
logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Deleted {UserId}", id);
_users.DeleteUser(id);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Deleted {UserId}", id);
}
}
}
@ -225,13 +225,13 @@ namespace Oqtane.Controllers
if (ModelState.IsValid)
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser != null)
{
var result = await IdentitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
if (result.Succeeded)
{
user = Users.GetUser(identityuser.UserName);
user = _users.GetUser(identityuser.UserName);
if (user != null)
{
if (identityuser.EmailConfirmed)
@ -239,22 +239,22 @@ namespace Oqtane.Controllers
user.IsAuthenticated = true;
user.LastLoginOn = DateTime.Now;
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
Users.UpdateUser(user);
logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
_users.UpdateUser(user);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
if (SetCookie)
{
await IdentitySignInManager.SignInAsync(identityuser, IsPersistent);
await _identitySignInManager.SignInAsync(identityuser, IsPersistent);
}
}
else
{
logger.Log(LogLevel.Information, this, LogFunction.Security, "User Not Verified {Username}", User.Username);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Not Verified {Username}", User.Username);
}
}
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "User Login Failed {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User Login Failed {Username}", User.Username);
}
}
}
@ -268,7 +268,7 @@ namespace Oqtane.Controllers
public async Task Logout([FromBody] User User)
{
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", User.Username);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", User.Username);
}
// POST api/<controller>/verify
@ -277,23 +277,23 @@ namespace Oqtane.Controllers
{
if (ModelState.IsValid)
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser != null)
{
var result = await IdentityUserManager.ConfirmEmailAsync(identityuser, token);
var result = await _identityUserManager.ConfirmEmailAsync(identityuser, token);
if (result.Succeeded)
{
logger.Log(LogLevel.Information, this, LogFunction.Security, "Email Verified For {Username}", User.Username);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Email Verified For {Username}", User.Username);
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
User = null;
}
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
User = null;
}
}
@ -306,7 +306,7 @@ namespace Oqtane.Controllers
{
if (ModelState.IsValid)
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser != null)
{
Notification notification = new Notification();
@ -315,19 +315,19 @@ namespace Oqtane.Controllers
notification.ToUserId = User.UserId;
notification.ToEmail = "";
notification.Subject = "User Password Reset";
string token = await IdentityUserManager.GeneratePasswordResetTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + Tenants.GetAlias().Name + "/reset?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/reset?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
notification.Body = "Dear " + User.DisplayName + ",\n\nPlease Click The Link Displayed Below To Reset Your Password:\n\n" + url + "\n\nThank You!";
notification.ParentId = null;
notification.CreatedOn = DateTime.Now;
notification.IsDelivered = false;
notification.DeliveredOn = null;
Notifications.AddNotification(notification);
logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", User.Username);
_notifications.AddNotification(notification);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", User.Username);
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Notification Failed For {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Notification Failed For {Username}", User.Username);
}
}
}
@ -338,24 +338,24 @@ namespace Oqtane.Controllers
{
if (ModelState.IsValid)
{
IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username);
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
if (identityuser != null && !string.IsNullOrEmpty(token))
{
var result = await IdentityUserManager.ResetPasswordAsync(identityuser, token, User.Password);
var result = await _identityUserManager.ResetPasswordAsync(identityuser, token, User.Password);
if (result.Succeeded)
{
logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset For {Username}", User.Username);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset For {Username}", User.Username);
User.Password = "";
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
User = null;
}
}
else
{
logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
User = null;
}
}
@ -382,7 +382,7 @@ namespace Oqtane.Controllers
private string GetUserRoles(int UserId, int SiteId)
{
string roles = "";
List<UserRole> userroles = UserRoles.GetUserRoles(UserId, SiteId).ToList();
List<UserRole> userroles = _userRoles.GetUserRoles(UserId, SiteId).ToList();
foreach (UserRole userrole in userroles)
{
roles += userrole.Role.Name + ";";