예제 #1
0
        public IActionResult ForgotPasswordData([FromForm] IdentityDTO request)
        {
            #region ForgotPassword
            ReturnMessage <ForgotPasswordDTO> response = new ServiceNode <IdentityDTO, ForgotPasswordDTO>(_localizer, _fc).PostClient(request, "/api/v1/users/getusertoken");
            if (response.IsCatched == 1)
            {
                TempData["ServerResponseError"] = response.Message;
                return(RedirectToAction("ForgotPassword"));
            }
            TempData["SuccessResponse"] = _localizer["We send password restore link to your email, please check your email adress"].ToString();
            #region SendRestoreEmail
            var configUrl = _configuration["BaseUrl"] + $"/users/restore?uk={response.Data.Token}&&pk={response.Data.Password}";
            MailSender.SendEmail(
                "TCYDM",
                "*****@*****.**",
                response.Data.Name,
                response.Data.Email,
                "Restore Password",
                "<a href =" + configUrl + ">Restore account</a>",
                "*****@*****.**",
                "o1o2o3o4o5o6o7o8o9o10"
                );

            #endregion
            #endregion
            return(RedirectToAction("Login", "Users"));
        }
예제 #2
0
        public async Task <IdentityResult> UpdateUser(IdentityDTO user)
        {
            ApplicationUser targetUser = mapper.Map <IdentityDTO, ApplicationUser>(user);
            IdentityResult  result     = await identityRepository.EditUser(userManager, targetUser);

            identityRepository.Save();
            return(result);
        }
예제 #3
0
        public IdentityViewModel GetIdentity(IdentityDTO dto)
        {
            if (_passwordHasher == null)
            {
                throw new Exception("The password hasher is not initialized.");
            }

            return(_dataAccessor.GetIdentity(dto.UserName, dto.Password));
        }
예제 #4
0
        public void Is_OK_No_Response()
        {
            //Arrange
            CheckpointDTO checkpoint = new CheckpointDTO()
            {
                ID          = 1,
                IP          = "192.168.0.1",
                Campus      = 1,
                Row         = 4,
                Description = "На 4 этаже, 425 аудитория",
                Status      = "Отметка",
                Type        = (TypeDTO)itemsType[2],
                Admissions  = itemsAdmission
            };
            IdentityDTO identity = new IdentityDTO()
            {
                ID         = 1,
                GUID       = "1",
                Picture    = "cat.jpg",
                Name       = "Сидр",
                Surname    = "Сидоров",
                Midname    = "Сидорович",
                Gender     = true,
                Birthdate  = Convert.ToDateTime("2000-01-25"),
                Country    = "Россия",
                City       = "Саратов",
                Department = "ИнПИТ",
                Group      = "ИФСТ",
                Status     = "Отчислен",
                Email      = "*****@*****.**",
                Phone      = "+79993499334",
                Role       = "Студент"
            };

            unitWorkMoq.Setup(x => x.Type.Get(1)).Returns(itemsType[0]);
            unitWorkMoq.Setup(x => x.Type.Get(2)).Returns(itemsType[1]);
            unitWorkMoq.Setup(x => x.Type.Get(3)).Returns(itemsType[2]);
            unitWorkMoq.Setup(x => x.Activity.GetAll())
            .Returns(itemsActivity.Where(x => x.IdentityGUID.Equals(id.ToString())));
            unitWorkMoq.Setup(x => x.Admission.GetAll())
            .Returns(itemsAdmission);
            unitWorkMoq.Setup(x => x.CheckpointAdmission.GetAll())
            .Returns(itemsCheckpointAdmission.Where(x => x.CheckpointID == checkpoint.ID));

            //Act
            var result = serviceMock.IsOk(checkpoint, identity);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(int));
            Assert.AreEqual(-1, result);
        }
