Exemplo n.º 1
0
        public ActionResult SignUp(SignupUser model)
        {
            if (ModelState.IsValid)
            {
                var anyUser = _userRepository.GetAll().Any(p => p.Email.Equals(model.Email));
                if (anyUser)
                {
                    return View();
                }

                Regex rgx = new Regex("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$");
                if (!rgx.IsMatch(model.Email))
                {
                    return View();
                }

                anyUser = _userRepository.GetAll().Any(p => p.FullName.Equals(model.FullName));
                if (anyUser)
                {
                    return View();
                }

                if (!model.Password.Equals(model.ConfirmPassword))
                {
                    return View();
                }

                _userRepository.Insert(new User { FullName = model.FullName, Email = model.Email, Password = model.Password });
                _userRepository.SaveChanges();

                LoginUser login = new LoginUser()
                {
                    Email = model.Email,
                    Password = model.Password,
                    RememberMe = true
                };
                Login(login, "");
            }
            return View();
        }
Exemplo n.º 2
0
        public ActionResult Login(LoginUser model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = _investContext.Auth.Login(model.Email, model.Password, model.RememberMe);

                if (user != null)
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Имя пользователя или пароль является не корректным.");
                }
            }

            return View(model);
        }