示例#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));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Petition,EventType,Place,EventDate,NAssistants,Details,Name,phone,Email")] Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Done)));
            }
            return(View(@event));
        }