Esempio n. 1
0
        public IActionResult Index(string pageInfo = null)
        {
            //HttpContext.Session.Clear();

            //LoginInfo.SetLoginUser(string.Empty, string.Empty);
            HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            using (var def = new DoctorContext())
            {
                var loadUsers = (from u in def.Users
                                 where u.LeaveDate >= DateTime.Now ||
                                 u.LeaveDate.Equals(DateTime.Parse("1900-01-01"))
                                 select u).ToList();
                UsersInfo.SetUsers(loadUsers);
                var users = new LoginIndexViewModel()
                {
                    Users = (from u in UsersInfo.Users
                             select new SelectListItem()
                    {
                        Text = u.UserName,
                        Value = u.UserNo,
                        Selected = false
                    }).ToList()
                };
                if (!string.IsNullOrEmpty(pageInfo))
                {
                    ModelState.AddModelError("PageInfo", pageInfo);
                }
                return(View(users));
            }
        }
Esempio n. 2
0
        public ActionResult LoginIndex(LoginIndexViewModel viewModel)
        {
            bool check = AccountBL.GetLogin(viewModel);

            if (check)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(Json(FJMessage.LoginErrorMessage, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public bool GetLogin(LoginIndexViewModel viewModel)
        {
            Account table = AdapterFJRepository.AccountRepository
                            .GetSingle(p => p.AccountUser == viewModel.Account && p.Password == viewModel.Password);

            SessionModel.LoginDate = new LoginModel()
            {
                AccountUser  = table.AccountUser,
                IdentityCode = table.IdentityCode,
                UserName     = table.UserName
            };
            if (table != null)
            {
                return(true);
            }
            return(false);
        }
        //Logika trazenja korisnika u bazi nakon unosa username i pw u Index Viewu.
        public IActionResult Index(LoginIndexViewModel vm)
        {
            //Trazenje korisnika u bazi

            Korisnik korisnik = new Klijenti();

            korisnik = _db.Korisnici.FirstOrDefault(x => x.username == vm.username && x.password == vm.password);
            if (korisnik != null)
            {
                //Ako je korisnik verifikovao email
                if (korisnik.isValid)
                {
                    HttpContext.SetLogiraniKorisnik(korisnik, vm.Remember);
                    if (korisnik.Zanimanje == "Student" || korisnik.Zanimanje == "Penzioner")
                    {
                        //Castovanje u klijenta
                        var    klijent   = korisnik as Klijenti;
                        string zanimanje = klijent.Zanimanje;
                        bool   isStudent = false;

                        //Provjera zanimanja i slike
                        isStudent = zanimanje == "Student" ? true : false;
                        if (isStudent)
                        {
                            if (klijent.slikaIndeksa == null)
                            {
                                ViewBag.KorisnikId = korisnik.Id;
                                return(PartialView("_Verifikacija"));
                            }
                        }
                        else
                        {
                            if (klijent.slikaPenzionerskeKartice == null)
                            {
                                ViewBag.KorisnikId = korisnik.Id;
                                return(PartialView("_Verifikacija"));
                            }
                        }
                    }
                    return(PartialView("_Pocetna"));
                }
            }
            return(PartialView("_FailureLogin"));
        }
        public async Task <ActionResult> Index(LoginIndexViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            var result = await _loginManager.PasswordSignInAsync(
                viewModel.Email, viewModel.Password, viewModel.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToAction("Index", "Home"));

            case SignInStatus.Failure:
                ModelState.AddModelError("Incorrect Login", "Email or password is incorrect");
                return(View(viewModel));

            default:
                throw new Exception("Unexpected Log In status");
            }
        }
        public IActionResult Index(bool expired)
        {
            if (this.AuthorizationLogic.IsLoggedIn)
            {
                return(RedirectToAction("Index", "VaultExplorer"));
            }

            var repository = VaultRepositoryFactory.CreateInstance();
            var vaults     = repository.GetAllVaultNames();

            if (vaults.Count() == 0)
            {
                return(RedirectToAction("Create", "Vault"));
            }

            var viewModel = new LoginIndexViewModel()
            {
                VaultNames = vaults,
                Expired    = expired
            };

            return(View(viewModel));
        }
        public IActionResult Validate(LoginIndexViewModel model)
        {
            var repository = VaultRepositoryFactory.CreateInstance();

            if (ModelState.IsValid)
            {
                using (var masterPasswordSecure = SecureStringConverter.ToSecureString(model.MasterPassword))
                {
                    if (repository.IsPasswordValid(model.SelectedVault, masterPasswordSecure))
                    {
                        this.SessionContext.SetCurrentVaultName(model.SelectedVault);
                        this.SessionContext.SetMasterPassword(masterPasswordSecure);
                        return(RedirectToAction("Index", "VaultExplorer"));
                    }
                    else
                    {
                        ModelState.AddModelError(nameof(model.MasterPassword), StringResources.IncorrectPassword);
                    }
                }
            }

            model.VaultNames = repository.GetAllVaultNames();
            return(View("Index", model));
        }
        public IActionResult Index()
        {
            var viewModel = new LoginIndexViewModel();

            return(View(viewModel));
        }
Esempio n. 9
0
        public async Task <IActionResult> Index(LoginIndexViewModel loginIndexViewModel)
        {
            using (var def = new DoctorContext())
            {
                if (loginIndexViewModel.UserNo != null)
                {
                    //var user = await def.Users.FindAsync(loginIndexViewModel.UserNo);
                    var user = (from u in UsersInfo.Users
                                where u.UserNo.Equals(loginIndexViewModel.UserNo)
                                select u).FirstOrDefault();
                    string inputPassword = string.IsNullOrEmpty(loginIndexViewModel.Password) ? string.Empty : loginIndexViewModel.Password;
                    string dbPassword    = string.IsNullOrEmpty(user.Pass) ? string.Empty : user.Pass;
                    if (inputPassword.Equals(dbPassword))
                    {
                        //SessionUserViewModel sessionUserViewModel = new SessionUserViewModel()
                        //{
                        //    UserNo = user.UserNo,
                        //    UserName = user.UserName
                        //};
                        //await HttpContext.Session.SetAsync("User", sessionUserViewModel);

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.NameIdentifier, user.UserNo),
                            new Claim("DisplayName", user.UserName)
                        };

                        var claimsIdentity = new ClaimsIdentity(
                            claims,
                            CookieAuthenticationDefaults.AuthenticationScheme);

                        var authProperties = new AuthenticationProperties
                        {
                            IsPersistent = true
                        };

                        await HttpContext.SignInAsync(
                            CookieAuthenticationDefaults.AuthenticationScheme,
                            new ClaimsPrincipal(claimsIdentity),
                            authProperties);

                        //LoginInfo.SetLoginUser(claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value, claimsIdentity.FindFirst("DisplayName").Value);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("Password", "密碼錯誤");
                    }
                }
                else
                {
                    ModelState.AddModelError("Account", "請選擇帳號");
                }
                loginIndexViewModel.Users = (from u in UsersInfo.Users
                                             select new SelectListItem()
                {
                    Text = u.UserName,
                    Value = u.UserNo,
                    Selected = false
                }).ToList();
                return(View(loginIndexViewModel));
            }
        }