Esempio n. 1
0
        public async Task <IActionResult> Login(GirisCO request)
        {
            KullaniciDTO user = _kullaniciService.GetByKullanici(request.Email, request.Sifre);

            if (user == null)
            {
                return(View("Error"));
            }

            var giris = new GirisDTO()
            {
                KullaniciId = user.Id,
                Durum       = true,
                Aktif       = true,
                Silindi     = false
            };
            var girisId = _girisService.Create(giris);

            if (user != null)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, user.Id.ToString()),
                    new Claim(ClaimTypes.NameIdentifier, user.Ad + " " + user.Soyad),
                    new Claim(ClaimTypes.Role, user.YetkiId.ToString())
                };

                var userIdentity = new ClaimsIdentity(claims, "login");

                ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
                await HttpContext.SignInAsync(principal);

                if (user.YetkiId == (int)Yetkiler.ADMIN)
                {
                    ViewBag.User = user;
                    return(RedirectToAction("Index", "Admin"));
                }

                if (user.YetkiId == (int)Yetkiler.TEACHER)
                {
                    ViewBag.User = user;
                    return(RedirectToAction("Index", "Home"));
                }

                ViewBag.User = user;
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }