Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically create feed accounts on app startup #184

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion LiftLog.Api/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ [FromServices] IValidator<CreateUserRequest> validator

var password = Guid.NewGuid().ToString();
var hashedPassword = passwordService.HashPassword(password, out var salt);
var id = request.Id ?? Guid.NewGuid();
var user = new User
{
Id = request.Id,
Id = id,
HashedPassword = hashedPassword,
Salt = salt,
LastAccessed = DateTimeOffset.UtcNow,
Expand All @@ -50,6 +51,7 @@ [FromServices] IValidator<CreateUserRequest> validator
await db.SaveChangesAsync();
return Ok(
new CreateUserResponse(
Id: id,
Lookup: idEncodingService.EncodeId(user.UserLookup),
Password: password
)
Expand Down
5 changes: 1 addition & 4 deletions LiftLog.Api/Validators/UserRequestValidators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace LiftLog.Api.Validators;

public class CreateUserRequestValidator : AbstractValidator<CreateUserRequest>
{
public CreateUserRequestValidator()
{
RuleFor(x => x.Id).NotEmpty();
}
public CreateUserRequestValidator() { }
}

public class GetUsersRequestValidator : AbstractValidator<GetUsersRequest>
Expand Down
4 changes: 2 additions & 2 deletions LiftLog.Lib/Models/UserActions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace LiftLog.Lib.Models;

public record CreateUserRequest(Guid Id);
public record CreateUserRequest(Guid? Id);

public record GetUsersRequest(Guid[] Ids);

public record DeleteUserRequest(Guid Id, string Password);

public record GetUsersResponse(Dictionary<Guid, GetUserResponse> Users);

public record CreateUserResponse(string Lookup, string Password);
public record CreateUserResponse(Guid Id, string Lookup, string Password);

public record PutUserDataRequest(
Guid Id,
Expand Down
2 changes: 1 addition & 1 deletion LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ else

private void StartPublishing()
{
Dispatcher.Dispatch(new CreateFeedIdentityAction(Guid.NewGuid(), string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan, publishWorkouts, From == null ? null : From));
Dispatcher.Dispatch(new CreateFeedIdentityAction(string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan, publishWorkouts, From == null ? null : From));
}

private void UpdatePublishingDetails()
Expand Down
13 changes: 11 additions & 2 deletions LiftLog.Ui/Pages/Feed/FeedPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@
}
else
{
<div class="flex justify-end">
<AppButton Type=AppButtonType.Text OnClick=NavigateToCreateFeedIdentity>Your details</AppButton>
<div class="flex justify-center">
@if(!FeedState.Value.Identity.PublishWorkouts)
{
<div class="flex justify-center">
<AppButton Type=AppButtonType.Text OnClick=NavigateToCreateFeedIdentity>You're not currently publishing your workouts for your friends to see. Tap to start!</AppButton>
</div>
}else{
<div class="ml-auto">
<AppButton Type=AppButtonType.Text OnClick=NavigateToCreateFeedIdentity>Your details</AppButton>
</div>
}
</div>
}

Expand Down
5 changes: 2 additions & 3 deletions LiftLog.Ui/Services/FeedIdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public async Task<ApiResult<FeedIdentity>> CreateFeedIdentityAsync(
ImmutableListValue<SessionBlueprint> currentPlan
)
{
var id = Guid.NewGuid();
var response = await feedApiService.CreateUserAsync(new CreateUserRequest(id));
var response = await feedApiService.CreateUserAsync(new CreateUserRequest(null));
if (!response.IsSuccess)
{
return ApiResult<FeedIdentity>.FromFailure(response);
Expand All @@ -34,7 +33,7 @@ ImmutableListValue<SessionBlueprint> currentPlan
var aesKey = await encryptionService.GenerateAesKeyAsync();
var rsaKeyPair = await encryptionService.GenerateRsaKeysAsync();
return await UpdateFeedIdentityAsync(
id: id,
id: response.Data.Id,
lookup: response.Data.Lookup,
password: response.Data.Password,
aesKey: aesKey,
Expand Down
1 change: 0 additions & 1 deletion LiftLog.Ui/Store/Feed/FeedActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace LiftLog.Ui.Store.Feed;
public record SetFeedIsHydratedAction();

public record CreateFeedIdentityAction(
Guid Id,
string? Name,
byte[]? ProfilePicture,
bool PublishBodyweight,
Expand Down
13 changes: 13 additions & 0 deletions LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ public override async Task InitializeAsync(IDispatcher dispatch, IStore store)
}

dispatch.Dispatch(new SetFeedIsHydratedAction());
if (((FeedState)store.Features[nameof(FeedFeature)].GetState()) is { Identity: null })
{
dispatch.Dispatch(
new CreateFeedIdentityAction(
Name: null,
ProfilePicture: null,
PublishBodyweight: false,
PublishPlan: false,
PublishWorkouts: false,
RedirectAfterCreation: null
)
);
}
}
catch (Exception e)
{
Expand Down
Loading