Exemplo n.º 1
0
        public async Task <Guid> CreateAsync(string username, string clearPassword)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username), "value must not be empty.");
            }

            if (string.IsNullOrWhiteSpace(clearPassword))
            {
                throw new ArgumentNullException(nameof(clearPassword), "value must not be empty.");
            }

            var uid     = Guid.NewGuid();
            var account = new LocalAccountEntity
            {
                Id            = uid,
                CreateTimeUtc = DateTime.UtcNow,
                Username      = username.ToLower().Trim(),
                PasswordHash  = HashPassword(clearPassword.Trim())
            };

            await _accountRepo.AddAsync(account);

            await _audit.AddAuditEntry(EventType.Settings, AuditEventId.SettingsAccountCreated, $"Account '{account.Id}' created.");

            return(uid);
        }
Exemplo n.º 2
0
        public LocalAccountEntity GetLocalSystemAccount()
        {
            m_Logger.DebugFormat("__{0}__: {1}: Enter Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            LocalAccountEntity systemAccount = new LocalAccountEntity();

            try
            {
                using (AccountDatabaseUtility db = new AccountDatabaseUtility(m_DbConnectionString))
                {
                    systemAccount = db.QueryLocalSystemAccount();
                }
            }
            catch (SqlException ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: SQL Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            m_Logger.DebugFormat("__{0}__: {1}: Leave Function", this.GetType().Name, MethodInfo.GetCurrentMethod().Name);
            return(systemAccount);
        }
Exemplo n.º 3
0
    public async Task <Guid> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
    {
        if (string.IsNullOrWhiteSpace(request.Username))
        {
            throw new ArgumentNullException(nameof(request.Username), "value must not be empty.");
        }

        if (string.IsNullOrWhiteSpace(request.ClearPassword))
        {
            throw new ArgumentNullException(nameof(request.ClearPassword), "value must not be empty.");
        }

        var uid     = Guid.NewGuid();
        var account = new LocalAccountEntity
        {
            Id            = uid,
            CreateTimeUtc = DateTime.UtcNow,
            Username      = request.Username.ToLower().Trim(),
            PasswordHash  = Helper.HashPassword(request.ClearPassword.Trim())
        };

        await _accountRepo.AddAsync(account);

        return(uid);
    }
Exemplo n.º 4
0
    public Account(LocalAccountEntity entity)
    {
        if (null == entity)
        {
            return;
        }

        Id               = entity.Id;
        CreateTimeUtc    = entity.CreateTimeUtc;
        LastLoginIp      = entity.LastLoginIp.Trim();
        LastLoginTimeUtc = entity.LastLoginTimeUtc.GetValueOrDefault();
        Username         = entity.Username.Trim();
    }
Exemplo n.º 5
0
        private static Account EntityToAccountModel(LocalAccountEntity entity)
        {
            if (entity is null)
            {
                return(null);
            }

            return(new()
            {
                Id = entity.Id,
                CreateTimeUtc = entity.CreateTimeUtc,
                LastLoginIp = entity.LastLoginIp.Trim(),
                LastLoginTimeUtc = entity.LastLoginTimeUtc.GetValueOrDefault(),
                Username = entity.Username.Trim()
            });
        }