Пример #1
0
        public bool ContainsUser(UserModel usermodel)
        {
            foreach (User item in GetUsers())
            {
                if (item.Email.Equals(usermodel.Email) && item.Password.Equals(usermodel.Password))
                {
                    return true;
                }
            }

            return false;
        }
Пример #2
0
        public ActionResult Signup(UserModel user)
        {
            if (ModelState.IsValid)
            {
                if(_repository.AddUser(user))
                {
                    if (user.Password != user.RepeatPassword)
                    {
                        ViewBag.Title = "Password doesn't match!";
                        return View(user);
                    }
                    return View("Information", user);
                }
            }

            ViewBag.Title = "Email is already in use!";
            return View(user);
        }
Пример #3
0
        public ActionResult Login(UserModel user)
        {
            if (ModelState.IsValid)
            {

                if(_repository.IsValid(user.Email, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.Email, false);
                    return RedirectToAction("Index", "Employee");
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect.");
                }

            }

            return View(user);
        }
Пример #4
0
        public bool AddUser(UserModel user)
        {
            if(context.Users.FirstOrDefault(email => email.Email.Equals(user.Email)) == null)
            {
                var crypto = new SimpleCrypto.PBKDF2();

                var encrPass = crypto.Compute(user.Password);

                User userToSave = context.Users.Create();

                userToSave.Email = user.Email;
                userToSave.Password = encrPass;
                userToSave.PasswordSalt = crypto.Salt;
                userToSave.UserId = Guid.NewGuid();

                context.Users.Add(userToSave);
                context.SaveChanges();

                return true;
            }

            return false;
        }