mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
[SG-58] Avatar color selector (#2330)
* chore: backend work * changed typing to match efc * Update User_Update.sql * fix: script cleanup * fix: adjust max length * fix: adjust max length * fix: added missing script changes * fix: use short form for creating objects * add: mysql migrations * chore: add mysql script * chore: posgres migrations * chore: postgres migrations * fix: lint * Update 20221115034053_AvatarColor.cs * fix: removed gravatar inline (#2447) Co-authored-by: Todd Martin <tmartin@bitwarden.com> Co-authored-by: Todd Martin <106564991+trmartin4@users.noreply.github.com>
This commit is contained in:
@ -471,6 +471,20 @@ public class AccountsController : Controller
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpPut("avatar")]
|
||||
[HttpPost("avatar")]
|
||||
public async Task<ProfileResponseModel> PutAvatar([FromBody] UpdateAvatarRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
await _userService.SaveUserAsync(model.ToUser(user), true);
|
||||
var response = new ProfileResponseModel(user, null, null, null, await _userService.TwoFactorIsEnabledAsync(user), await _userService.HasPremiumFromOrganization(user));
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpGet("revision-date")]
|
||||
public async Task<long?> GetAccountRevisionDate()
|
||||
{
|
||||
|
16
src/Api/Models/Request/Accounts/UpdateAvatarRequestModel.cs
Normal file
16
src/Api/Models/Request/Accounts/UpdateAvatarRequestModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Api.Models.Request.Accounts;
|
||||
|
||||
public class UpdateAvatarRequestModel
|
||||
{
|
||||
[StringLength(7)]
|
||||
public string AvatarColor { get; set; }
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
existingUser.AvatarColor = AvatarColor;
|
||||
return existingUser;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ public class ProfileResponseModel : ResponseModel
|
||||
SecurityStamp = user.SecurityStamp;
|
||||
ForcePasswordReset = user.ForcePasswordReset;
|
||||
UsesKeyConnector = user.UsesKeyConnector;
|
||||
AvatarColor = user.AvatarColor;
|
||||
Organizations = organizationsUserDetails?.Select(o => new ProfileOrganizationResponseModel(o));
|
||||
Providers = providerUserDetails?.Select(p => new ProfileProviderResponseModel(p));
|
||||
ProviderOrganizations =
|
||||
@ -58,6 +59,7 @@ public class ProfileResponseModel : ResponseModel
|
||||
public string SecurityStamp { get; set; }
|
||||
public bool ForcePasswordReset { get; set; }
|
||||
public bool UsesKeyConnector { get; set; }
|
||||
public string AvatarColor { get; set; }
|
||||
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
|
||||
public IEnumerable<ProfileProviderResponseModel> Providers { get; set; }
|
||||
public IEnumerable<ProfileProviderOrganizationResponseModel> ProviderOrganizations { get; set; }
|
||||
|
Reference in New Issue
Block a user