Exemplo n.º 1
0
        public void TestUserCreation()
        {
            using (var storage = new Storage())
            {
                var adminEmail = "*****@*****.**";
                if (storage.Users.Get(x => x.Email == adminEmail) != null)
                {
                    return;
                }

                var user = new UserEntity
                {
                    Email               = adminEmail,
                    Name                = "Павел П",
                    PasswordHash        = PasswordUtil.GetHash("password"),
                    LastChangedByUserId = 1
                };

                storage.Users.Save(user);

                var newUser = storage.Users.Get(x => x.Email == adminEmail);
                Assert.IsTrue(newUser != null);
                Assert.IsTrue(newUser.UserId > 0);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult ChangeAccountInfo([FromBody] ChangeUserInfoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception(ConvertToErrorMessage(ModelState));
            }

            var currentUser = Storage.Users.GetById(CurrentUser.UserId);

            if (currentUser.PasswordHash != PasswordUtil.GetHash(model.OldPassword))
            {
                throw new Exception("Старый пароль не верный");
            }



            currentUser.Email        = model.Email;
            currentUser.Name         = model.Email.Split('@')[0];
            currentUser.PasswordHash = PasswordUtil.GetHash(model.NewPassword);

            Storage.Users.Save(currentUser);

            return(Ok());
        }