Beispiel #1
0
        private static void CreateLogon(long userId, int userTypeId, bool rememberPassword)
        {
            using (DataAccess db = new DataAccess())
            {
                var newLogon = new WebLogon()
                {
                    UserId          = userId,
                    UserTypeId      = userTypeId,
                    Token           = Guid.NewGuid().ToString(),
                    TokenExpiryDate = DateTime.Now.AddMonths(1),
                    IPAddress       = HttpContext.Current.Request.UserHostAddress,
                    DateLogon       = DateTime.Now
                };

                db.WebLogons.Add(newLogon);
                db.SaveChanges();

                CookieHelper.DeleteAuthCookie();
                if (rememberPassword)
                {
                    CookieHelper.SetAuthCookie(userId, userTypeId, newLogon.Token);
                }
                else
                {
                    CookieHelper.SetAuthCookie(userId, userTypeId, string.Empty);
                }
                HttpContext.Current.Session["UserId"]     = userId;
                HttpContext.Current.Session["UserTypeId"] = userTypeId;
            }
        }
Beispiel #2
0
 public static void DeleteOldLogons(long userId, int userTypeId)
 {
     //删除所有旧登陆记录
     CookieHelper.DeleteAuthCookie();
     using (DataAccess db = new DataAccess())
     {
         db.WebLogons.Where(r => r.UserId == userId && r.UserTypeId == userTypeId).ToList().ForEach(r => db.WebLogons.Remove(r));
         db.SaveChanges();
     }
 }