Exemplo n.º 1
0
        public void Untampered_hash_matches_the_text()
        {
            // Arrange
            var userAccount = new UserAccount()
            {
                Name         = "Destination",
                EmailAddress = "*****@*****.**",
                Salt         = "salt",
                Hash         = "hash"
            };

            var updateModel = new UserAccountUpdateModel()
            {
                Name         = "Source",
                EmailAddress = "",
                Password     = "******"
            };

            // Act
            ModelUpdater.CopyProperties(updateModel, userAccount);

            bool match = true;

            // Assert
            Assert.True(match);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateOrganisation(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "organisation")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(UpdateOrganisation) processed a request.");

            var accessTokenResult = _tokenProvider.ValidateToken(req);

            if (accessTokenResult.Status == AccessTokenStatus.Valid)
            {
                try
                {
                    Guid userAccountId  = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "UserAccount").Value);
                    Guid organisationId = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "Organisation").Value);

                    string requestBody             = await new StreamReader(req.Body).ReadToEndAsync();
                    var    organisationUpdateModel = JsonConvert.DeserializeObject <OrganisationCreateModel>(requestBody);

                    var organisationRepo = new OrganisationRepository();
                    var organisation     = organisationRepo.GetOrganisationById(organisationId);

                    ModelUpdater.CopyProperties(organisationUpdateModel, organisation);

                    bool updated = organisationRepo.UpdateOrganisation(organisation);

                    return(new OkObjectResult("Updated"));
                }
                catch (Exception exception)
                {
                    return(new BadRequestObjectResult(exception.Message));
                }
            }
            else
            {
                return(new UnauthorizedResult());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateUserAccount(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "UserAccount/UpdateUserAccount")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(UpdateUserAccount) processed a request.");

            var accessTokenResult = _tokenProvider.ValidateToken(req);

            if (accessTokenResult.Status == AccessTokenStatus.Valid)
            {
                try
                {
                    var userAccountId = accessTokenResult.Principal.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
                    log.LogInformation($"JWT validated for UserAccount: {userAccountId}.");

                    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                    var    updateModel = JsonConvert.DeserializeObject <UserAccountUpdateModel>(requestBody);

                    var userAccountRepo = new UserAccountRepository();
                    var userAccount     = userAccountRepo.GetUserAccountById(new Guid(userAccountId));

                    ModelUpdater.CopyProperties(updateModel, userAccount);

                    bool updated = userAccountRepo.UpdateUserAccount(userAccount);

                    return(new OkObjectResult("Updated"));
                }
                catch (Exception exception)
                {
                    return(new BadRequestObjectResult(exception.Message));
                }
            }
            else
            {
                return(new UnauthorizedResult());
            }
        }
Exemplo n.º 4
0
 public virtual void Update(T entity, ICollection <KeyValuePair <string, string> > values)
 {
     ModelUpdater.UpdateModel <T>(entity, values, this.Context);
 }