示例#1
0
        public ActionResult Register(KayitKalibi model)
        {
            HttpResponseMessage result = WebApiCagirici.postFonksiyonuCagir("kullanicilar/kullaniciekle", serializer.Serialize(model));

            if (result.IsSuccessStatusCode)
            {
                return(RedirectToAction("Login"));
            }
            else if (result.StatusCode == System.Net.HttpStatusCode.Conflict)
            {
                ModelState.AddModelError("", "Eposta veya kullanıcı adı zaten kullanılıyor.");
            }

            return(View(model));
        }
示例#2
0
        public ActionResult Login(GirisKalibi model, string returnUrl)
        {
            /*
             * if (ModelState.IsValid)
             * {
             *
             *
             *  var user = userManager.Find(model.kullaniciadi, model.sifre);
             *
             *  if (user == null)
             *  {
             *      ModelState.AddModelError("", "Yanlış kullanıcı adı veya parola");
             *
             *  }
             *  else
             *  {
             *      var authManager = HttpContext.GetOwinContext().Authentication; //Login işlemini veya logout işlemini yapan nesne
             *
             *      var identity = userManager.CreateIdentity(user, "ApplicationCookie"); // Cookie - Cookie yi authManager aracılığıyla gönderiyoruzz
             *
             *      var authProperties = new AuthenticationProperties()
             *      {
             *          IsPersistent = true
             *
             *      };
             *
             *      authManager.SignOut();
             *      authManager.SignIn(authProperties, identity);
             *
             *      return Redirect(string.IsNullOrEmpty(returnUrl) ? "/" : returnUrl);
             *
             *  }
             * }*/

            HttpResponseMessage result = WebApiCagirici.postFonksiyonuCagir("kullanicilar/kullanicidogrula", serializer.Serialize(model));

            if (result.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                ModelState.AddModelError("", "Yanlış kullanıcı adı veya parola");
            }
            else if (result.IsSuccessStatusCode)
            {
                var authManager = HttpContext.GetOwinContext().Authentication; //Login işlemini veya logout işlemini yapan nesne

                var user = userManager.Find(model.kullaniciadi, model.sifre);

                var identity = userManager.CreateIdentity(user, "ApplicationCookie"); // Cookie - Cookie yi authManager aracılığıyla gönderiyoruzz

                var authProperties = new AuthenticationProperties()
                {
                    IsPersistent = true
                };

                authManager.SignOut();
                authManager.SignIn(authProperties, identity);

                return(Redirect(string.IsNullOrEmpty(returnUrl) ? "/" : returnUrl));
            }

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