Exemplo n.º 1
0
        public ActionResult Register(ViewModelAppUser viewModelAppUser)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register", "Login"));
            }
            else
            {
                UnitOfWork unitOfWork = new UnitOfWork();
                AppUser    appUser    = unitOfWork.AppUser.Find(x => x.UserEmail == viewModelAppUser.UserEmail && x.UserPassword == viewModelAppUser.UserPassword).FirstOrDefault();

                if (appUser is null)
                {
                    AppUser appUserTemp = new AppUser()
                    {
                        UserEmail        = viewModelAppUser.UserEmail,
                        UserPassword     = viewModelAppUser.UserPassword,
                        IsEmailActivated = false,
                        IsPassive        = false,
                        UserRole         = 1,
                    };

                    unitOfWork.AppUser.Add(appUserTemp);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Register", "Login", viewModelAppUser));
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Login(ViewModelAppUser viewModelAppUser)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", "Login"));
            }
            else
            {
                UnitOfWork unitOfWork = new UnitOfWork();
                AppUser    appUser    = unitOfWork.AppUser.Find(x => x.UserEmail == viewModelAppUser.UserEmail && x.UserPassword == viewModelAppUser.UserPassword).FirstOrDefault();

                if (appUser is null)
                {
                    return(RedirectToAction("Index", "Login"));
                }
                else
                {
                    string     enc    = Encrypt.Encrypt_(appUser.UserEmail, appUser.UserPassword);
                    HttpCookie cookie = new HttpCookie("logedUser", enc);
                    Response.Cookies.Add(cookie);
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }