Beispiel #1
0
        public async Task ChangePasswordAsync(int id, string password)
        {
            var validateResult = PasswordValidator.Validate(password);

            if (validateResult != "OK")
            {
                throw new BadRequestException(validateResult);
            }

            var darbinieks = await _context.Darbinieki
                             .Where(d => d.Id == id)
                             .FirstOrDefaultAsync();

            if (darbinieks == null)
            {
                throw new BadRequestException($"Darbinieks ar Id={id} netika atrasts");
            }
            if (!string.IsNullOrEmpty(darbinieks.Lietotajvards))
            {
                if (!string.IsNullOrEmpty(darbinieks.Parole))
                {
                    if (password == PasswordValidator.Decrypt(darbinieks.Parole, _settings.EncryptionKey))
                    {
                        throw new BadRequestException("Parole nedrīkst būt tāda pati kā iepriekšējā");
                    }
                }
            }
            else
            {
                throw new BadRequestException("Darbiniekam nav lietotājvārda");
            }

            darbinieks.Parole = PasswordValidator.Encrypt(password, _settings.EncryptionKey);
            await _context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <string> GetPasswordByEmailAsync(string email)
        {
            var user = await _context.Darbinieki.AsNoTracking()
                       .Where(d => d.Epasts == email)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                throw new BadRequestException("Darbinieks ar šādu e-pasta adresi neeksistē");
            }
            if (!user.Aktivs)
            {
                throw new BadRequestException("Jūsu konts ir bloķēts");
            }

            return(PasswordValidator.Decrypt(user.Parole, _settings.EncryptionKey));
        }