Esempio n. 1
0
 /// <summary>
 /// Create a new Cooky object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="hashValue">Initial value of the HashValue property.</param>
 public static Cooky CreateCooky(global::System.Int32 id, global::System.Int32 userId, global::System.String hashValue)
 {
     Cooky cooky = new Cooky();
     cooky.Id = id;
     cooky.UserId = userId;
     cooky.HashValue = hashValue;
     return cooky;
 }
Esempio n. 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Cookies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCookies(Cooky cooky)
 {
     base.AddObject("Cookies", cooky);
 }
Esempio n. 3
0
        public HttpCookie CreateFormsAuthenticationCookie(OpenIdUser user)
        {
            Random rand = new Random();
            int randomInt = rand.Next(0, int.MaxValue);
            string hashValue = MD5Encryptor.GetHash(randomInt.ToString());

            using (CookiesRepository cookiesRep = new CookiesRepository())
            {
                Cooky existingCookie = cookiesRep.GetList().FirstOrDefault(x => x.UserId == user.UserId);

                if (existingCookie != null)
                {
                    if (cookiesRep.Delete(existingCookie.Id) == false)
                        return null;
                }
                Cooky newCookie = new Cooky()
                {
                    UserId = user.UserId,
                    HashValue = hashValue
                };

                if (cookiesRep.Create(newCookie) == false)
                    return null;
            }

            //var ticket = new FormsAuthenticationTicket(1, user.FullName, DateTime.Now, DateTime.Now.AddDays(7), true, user.GetCookieString(hashValue));
            //var encrypted = FormsAuthentication.Encrypt(ticket).ToString();
            var cookie = new HttpCookie(LOGIN_COOKIE_NAME, user.GetCookieString(hashValue));
            return cookie;
        }