Path: redb/redb.Core/Models/Entities/RedbUser.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Models/Entities/RedbUser.cs
----
using redb.Core.Models.Contracts;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace redb.Core.Models.Entities
{
///
/// REDB user entity with direct data storage.
/// Maps to _users table in PostgreSQL.
///
public class RedbUser : IRedbUser
{
///
/// Unique user identifier.
///
[JsonPropertyName("id")]
public long Id { get; set; }
///
/// User login (unique).
///
[JsonPropertyName("login")]
public string Login { get; set; } = string.Empty;
///
/// User display name.
///
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
///
/// User password (hashed).
///
[JsonPropertyName("password")]
public string Password { get; set; } = string.Empty;
///
/// Whether user is active.
///
[JsonPropertyName("enabled")]
public bool Enabled { get; set; } = true;
///
/// User registration date.
///
[JsonPropertyName("date_register")]
public DateTimeOffset DateRegister { get; set; } = DateTimeOffset.UtcNow;
///
/// User dismissal date (null if active).
///
[JsonPropertyName("date_dismiss")]
public DateTimeOffset? DateDismiss { get; set; }
///
/// User phone (optional).
///
[JsonPropertyName("phone")]
public string? Phone { get; set; }
///
/// User email (optional).
///
[JsonPropertyName("email")]
public string? Email { get; set; }
///
/// Additional user key (optional).
///
[JsonPropertyName("key")]
public long? Key { get; set; }
///
/// Integer code for categorization (optional).
///
[JsonPropertyName("code_int")]
public long? CodeInt { get; set; }
///
/// String code for departments/branches (optional).
///
[JsonPropertyName("code_string")]
public string? CodeString { get; set; }
///
/// GUID code for distributed systems (optional).
///
[JsonPropertyName("code_guid")]
public Guid? CodeGuid { get; set; }
///
/// User notes or comments (optional).
///
[JsonPropertyName("note")]
public string? Note { get; set; }
///
/// Hash for data integrity verification (optional).
///
[JsonPropertyName("hash")]
public Guid? Hash { get; set; }
///
/// Configuration object ID (optional).
///
[JsonPropertyName("id_configuration")]
public long? IdConfiguration { get; set; }
///
/// Default constructor for deserialization and mapping.
///
public RedbUser()
{
}
///
/// Constructor with required fields.
///
public RedbUser(string login, string name, string password)
{
Login = login ?? throw new ArgumentNullException(nameof(login));
Name = name ?? throw new ArgumentNullException(nameof(name));
Password = password ?? throw new ArgumentNullException(nameof(password));
}
///
/// System user (SYS_USER_ID = 0).
///
public static RedbUser SystemUser => new RedbUser
{
Id = 0,
Login = "sys",
Name = "System User",
Password = "",
Enabled = true,
DateRegister = DateTimeOffset.MinValue,
DateDismiss = null,
Phone = null,
Email = null,
Key = null,
CodeInt = 0,
CodeString = "SYS",
CodeGuid = new Guid("00000000-0000-0000-0000-000000000001"),
Note = "System user REDB",
Hash = null
};
public override string ToString()
{
var status = Enabled ? "Active" : "Disabled";
var codes = new List();
if (CodeInt.HasValue) codes.Add($"Int={CodeInt}");
if (!string.IsNullOrEmpty(CodeString)) codes.Add($"Str={CodeString}");
if (Key.HasValue) codes.Add($"Key={Key}");
var codesStr = codes.Count > 0 ? $" [{string.Join(", ", codes)}]" : "";
return $"User {Id}: {Login} ({Name}) - {status}{codesStr}";
}
}
}