Ejemplo n.º 1
0
        public async Task <ActionResult <LoginResponse> > Post(
            [FromBody] CredentialsRequest credentials,
            [FromServices] NotifyUsersService notifyUsersService,
            [FromServices] IOptions <DefaultUsersSettings> defaultUserSettings)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await authorizationService.GetJwtTokenForUser(credentials.Login, credentials.Password);

            if (result.IsT1)
            {
                return(Unauthorized());
            }
            var(userToken, user) = result.AsT0;
            var loginInfo = GenerateResponse(user, userToken);
            var claims    = await userManager.GetClaimsAsync(user);

            if (claims.Any(c => c.Type == DefaultClaims.NeedResetPassword.Type))
            {
                _ = Task.Delay(TimeSpan.FromSeconds(30)).ContinueWith(async(t) => await notifyUsersService.SendInformationMessageToUser(user.Id, defaultUserSettings.Value.ResetPasswordWarningText));
            }

            await SaveLoginEvent(credentials.ClientIP, user.Id);

            return(loginInfo);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post(
            Guid solutionId,
            SolutionStatus state,
            [FromServices] NotifyUsersService notifyUserService)
        {
            var solution = await dbContext.Solutions.SingleOrDefaultAsync(S => S.Id == solutionId);

            if (solution == null)
            {
                return(NotFound());
            }

            solution.Status = state;
            if (state == SolutionStatus.InProcessing)
            {
                solution.StartCheckingTime = DateTimeOffset.UtcNow;
            }
            else //Some end state
            {
                solution.TotalScore = await CalculateScore(solution.Id);

                solution.CheckedTime = DateTimeOffset.UtcNow;
            }
            await dbContext.SaveChangesAsync();

            await notifyUserService.NewSolutionAdded(solution);

            return(Ok());
        }