Beispiel #1
0
        public async Task <AuthenticateResponse> Authenticate(AuthenticateRequest model)
        {
            ApplicationUser user = db.ApplicationUser.FirstOrDefault(_ => _.UserName == model.Username);

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

            var passCorrect = await userManager.CheckPasswordAsync(user, model.Password);

            if (!passCorrect)
            {
                return(null);
            }

            string jwtToken = await tokenService.GenerateJwtToken(user);

            RefreshToken refreshToken = tokenService.GenerateRefreshToken();

            user.RefreshTokens.Add(refreshToken);
            db.Update(user);
            await db.SaveChangesAsync();


            return(new AuthenticateResponse(user, jwtToken, refreshToken.Token));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Petition,EventType,Place,EventDate,NAssistants,Details,Name,phone,Email")] Event @event)
        {
            if (id != @event.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(@event);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventExists(@event.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }