Пример #1
0
        public AuthenticateResponse Authenticate(AuthenticateRequest model, string ipAddress)
        {
            var account = _context.Accounts.SingleOrDefault(x => x.Email == model.Email);

            if (account == null || !account.IsVerified || !BC.Verify(model.Password, account.PasswordHash))
            {
                throw new AppException("Email or password is incorrect");
            }

            // authentication successful so generate jwt and refresh tokens
            string jwtToken     = generateJwtToken(account);
            var    refreshToken = generateRefreshToken(ipAddress);

            account.RefreshTokens.Add(refreshToken);

            // remove old refresh tokens from account
            removeOldRefreshTokens(account);

            // save changes to db
            _context.Update(account);
            _context.SaveChanges();

            var response = _mapper.Map <AuthenticateResponse>(account);

            response.JwtToken     = jwtToken;
            response.RefreshToken = refreshToken.Token;
            return(response);
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("BancoId,BancoNome")] Banco banco)
        {
            if (id != banco.BancoId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(banco);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BancoExists(banco.BancoId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(banco));
        }