Add real name col / citizen name prop (#12)

Still need to work on allowing the column to be edited
This commit is contained in:
2021-02-06 21:43:16 -05:00
parent 21ba35408e
commit 1b2540e5d2
10 changed files with 31 additions and 19 deletions

View File

@@ -65,7 +65,8 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
var citizen = await _db.FindCitizenByNAUser(account.Username);
if (citizen == null)
{
citizen = new Citizen(await CitizenId.Create(), account.Username, account.DisplayName, account.Url,
citizen = new Citizen(await CitizenId.Create(), account.Username,
string.IsNullOrWhiteSpace(account.DisplayName) ? null : account.DisplayName, null, account.Url,
now, now);
await _db.AddCitizen(citizen);
}
@@ -73,7 +74,7 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
{
citizen = citizen with
{
DisplayName = account.DisplayName,
DisplayName = string.IsNullOrWhiteSpace(account.DisplayName) ? null : account.DisplayName,
LastSeenOn = now
};
_db.UpdateCitizen(citizen);
@@ -83,7 +84,7 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
// Step 3 - Generate JWT
var jwt = Auth.CreateJwt(citizen, _config);
return new JsonResult(new LogOnSuccess(jwt, citizen.Id.ToString(), citizen.DisplayName));
return new JsonResult(new LogOnSuccess(jwt, citizen.Id.ToString(), citizen.CitizenName));
}
[Authorize]

View File

@@ -80,13 +80,6 @@ namespace JobsJobsJobs.Server
$"Profiles must be from noagendasocial.com; yours is {profileResponse.AccountName}");
}
// If the user hasn't filled in a display name, use the username as the display name.
// (this is what Mastodon does)
if (string.IsNullOrWhiteSpace(profileResponse.DisplayName))
{
profileResponse.DisplayName = profileResponse.Username;
}
return Result<MastodonAccount>.AsOk(profileResponse);
}
@@ -104,7 +97,7 @@ namespace JobsJobsJobs.Server
Subject = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, citizen.Id.ToString()),
new Claim(ClaimTypes.Name, citizen.DisplayName),
new Claim(ClaimTypes.Name, citizen.CitizenName),
}),
Expires = DateTime.UtcNow.AddHours(2),
Issuer = "https://noagendacareers.com",

View File

@@ -49,11 +49,13 @@ namespace JobsJobsJobs.Server.Data
m.Property(e => e.Id).HasColumnName("id").IsRequired().HasMaxLength(12)
.HasConversion(Converters.CitizenIdConverter);
m.Property(e => e.NaUser).HasColumnName("na_user").IsRequired().HasMaxLength(50);
m.Property(e => e.DisplayName).HasColumnName("display_name").IsRequired().HasMaxLength(255);
m.Property(e => e.DisplayName).HasColumnName("display_name").HasMaxLength(255);
m.Property(e => e.ProfileUrl).HasColumnName("profile_url").IsRequired().HasMaxLength(1_024);
m.Property(e => e.JoinedOn).HasColumnName("joined_on").IsRequired();
m.Property(e => e.LastSeenOn).HasColumnName("last_seen_on").IsRequired();
m.Property(e => e.RealName).HasColumnName("real_name").HasMaxLength(255);
m.HasIndex(e => e.NaUser).IsUnique();
m.Ignore(e => e.CitizenName);
});
modelBuilder.Entity<Continent>(m =>

View File

@@ -156,7 +156,7 @@ namespace JobsJobsJobs.Server.Data
query = query.Where(it => citizenIds.Contains(it.Citizen.Id));
}
return await query.Select(x => new ProfileSearchResult(x.Citizen.Id, x.Citizen.DisplayName,
return await query.Select(x => new ProfileSearchResult(x.Citizen.Id, x.Citizen.CitizenName,
x.Profile.SeekingEmployment, x.Profile.RemoteWork, x.Profile.FullTime, x.Profile.LastUpdatedOn))
.ToListAsync().ConfigureAwait(false);
}

View File

@@ -28,7 +28,7 @@ namespace JobsJobsJobs.Server.Data
await db.Successes
.Join(db.Citizens, s => s.CitizenId, c => c.Id, (s, c) => new { Success = s, Citizen = c })
.OrderByDescending(it => it.Success.RecordedOn)
.Select(it => new StoryEntry(it.Success.Id, it.Citizen.Id, it.Citizen.DisplayName,
.Select(it => new StoryEntry(it.Success.Id, it.Citizen.Id, it.Citizen.CitizenName,
it.Success.RecordedOn, it.Success.FromHere, it.Success.Story != null))
.ToListAsync().ConfigureAwait(false);
}