This commit is contained in:
2018-09-04 17:00:16 +00:00
parent f1ce2baa63
commit a15e02db54
10 changed files with 70 additions and 16 deletions

View File

@@ -104,6 +104,11 @@ namespace AyaNova.Api.Controllers
}
//If the user is inactive they may not login
if (!u.Active)
{
return StatusCode(401, new ApiErrorResponse(ApiErrorCode.NOT_AUTHORIZED, null, "User deactivated"));
}
//build the key (JWT set in startup.cs)
byte[] secretKey = System.Text.Encoding.ASCII.GetBytes(ServerBootConfig.AYANOVA_JWT_SECRET);

View File

@@ -28,6 +28,7 @@ namespace AyaNova.Biz
//get a db and logger
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData");
User u = new User();
u.Active=true;
u.Name = "AyaNova Administrator";
u.Salt = Hasher.GenerateSalt();
u.Login = "manager";

View File

@@ -70,8 +70,8 @@ namespace AyaNova.Biz
inObj = System.Text.RegularExpressions.Regex.Replace(inObj, "-+", "-");
//Ensure doesn't start or end with a dash
inObj = inObj.Trim('-');
//No longer than 35 characters
inObj = StringUtil.MaxLength(inObj, 35);
//No longer than 255 characters
inObj = StringUtil.MaxLength(inObj, 255);
return inObj;
}
@@ -212,9 +212,9 @@ namespace AyaNova.Biz
if (string.IsNullOrWhiteSpace(inObj))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name");
//Name must be less than 35 characters
if (inObj.Length > 35)
AddError(ValidationErrorType.LengthExceeded, "Name", "35 char max");
//Name must be less than 255 characters
if (inObj.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "Name", "255 char max");
//Name must be unique
if (ct.Tag.Where(m => m.Name == inObj).FirstOrDefault() != null)

View File

@@ -147,9 +147,9 @@ namespace AyaNova.Biz
// if (string.IsNullOrWhiteSpace(inObj))
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Name");
// //Name must be less than 35 characters
// if (inObj.Length > 35)
// AddError(ValidationErrorType.LengthExceeded, "Name", "35 char max");
// //Name must be less than 255 characters
// if (inObj.Length > 255)
// AddError(ValidationErrorType.LengthExceeded, "Name", "255 char max");
return;
}

View File

@@ -14,8 +14,8 @@ namespace AyaNova.Models
[Required]
public long OwnerId { get; set; }
[Required]
public string Name { get; set; }//max 35 characters ascii set
[Required, MaxLength(255)]
public string Name { get; set; }//max 255 characters ascii set
}
}

View File

@@ -201,7 +201,7 @@ namespace AyaNova.Util
{
LogUpdateMessage(log);
exec("CREATE TABLE atag (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(35) not null)");
exec("CREATE TABLE atag (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null)");
exec("CREATE UNIQUE INDEX tagname_idx ON atag (name);");
exec("CREATE TABLE atagmap (id BIGSERIAL PRIMARY KEY, ownerid bigint not null," +
"tagid bigint not null REFERENCES atag (id), tagtoobjectid bigint not null, tagtoobjecttype integer not null)");

View File

@@ -16,7 +16,7 @@ namespace AyaNova.Util
public enum SeedLevel { SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet };
//////////////////////////////////////////////////////
//Seed database for trial and testing purposes
//
@@ -199,6 +199,9 @@ namespace AyaNova.Util
//PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs
GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT");
//TEST NOT ACTIVE - this is used for a test to see if inactive user can login
GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, false, "TEST_INACTIVE", "TEST_INACTIVE");
}
@@ -206,17 +209,32 @@ namespace AyaNova.Util
/// <summary>
/// Generate seed user with active=true
/// (override to save typing)
/// </summary>
/// <param name="count"></param>
/// <param name="roles"></param>
/// <param name="userType"></param>
/// <param name="login"></param>
/// <param name="password"></param>
public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, string login, string password)
{
GenSeedUser(count, roles, userType, true, login, password);
}
//////////////////////////////////////////////////////
//Seed user - default login / pw is first name
//
public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, string login = null, string password = null)
public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
{
AyContext ct = ServiceProviderProvider.DBContext;
for (int x = 0; x < count; x++)
{
User u = new User();
u.OwnerId=1;
u.Active = active;
u.OwnerId = 1;
var p = new Bogus.Person();
u.Name = p.FullName;
u.Salt = Hasher.GenerateSalt();