public void CreateInvalidModel()
        {
            var controller = new UserController(new UserBLL(new UserServiceStub()));
            var User = new User();
            controller.ModelState.AddModelError("FirstName", "");

            var actionResult = (ViewResult)controller.Create(User);
            Assert.AreEqual(actionResult.ViewName, "");
        }
 public ActionResult Login(User user)
 {
     user.Email = user.Email.ToLower();
     if (Membership.ValidateUser(user.Email, user.Password) && db.UserDb.GetAll().First(x=>x.Email == user.Email).IsRegister)
     {
         FormsAuthentication.SetAuthCookie(user.Email, true);
         return RedirectToAction("Index", "Home", new { area = "Common" , message = "Вы успешно вошли в систему!"});
     }
     return RedirectToAction("Login", "Security", new {area = "Security", message = "Оишбка входа!"});
 }
示例#3
0
 public bool Update(User user)
 {
     try
     {
         user.Password = PasswordHasher.HashPassword(user.Password);
         userDb.Update(user);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 public ActionResult Registration(User user)
 {
     try
     {
         user.Email = user.Email.ToLower();
         ViewBag.Msg = db.UserDb.Insert(user);
     }
     catch (Exception)
     {
         return RedirectToAction("Index", "Home", new { area = "Common", message = ViewBag.Msg });
     }
     return RedirectToAction("Index", "Home", new { area = "Common", message = ViewBag.Msg});
 }
示例#5
0
 public bool Insert(User user)
 {
     try
     {
         userDb.GetAll().First(x => x.Email == user.Email);
         return false;
     }
     catch (InvalidOperationException)
     {
         user.RegisterDate = DateTime.Now;
         user.IsDeleted = false;
         user.IsRegister = false;
         user.RoleId = 2;
         user.Password = PasswordHasher.HashPassword(user.Password);
         userDb.Insert(user);
         return true;
     }
 }
        public ActionResult Login(User user)
        {
            try
            {

                if (PasswordUtility.CheckUsedPasswordAgainstHashed(user.Email, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.Email, false);

                    Session.Add("UserId", user.UserID);
                    return SetSessionMessage(RedirectToAction("Index", "Home", new { area = "Common" }),SESSIONMESSAGE.SUCCESS,"Login was successfull!");
                }
                else
                {
                    return SetSessionMessage(View(user), SESSIONMESSAGE.FAIL, "You did not supply correct information. Please try again.");
                }
            }
            catch (Exception)
            {
                return SetSessionMessage(RedirectToAction("Login"), SESSIONMESSAGE.SUCCESS, "You are now logged in.");
            }
        }
示例#7
0
        public User createUserAndUpdateRole(User User)
        {
            using (var UserService = new UserBLL())
            {
                var RoleService = new UserRoleBLL();
                int roleId = 0;
                try
                {
                    roleId = RoleService.GetList().Where(x => x.RoleStringId == "C").FirstOrDefault().RoleId;
                    User.RoleId = roleId;
                }
                catch (Exception)
                {
                    Role newRole = RoleService.Insert(new Role { RoleStringId = "C", RoleName = "Customer" });
                    User.RoleId = newRole.RoleId;
                }

                User.RoleStringId = "C";
                User.Password = PasswordUtility.HashMyPassword(User.Password);
                return UserService.Insert(User);
            }
        }
        public void CreateValidModel()
        {
            var controller = new UserController(new UserBLL(new UserServiceStub()));
            var User = new User
            {
                UserID = 1,
                FirstName = "Espen",
                LastName = "Zaal",
                Address = "Osloveien 123",
                PostCode = "1234",
                PostAddress = "Oslo",
                Email = "*****@*****.**",
                Orders = new List<Order>(),
                Password = "******",
                RoleId = 1,
                RoleStringId = "C",
                Telephone = "22334455"
            };

            var actionResult = (RedirectToRouteResult)controller.Create(User);
            Assert.AreEqual(actionResult.RouteName, "");
            Assert.IsTrue(actionResult.RouteValues.Values.Count == 1);
            Assert.AreEqual(actionResult.RouteValues.Values.First(), "Index");
        }
 public ActionResult EditProfile(User user)
 {
     db.UserDb.Update(user);
     return RedirectToAction("EditProfile");
 }
示例#10
0
        public void GetUserList()
        {
            var controller = new UserController(new UserBLL(new UserServiceStub()));
            var User = new User
            {
                UserID = 1,
                FirstName = "Espen",
                LastName = "Zaal",
                Address = "Osloveien 123",
                PostCode = "1234",
                PostAddress = "Oslo",
                Email = "*****@*****.**",
                Orders = new List<Order>(),
                Password = "******",
                RoleId = 1,
                RoleStringId = "C",
                Telephone = "22334455"
            };
            List<User> forventet = new List<User>();
            forventet.Add(User);
            forventet.Add(User);
            forventet.Add(User);

            var actionResult = (ViewResult)controller.Index();
            var result = (List<User>)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");
            for(var i = 0; i < forventet.Count; i++)
            {
                Assert.AreEqual(forventet[i].UserID, result[i].UserID);
                Assert.AreEqual(forventet[i].FirstName, result[i].FirstName);
                Assert.AreEqual(forventet[i].LastName, result[i].LastName);
                Assert.AreEqual(forventet[i].Address, result[i].Address);
                Assert.AreEqual(forventet[i].PostCode, result[i].PostCode);
                Assert.AreEqual(forventet[i].PostAddress, result[i].PostAddress);
                Assert.AreEqual(forventet[i].Email, result[i].Email);
                Assert.AreEqual(forventet[i].Password, result[i].Password);
                Assert.AreEqual(forventet[i].RoleId, result[i].RoleId);
                Assert.AreEqual(forventet[i].RoleStringId, result[i].RoleStringId);
                Assert.AreEqual(forventet[i].Telephone, result[i].Telephone);
            }
        }