Exemplo n.º 1
0
        public async Task <IActionResult> LogIn([FromBody] LogInDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            User currentUser = _context.Users.Where(u => u.Email.Equals(dto.Email.ToLower()) && u.Password.Equals(dto.Password)).FirstOrDefault();

            if (currentUser == null)
            {
                return(BadRequest());
            }

            return(Ok(JsonConvert.SerializeObject(currentUser.Email)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Activate(string hash)
        {
            if (hash == null)
            {
                return(BadRequest());
            }

            try
            {
                NewUserData data        = _context.NewUserData.FirstOrDefault(ud => ud.Hash.Equals(hash));
                User        currentUser = _context.Users.FirstOrDefault(u => u.Email.Equals(data.NewUserEmmail));
                currentUser.UserVerified = true;


                _context.Update(currentUser);
                _context.SaveChanges();

                if (data.Writer)
                {
                    ControlFlow.ResumeOnError(() => { EmailService.SendEmail(new UserDto()
                        {
                            FirstName = data.Hash, Writer = data.Writer, Email = data.NewUserEmmail
                        }, null, "WorkUpload"); });
                }

                HttpResponseMessage taskResponse = await client.GetAsync($"{_configuration["url"]}/task?processDefinitionId={data.processDefinitionId}&&processInstanceId={data.processInstanceId}");

                Task <string>      jsonStringResult = taskResponse.Content.ReadAsStringAsync();
                List <CamundaTask> tasks            = JsonConvert.DeserializeObject <List <CamundaTask> >(jsonStringResult.Result);

                if (tasks.Count == 0)
                {
                    return(BadRequest());
                }

                var content = new StringContent("{}", Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteTask = await client.PostAsync($"{_configuration["url"]}/task/{tasks[0].id}/complete", content);

                //logujem ga
                FetchAndLock fetchAndLock = new FetchAndLock()
                {
                    workerId = currentUser.Email, maxTasks = 10, topics = new List <Topic>()
                    {
                        new Topic()
                        {
                            lockDuration = 10000, topicName = "ProveraKorisnikovePotvrde"
                        }
                    }
                };
                var fetchAndLockContent = new StringContent(JsonConvert.SerializeObject(fetchAndLock), Encoding.UTF8, "application/json");
                HttpResponseMessage lockExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/fetchAndLock", fetchAndLockContent);

                //daj mi moj lokovan da izvucem id
                HttpResponseMessage externalTaskInfo = await client.GetAsync($"{_configuration["url"]}/external-task?workerId={currentUser.Email}");

                Task <string> jsonStringResult_1         = externalTaskInfo.Content.ReadAsStringAsync();
                List <CamundaExternalTask> externalTasks = JsonConvert.DeserializeObject <List <CamundaExternalTask> >(jsonStringResult_1.Result);
                CamundaExternalTask        currenTask    = externalTasks.First();

                //prosledimm reziltat
                CompleteExternalTask completeExternalTask = new CompleteExternalTask()
                {
                    workerId = currentUser.Email, variables = new VariablesFirstTask()
                    {
                        Writer = new Writer()
                        {
                            value = data.Writer
                        }
                    }
                };
                var completeExternalTaskContent           = new StringContent(JsonConvert.SerializeObject(completeExternalTask), Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/{currenTask.id}/complete", completeExternalTaskContent);


                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RegisterNewUser([FromBody] UserDto dto)
        {
            int userId = -1;

            try
            {
                var content = new StringContent("{}", Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteTask = await client.PostAsync($"{_configuration["url"]}/task/{dto.TaskId}/complete", content);

                lit_udr.EntityFramework.Model.User newUser = new lit_udr.EntityFramework.Model.User()
                {
                    FirstName      = dto.FirstName,
                    LastName       = dto.LastName,
                    Password       = CreatePasswordHash(dto.Password),
                    Email          = dto.Email.ToLower(),
                    Country        = dto.Country,
                    City           = dto.City,
                    Writer         = dto.Writer,
                    BetaReader     = dto.BetaReader,
                    UserVerified   = false,
                    UserRetryCount = 0,
                    UserGenres     = new List <UserGenre>()
                };

                dto.Genre = dto.Genre.Distinct().ToList();
                foreach (string genre in dto.Genre)
                {
                    lit_udr.EntityFramework.Model.Genre genreInDatabase = _context.Genres.FirstOrDefault(x => x.Name.Equals(genre));
                    newUser.UserGenres.Add(new UserGenre()
                    {
                        UserId = newUser.Id, GenreId = genreInDatabase.Id
                    });
                }
                _context.Users.Add(newUser);
                _context.SaveChanges();

                userId = newUser.Id;
                ControlFlow.ResumeOnError(() => { EmailService.SendEmail(dto, _context, "Registration"); });

                //logujem ga
                FetchAndLock fetchAndLock = new FetchAndLock()
                {
                    workerId = newUser.Email, maxTasks = 10, topics = new List <Topic>()
                    {
                        new Topic()
                        {
                            lockDuration = 10000, topicName = "ProveraRegistracije"
                        }
                    }
                };
                var fetchAndLockContent = new StringContent(JsonConvert.SerializeObject(fetchAndLock), Encoding.UTF8, "application/json");
                HttpResponseMessage lockExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/fetchAndLock", fetchAndLockContent);

                //daj mi moj lokovan da izvucem id
                HttpResponseMessage externalTaskInfo = await client.GetAsync($"{_configuration["url"]}/external-task?workerId={newUser.Email}");

                Task <string> jsonStringResult_1         = externalTaskInfo.Content.ReadAsStringAsync();
                List <CamundaExternalTask> externalTasks = JsonConvert.DeserializeObject <List <CamundaExternalTask> >(jsonStringResult_1.Result);
                CamundaExternalTask        currenTask    = externalTasks.First();

                //prosledimm reziltat
                CompleteExternalTask completeExternalTask = new CompleteExternalTask()
                {
                    workerId = newUser.Email, variables = new Camunda.Model.ProcessModel.Variables()
                    {
                        DataCorrect = new DataCorrect()
                        {
                            value = true
                        }
                    }
                };
                var completeExternalTaskContent           = new StringContent(JsonConvert.SerializeObject(completeExternalTask), Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/{currenTask.id}/complete", completeExternalTaskContent);



                return(Ok());
            }
            catch (Exception e)
            {
                User currentUser = _context.Users.FirstOrDefault(u => u.Id.Equals(userId));
                if (currentUser != null)
                {
                    _context.Users.Remove(currentUser);
                    _context.SaveChanges();
                }

                var content = new StringContent("{}", Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteTask = await client.PostAsync($"{_configuration["url"]}/task/{dto.TaskId}/complete", content);

                //logujem ga
                FetchAndLock fetchAndLock = new FetchAndLock()
                {
                    workerId = "BadRequest", maxTasks = 10, topics = new List <Topic>()
                    {
                        new Topic()
                        {
                            lockDuration = 10000, topicName = "ProveraRegistracije"
                        }
                    }
                };
                var fetchAndLockContent = new StringContent(JsonConvert.SerializeObject(fetchAndLock), Encoding.UTF8, "application/json");
                HttpResponseMessage lockExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/fetchAndLock", fetchAndLockContent);

                //daj mi moj lokovan da izvucem id
                HttpResponseMessage externalTaskInfo = await client.GetAsync($"{_configuration["url"]}/external-task?workerId=BadRequest");

                Task <string> jsonStringResult_1         = externalTaskInfo.Content.ReadAsStringAsync();
                List <CamundaExternalTask> externalTasks = JsonConvert.DeserializeObject <List <CamundaExternalTask> >(jsonStringResult_1.Result);
                CamundaExternalTask        currenTask    = externalTasks.First();

                //prosledimm reziltat
                CompleteExternalTask completeExternalTask = new CompleteExternalTask()
                {
                    workerId = "BadRequest", variables = new Camunda.Model.ProcessModel.Variables()
                    {
                        DataCorrect = new DataCorrect()
                        {
                            value = false
                        }
                    }
                };
                var completeExternalTaskContent           = new StringContent(JsonConvert.SerializeObject(completeExternalTask), Encoding.UTF8, "application/json");
                HttpResponseMessage commpleteExternalTask = await client.PostAsync($"{_configuration["url"]}/external-task/{currenTask.id}/complete", completeExternalTaskContent);


                return(BadRequest());
            }
        }