Ejemplo n.º 1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                string InitialURL = Request.Url.AbsoluteUri;
                if (InitialURL.IndexOf("Ticket") == -1)
                {
                    string Url = ConfigurationManager.AppSettings["YetkiGirisSayfasi"] + "?ReturnUrl=" +
                                  Request.Url.GetLeftPart(UriPartial.Path).Replace("http:", "http://").Replace("////", "//") +
                                 "&UN=" +
                                 ConfigurationManager.AppSettings["YetkiProjeUN"];
                    Response.Redirect(Url, true);
                }
                else//Yani ticket i alıp döndü isek
                {
                    //Burada kullanıcıyı otantike etmemiz gereki artık
                    using (YetkiServisSoapClient client = new YetkiServisSoapClient())
                    {
                        KullaniciDataSet dsKullanici = client.TicketGetir(Md5Sifreleme(Request["Ticket"].ToString()));
                        //ukarkin   :   daadfacd-f637-446f-91ca-cf789caf4ba3
                        //iakcan    :   67e395d3-ad0e-442f-8f9d-e770910a2e6b
                        Guid KullaniciUN = Guid.Parse(dsKullanici.Tables[0].Rows[0]["KullaniciUN"].ToString());
                        string Adi = dsKullanici.Tables[0].Rows[0]["Adi"].ToString();
                        string Soyadi = dsKullanici.Tables[0].Rows[0]["Soyadi"].ToString();
                        string KullaniciAdi = dsKullanici.Tables[0].Rows[0]["KullaniciAdi"].ToString();
                        string SicilNo = dsKullanici.Tables[0].Rows[0]["SicilNo"].ToString();
                        string Eposta = dsKullanici.Tables[0].Rows[0]["Eposta"].ToString();
                        string ActivationKey = dsKullanici.Tables[0].Rows[0]["ActivationKey"].ToString();
                        Guid BirimUN = Guid.Parse(dsKullanici.Tables[0].Rows[0]["BirimUN"].ToString());

                        #region CookieOlustur

                        /*
                        MenuDataSet dsMenu = client.KullaniciYetkiliMenulerGetir(KullaniciUN, _projectUN);
                        int RolSayisi=dsMenu.Tables[0].Rows.Count;
                        string[] _roller = new string[RolSayisi];
                        if(RolSayisi>0)
                        {
                            int Sayac=0;

                            foreach (DataRow row in dsMenu.Tables[0].Rows)
                            {
                                _roller[Sayac]=row["MenuAdi"].ToString();
                                Sayac++;
                            }
                        }
                        */

                        YetkiDataSet dsProjeUzerindeKullaniciYetkileri = client.KullaniciYetkilerGetir(KullaniciUN, _projectUN);
                        int YetkiSayisi = dsProjeUzerindeKullaniciYetkileri.Tables[0].Rows.Count;

                        string[] _yetkiler = new string[YetkiSayisi];
                        if (YetkiSayisi > 0)
                        {
                            int Sayac = 0;
                            foreach (DataRow row in dsProjeUzerindeKullaniciYetkileri.Tables[0].Rows)
                            {
                                _yetkiler[Sayac] = row["YetkiAdi"].ToString();
                                Sayac++;
                            }
                        }

                        App_Start.User usr = new User();
                        usr.KullaniciUN = KullaniciUN;
                        usr.Name = Adi;
                        usr.Username = KullaniciAdi;
                        usr.Age = 44;
                        usr.EPosta = Eposta;
                        usr.Roller = _yetkiler;

                        var serializer = new JavaScriptSerializer();

                        string userData = serializer.Serialize(usr);

                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                            usr.Username,
                            DateTime.Now,
                            DateTime.Now.AddDays(30),
                            true,
                            userData,
                            FormsAuthentication.FormsCookiePath);

                        // Encrypt the ticket.
                        string encTicket = FormsAuthentication.Encrypt(ticket);

                        // Create the cookie.

                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        RedirectToAction("Index", "IsEmris");
                        //}
                        #endregion CookieOlustur
                    }

                }
            }
        }
Ejemplo n.º 2
0
        /*
        /// <summary>
        /// Authenticates a user against a database, web service, etc.
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <returns>User</returns>
        public static User AuthenticateUser(string username, string password)
        {
            User user = null;

            // Lookup user in database, web service, etc. We'll just generate a fake user for this demo.
            if (username == "john" && password == "doe")
            {
                user = new User { Id = 123, Name = "John Doe", Username = "******", Age = 21 };
            }

            return user;
        }
         */
        /// <summary>
        /// Authenticates a user against a database, web service, etc.
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <returns>User</returns>
        public static User AuthenticateUser(string username, string password)
        {
            User user = null;
            using (YetkiServisSoapClient client = new YetkiServisSoapClient())
            {
                KullaniciDataSet dsKullaniciDataSet = client.KullaniciGiris(username, password);
                if (dsKullaniciDataSet.Tables[0].Rows.Count > 0)
                {
                    user = new User
                    {
                        KullaniciUN = Guid.Parse(dsKullaniciDataSet.Tables[0].Rows[0]["KullaniciUN"].ToString()),
                        Name = dsKullaniciDataSet.Tables[0].Rows[0]["Adi"].ToString() + " " + dsKullaniciDataSet.Tables[0].Rows[0]["Soyadi"].ToString(),
                        Username = dsKullaniciDataSet.Tables[0].Rows[0]["KullaniciAdi"].ToString(),
                        Age = 21,
                        EPosta = dsKullaniciDataSet.Tables[0].Rows[0]["EPosta"].ToString()
                    };
                    //KullaniciOturumDataSet dsKullaniciOturumDataSet= client.KullaniciOturumGetir(user.KullaniciUN, Guid.Parse("20cca136-e571-4cbb-8ec3-7ea233df2b49"), 0,ref string HataVar);
                }
            }
            return user;
        }