This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using DbAPI.Connections;
using DTS.Common.Classes;
using DTS.Common.Interface.Database;
using System;
using System.Data;
using System.Data.SqlClient;
namespace DbAPI.User
{
/// <summary>
/// Basic implementation of <see cref="IUser"/>
/// <inheritdoc cref="IUser"/>
/// </summary>
internal class User : IUserDbRecord
{
public int ID { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public string Password { get; set; }
public short Role { get; set; }
public DateTime LastModified { get; set; }
public string LastModifiedBy { get; set; }
public bool LocalOnly { get; set; }
public User(int id, string user, string display, string pwd, short role, DateTime lastModified, string lastModifiedBy, bool local)
{
ID = id;
UserName = user;
DisplayName = display;
Password = pwd;
Role = role;
LastModified = lastModified;
LastModifiedBy = lastModifiedBy;
LocalOnly = local;
}
internal static ulong GetUser(IConnectionDetails connection, out IUserDbRecord usr, string userName)
{
usr = null;
var res = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_UsersGetId");
if (res != Errors.ErrorCodes.ERROR_SUCCESS)
{
return Errors.ErrorCodes.ERROR_ACCESS_DENIED;
}
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar, 255) { Value = userName });
var newId = new SqlParameter("@UserId", SqlDbType.Int) { Direction = ParameterDirection.Output };
cmd.Parameters.Add(newId);
var reader = cmd.ExecuteReader();
if (DBNull.Value.Equals(newId.Value))
{
return Errors.ErrorCodes.ERROR_LOGINFAILED;
}
var id = Convert.ToInt32(newId.Value);
if (0 >= id) { return Errors.ErrorCodes.ERROR_LOGINFAILED; }
reader.Close();
cmd.Parameters.Clear();
cmd.CommandText = "sp_UsersGet";
cmd.Parameters.Add(new SqlParameter("@UserId", SqlDbType.Int) { Value = id });
reader = cmd.ExecuteReader();
if (!reader.Read()) { return Errors.ErrorCodes.ERROR_UNKNOWN; }
var thisid = Utility.GetInt(reader, "ID");
var uname = Utility.GetString(reader, "UserName");
var displayName = Utility.GetString(reader, "DisplayName");
var password = Utility.GetString(reader, "password");
var role = Utility.GetShort(reader, "Role");
var lastModified = Utility.GetDateTime(reader, "LastModified", DateTime.MinValue);
var lastModifiedBy = Utility.GetString(reader, "LastModifiedBy");
var local = Utility.GetBool(reader, "LocalOnly");
usr = new User(thisid, uname, displayName, password, role, lastModified, lastModifiedBy, local);
return Errors.ErrorCodes.ERROR_SUCCESS;
}
finally
{
cmd.Connection.Dispose();
}
}
}
}