mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -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; }
|
||||
|
@ -61,6 +61,8 @@ public class User : ITableObject<Guid>, ISubscriber, IStorable, IStorableSubscri
|
||||
public int FailedLoginCount { get; set; }
|
||||
public DateTime? LastFailedLoginDate { get; set; }
|
||||
public bool UnknownDeviceVerificationEnabled { get; set; }
|
||||
[MaxLength(7)]
|
||||
public string AvatarColor { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
|
@ -34,7 +34,8 @@
|
||||
@UsesKeyConnector BIT = 0,
|
||||
@FailedLoginCount INT = 0,
|
||||
@LastFailedLoginDate DATETIME2(7),
|
||||
@UnknownDeviceVerificationEnabled BIT = 1
|
||||
@UnknownDeviceVerificationEnabled BIT = 1,
|
||||
@AvatarColor VARCHAR(7) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -76,7 +77,8 @@ BEGIN
|
||||
[UsesKeyConnector],
|
||||
[FailedLoginCount],
|
||||
[LastFailedLoginDate],
|
||||
[UnknownDeviceVerificationEnabled]
|
||||
[UnknownDeviceVerificationEnabled],
|
||||
[AvatarColor]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -115,6 +117,7 @@ BEGIN
|
||||
@UsesKeyConnector,
|
||||
@FailedLoginCount,
|
||||
@LastFailedLoginDate,
|
||||
@UnknownDeviceVerificationEnabled
|
||||
@UnknownDeviceVerificationEnabled,
|
||||
@AvatarColor
|
||||
)
|
||||
END
|
||||
|
@ -34,7 +34,8 @@
|
||||
@UsesKeyConnector BIT = 0,
|
||||
@FailedLoginCount INT,
|
||||
@LastFailedLoginDate DATETIME2(7),
|
||||
@UnknownDeviceVerificationEnabled BIT = 1
|
||||
@UnknownDeviceVerificationEnabled BIT = 1,
|
||||
@AvatarColor VARCHAR(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -76,7 +77,8 @@ BEGIN
|
||||
[UsesKeyConnector] = @UsesKeyConnector,
|
||||
[FailedLoginCount] = @FailedLoginCount,
|
||||
[LastFailedLoginDate] = @LastFailedLoginDate,
|
||||
[UnknownDeviceVerificationEnabled] = @UnknownDeviceVerificationEnabled
|
||||
[UnknownDeviceVerificationEnabled] = @UnknownDeviceVerificationEnabled,
|
||||
[AvatarColor] = @AvatarColor
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
|
@ -35,6 +35,7 @@
|
||||
[FailedLoginCount] INT CONSTRAINT [D_User_FailedLoginCount] DEFAULT ((0)) NOT NULL,
|
||||
[LastFailedLoginDate] DATETIME2 (7) NULL,
|
||||
[UnknownDeviceVerificationEnabled] BIT CONSTRAINT [D_User_UnknownDeviceVerificationEnabled] DEFAULT ((1)) NOT NULL,
|
||||
[AvatarColor] VARCHAR(7) NULL,
|
||||
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user