예제 #5
0
        public async Task <ActionResult <ReqResult> > VerifyPassword([FromBody] IdentityDTO userIdentity)
        {
            var result = await _repository.VerifyUser(userIdentity);

            if (result == ReqResult.Ok)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
        // GET api/identities/5
        /// <summary>
        /// Gets a <see cref="IdentityDTO"/> object from the repository.
        /// </summary>
        /// <param name="id">The ID of <see cref="IdentityDTO"/>.</param>
        /// <returns>The <see cref="IdentityDTO"/> with the given ID.</returns>
        public IHttpActionResult Get(int id)
        {
            IdentityDTO item = service.Get(id);

            if (item != null)
            {
                dynamic json = new JObject();
                json["item"] = JToken.FromObject(item);
                return(Ok(AESService.Encrypt(json)));
            }
            else
            {
                return(NotFound());
            }
        }
예제 #7
0
        public IActionResult GetUserToken([FromBody] IdentityDTO request)
        {
            #region FunctionBody
            var existedUser = _db.Users.Where(a => a.Email == request.Identification || a.PhoneNumber == request.Identification).FirstOrDefault();
            if (existedUser is null)
            {
                return(StatusCode(400, new ReturnErrorMessage((int)ErrorTypes.Errors.WrongUser)));
            }
            if (existedUser.IsConfirmed == 0)
            {
                return(StatusCode(400, new ReturnErrorMessage((int)ErrorTypes.Errors.NeedConfirmation)));
            }
            return(Ok(new ReturnMessage(data: new { Token = existedUser.Token, Password = existedUser.Password, Email = existedUser.Email, Name = existedUser.Name })));

            #endregion
        }
예제 #8
0
        public async Task <ApiResponse> ResendVerificationCode([FromBody] IdentityDTO arg)
        {
            try
            {
                var userId = await userService.ResendVerificationCodeAsync(arg.Identity);

                return(new ApiResponse(InfoMessages.CodeHasSent, new GuidIdDTO()
                {
                    Id = userId
                }, HttpStatusCode.OK.ToInt()));
            }
            catch (CustomException ex)
            {
                throw new ApiException(ex, ex.StatusCode);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
        }
        public async Task <ReqResult> VerifyUser(IdentityDTO userLoginInfo)
        {
            var userToVerify = await _context.Users
                               .Where(user => user.email == userLoginInfo.email)
                               .FirstOrDefaultAsync();

            if (userToVerify == null)
            {
                return(ReqResult.EmailDoesntExist);
            }

            bool isValidLogin = BCrypt.Net.BCrypt.Verify(userLoginInfo.password,
                                                         userToVerify.password_hash);

            if (isValidLogin)
            {
                return(ReqResult.Ok);
            }
            else
            {
                return(ReqResult.BadPassword);
            }
        }
        public IHttpActionResult Post([FromBody] ActivityAPIModel item)
        {
            if (item != null)
            {
                CheckpointDTO checkpoint = checkpointService.GetByIP(item.CheckpointIP);
                IdentityDTO   identity   = null;
                if (!string.IsNullOrEmpty(item.GUID))
                {
                    identity = identityService.GetByGUID(item.GUID);
                }
                else
                {
                    return(BadRequest());
                }
                if (identity != null)
                {
                    string picturePath = "/Content/uploads/" + identity.Picture;
                    int    code        = activityService.IsOk(checkpoint, identity);
                    switch (code)
                    {
                    case 200:
                        return(Ok(identity));

                    case 500:
                        return(Content(HttpStatusCode.BadRequest, "Permission denied"));

                    default:
                        return(Ok());
                    }
                }
                else
                {
                    return(Content(HttpStatusCode.BadRequest, "Object does not exist"));
                }
            }
            return(BadRequest());
        }
예제 #11
0
        /// <summary>
        /// Implements <see cref="IActivityService.IsOk(CheckpointDTO, IdentityDTO)()"/>.
        /// </summary>
        public int IsOk(CheckpointDTO checkpoint, IdentityDTO identity)
        {
            Type checkpointType = Database.Type.Get(checkpoint.Type.ID);

            /* Codes:
             * -1 -- Ok. No response
             * 200 -- Ok. Return response
             * 500 -- Fail. Permission denied */
            switch (checkpointType.Status)
            {
            case "Пропускной":
                if (IsPassed(identity.GUID))
                {
                    Create(new Activity
                    {
                        CheckpointIP = checkpoint.IP,
                        Date         = System.DateTime.Now,
                        IdentityGUID = identity.GUID,
                        ModeID       = 3,
                        Status       = true
                    });
                    return(-1);
                }
                else
                {
                    if (IsAdmission(checkpoint.ID, identity.Role))
                    {
                        Create(new Activity
                        {
                            CheckpointIP = checkpoint.IP,
                            Date         = System.DateTime.Now,
                            IdentityGUID = identity.GUID,
                            ModeID       = 1,
                            Status       = true
                        });
                        return(200);
                    }
                    return(500);
                }

            case "Лекционный":
                if (IsInClassroom(identity.GUID))
                {
                    Create(new Activity
                    {
                        CheckpointIP = checkpoint.IP,
                        Date         = System.DateTime.Now,
                        IdentityGUID = identity.GUID,
                        ModeID       = 5,
                        Status       = true
                    });
                    return(-1);
                }
                else
                {
                    Create(new Activity
                    {
                        CheckpointIP = checkpoint.IP,
                        Date         = System.DateTime.Now,
                        IdentityGUID = identity.GUID,
                        ModeID       = 4,
                        Status       = true
                    });
                    return(-1);
                }

            default:
                Create(new Activity
                {
                    CheckpointIP = checkpoint.IP,
                    Date         = System.DateTime.Now,
                    IdentityGUID = identity.GUID,
                    ModeID       = 3,
                    Status       = true
                });
                return(-1);
            }
        }