Example #1
0
        public void UpdateForumSession(string username, string sessionhash, int loggedin)
        {
            int forumUserId = 0;

            using (NtxfcDbContext db = new NtxfcDbContext())
            {
                Login login = db.Logins.FirstOrDefault(x => x.Username == username);
                if (login != null)
                {
                    forumUserId = login.ForumUserId;
                }
            }

            if (forumUserId != 0)
            {
                using (ExternalDbContext db = new ExternalDbContext())
                {
                    var session = db.Sessions.FirstOrDefault(x => x.sessionhash == sessionhash);
                    if (session != null)
                    {
                        session.loggedin = loggedin;
                        session.userid   = forumUserId;
                        db.Sessions.Attach(session);
                        db.Entry(session).Property(u => u.loggedin).IsModified = true;
                        db.Entry(session).Property(u => u.userid).IsModified   = true;
                        db.SaveChanges();
                    }
                }
            }
        }
Example #2
0
 public void DeleteForumCpSession(string hash)
 {
     using (ExternalDbContext db = new ExternalDbContext())
     {
         var session = db.CpSessions.FirstOrDefault(x => x.hash == hash);
         if (session != null)
         {
             db.CpSessions.Remove(session);
             db.SaveChanges();
         }
     }
 }
        private void CreateExternalSampleDatabase(string connectionStringName, string connString)
        {
            using (var context = new ExternalDbContext(connString))
            {
                context.Database.EnsureCreated();
                context.Database.Migrate();

                if (context.MyTable.Count() == 0)
                {
                    var myRecord = new MyTable
                    {
                        Data = connectionStringName
                    };

                    context.MyTable.Add(myRecord);

                    context.SaveChanges();
                }
            }
        }
Example #4
0
        public User CreateForumUser(User user, string activationid)
        {
            using (ExternalDbContext db = new ExternalDbContext())
            {
                db.Users.Add(user);
                db.SaveChanges();
            }

            using (ExternalDbContext db = new ExternalDbContext())
            {
                db.Database.ExecuteSqlCommand("INSERT INTO `vb3_userfield` (userid) VALUES(@userid)", new MySqlParameter("userid", user.userid));
                db.SaveChanges();
            }

            using (ExternalDbContext db = new ExternalDbContext())
            {
                db.Database.ExecuteSqlCommand("INSERT INTO `vb3_useractivation` (userid, activationid) VALUES(@userid,@activationid)", new MySqlParameter("userid", user.userid), new MySqlParameter("activationid", activationid));
                db.SaveChanges();
            }

            return(user);
        }
Example #5
0
        public string SaveForumSession(string username, string host, string useragent, string forwardedfor)
        {
            int forumUserId = 0;

            using (NtxfcDbContext db = new NtxfcDbContext())
            {
                Login login = db.Logins.FirstOrDefault(x => x.Username == username);
                if (login != null)
                {
                    forumUserId = login.ForumUserId;
                }
            }

            if (forumUserId != 0)
            {
                Session session = new Session();
                session.sessionhash = Guid.NewGuid().ToString("N");
                session.userid      = forumUserId;
                session.host        = host;
                session.idhash      = CalculateMD5Hash(String.Concat(useragent, GetSubIP(GetRealIP(host, forwardedfor))));
                TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                session.lastactivity   = Convert.ToInt32(ts.TotalSeconds);
                session.location       = "/login.php";
                session.useragent      = useragent;
                session.loggedin       = 1;
                session.apiaccesstoken = string.Empty;

                using (ExternalDbContext db = new ExternalDbContext())
                {
                    db.Sessions.Add(session);
                    db.SaveChanges();
                }

                return(session.sessionhash);
            }

            return(string.Empty);
        }
Example #6
0
        public User ActivateUser(string username, string activationid)
        {
            User user;

            using (ExternalDbContext db = new ExternalDbContext())
            {
                user             = db.Users.FirstOrDefault(x => x.username == username);
                user.usergroupid = 2;
                db.Users.Attach(user);
                db.Entry(user).Property(u => u.usergroupid).IsModified = true;
                db.SaveChanges();
            }

            if (user != null)
            {
                using (ExternalDbContext db = new ExternalDbContext())
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM `vb3_useractivation` WHERE userid = @userid AND activationid = @activationid", new MySqlParameter("userid", user.userid), new MySqlParameter("activationid", activationid));
                    db.SaveChanges();
                }
            }

            return(user);
        }