Ejemplo n.º 1
0
        public async Task <Jwt> Login(LoginForm form)
        {
            var identity = await _identitiesRepository.GetByLoginAndPassword(form);

            if (identity == null)
            {
                return(null);
            }

            var hashed = _passwordHashCalculator.Calc(form.Password);

            if (identity.Password != hashed)
            {
                return(null);
            }

            var token = await _tokensRepository.IssueToken(identity.Id, DateTimeOffset.UtcNow.AddYears(1));

            if (token == null)
            {
                return(null);
            }

            var mappedToken = _mapper.Map <Jwts, Jwt>(token);

            var tokenBody = _jwtGenerator.Generate(mappedToken);
            await _tokensRepository.WriteBody(tokenBody.Id, tokenBody.Token);

            return(tokenBody);
        }
Ejemplo n.º 2
0
        public Task Add(LoginForm form)
        {
            _ac.Identities.Add(new Entities.Identities
            {
                Login     = form.Login,
                Password  = _passwordHashCalculator.Calc(form.Password),
                IsDeleted = false
            });

            return(_ac.SaveChangesAsync());
        }