public static void Login(User user, HttpContextBase context)
        {

            using (EPDataContext dbContext = new EPDataContext())
            {
                SessionUser userSession = new SessionUser()
                {
                    CreateDT = DateTime.Now,
                    Id = Guid.NewGuid(),
                    IsDeleted = false,
                    LastActivityDT = DateTime.Now,
                    LoginDT = DateTime.Now,
                    ModifiedDT = DateTime.Now,
                    RemoteIP = context.Request.ServerVariables["REMOTE_ADDR"],
                    UserId = user.Id,
                    Status = UserLoginStatus.Active.ToString()

                };
                dbContext.SessionUsers.Add(userSession);
                dbContext.SaveChanges();

                HttpCookie cookie = new HttpCookie(SESSION_ID, userSession.Id.ToString());
                context.Response.AppendCookie(cookie);

            }
        }
Example #2
0
 public ActionResult Reg(User user)
 {
     if (!String.IsNullOrEmpty(user.UserName) && !String.IsNullOrEmpty(user.Password))
     {
         if (DbContext.Users.SingleOrDefault(t => t.UserName == user.UserName) == null)
         {
             user.UserType = UserType.User.ToString();
             DbContext.Users.Add(user);
             DbContext.SaveChanges();
             return new ContentResult() { Content = "true" };
         }
         else
         {
             return new ContentResult() { Content = "该用户名已存在" };
         }
     }
     else
     {
         return new ContentResult() { Content = "用户名和密码不得为空" };
     }
 }