コード例 #1
0
        public async Task <ActionResult <Resource> > ChangePassword([FromBody] ChangePasswordDto changePassword)
        {
            var spec     = new ResourceByEmailSpecification(changePassword.Email, changePassword.Password);
            var resource = await _resourcesRepo.GetEntityWithSpec(spec);

            if (resource == null)
            {
                return(BadRequest("Old password not match"));
            }
            resource.Password = changePassword.NewPassword;
            _unitOfWork.Repository <Resource>().Update(resource);
            await _unitOfWork.Complete();

            return(Ok(resource));
        }
コード例 #2
0
        public async Task <ActionResult <UserDto> > Login([FromBody] LoginDto loginDto)
        {
            var spec     = new ResourceByEmailSpecification(loginDto.Email);
            var resource = await _resourcesRepo.GetEntityWithSpec(spec);

            if (resource == null)
            {
                return(Unauthorized("Unauthorize user"));
            }
            if (loginDto.Password != resource.Password)
            {
                return(BadRequest("Password not match"));
            }
            return(new UserDto
            {
                Token = _tokenService.CreateToken(resource),
                Email = resource.Email,
                DisplayName = resource.Name
            });
        }