public ActionResult LoginOgrenci(LoginOgrenci model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                //Yapılan giriş kullanıcı listesinde bulunuyorsa ve rolü öğrenciyse giriş geçerlidir. Aksi taktirde hatalı giriş uyarısı gözükecektir.
                var user = userManager.Find(model.OgrenciNo, model.Sifre);
                if (user != null)
                {
                    var roles = userManager.GetRoles(user.Id);

                    if (roles.Count(i => i == "Ogrenci") != 0)
                    {
                        var authManager = HttpContext.GetOwinContext().Authentication;

                        var identity       = userManager.CreateIdentity(user, "ApplicationCookie");
                        var authProperties = new AuthenticationProperties()
                        {
                            IsPersistent = true
                        };
                        authManager.SignOut();
                        authManager.SignIn(authProperties, identity);

                        return(RedirectToAction("OgrenciBilgisi", "home", new { area = "Ogrenci" }));
                    }
                    else
                    {
                        ModelState.AddModelError("error", "Yanlış Kullanıcı Adı veya Şifre");
                    }
                }
                else
                {
                    ModelState.AddModelError("error", "Yanlış Kullanıcı Adı veya Şifre");
                }
            }

            ViewBag.returnUrl = returnUrl;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult LoginOgrenci(LoginOgrenci model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = userManager.Find(model.OgrenciNo, model.Sifre);
                if (user != null)
                {
                    var roles = userManager.GetRoles(user.Id);

                    if (roles.Count(i => i == "Ogrenci") != 0)
                    {
                        var authManager = HttpContext.GetOwinContext().Authentication;

                        var identity       = userManager.CreateIdentity(user, "ApplicationCookie");
                        var authProperties = new AuthenticationProperties()
                        {
                            IsPersistent = true
                        };
                        authManager.SignOut();
                        authManager.SignIn(authProperties, identity);

                        return(RedirectToAction("index", "home", new { area = "Ogrenci" }));
                    }
                    else
                    {
                        ModelState.AddModelError("error", "Yanlış Kullanıcı Adı veya Şifre");
                    }
                }
                else
                {
                    ModelState.AddModelError("error", "Yanlış Kullanıcı Adı veya Şifre");
                }
            }

            ViewBag.returnUrl = returnUrl;
            return(View(model));
        }