예제 #1
0
        public void registration()
        {
            String login, passwd, username, surname, email;

            login    = binRead.ReadString();
            passwd   = binRead.ReadString();
            username = binRead.ReadString();
            surname  = binRead.ReadString();
            email    = binRead.ReadString();

            using (var dc = new PTMessengerEntitiesModel())
            {
                var log_count = (from l in dc.TUsers
                                 where l.TUsers_login == login
                                 select l).Count();
                if (log_count > 0)
                {
                    binWrite.Write("LOGIN_EXIST");
                    Console.WriteLine("{0} Nowy uzytkownik chcial uzyc istniejacego loginu {1}", DateTime.Now, login);
                    return;
                }
            }

            var newUser = new TUsers();

            newUser.TUser_imie     = username;
            newUser.TUser_nazwisko = surname;
            newUser.TUsers_login   = login;
            newUser.TUsers_passwd  = passwd;
            newUser.TUsers_email   = email;
            newUser.TUser_lock     = false;
            try
            {
                using (var dc = new PTMessengerEntitiesModel())
                {
                    dc.TUsers.Add(newUser);
                    dc.SaveChanges();
                }
                binWrite.Write("REG_SUCCESS");
                Console.WriteLine("{0} Dodano nowego uzytkownika {1}, {2}, {3}, {4}", DateTime.Now, username, surname, login, email);
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Console.WriteLine("Property: {0} Error: {1}",
                                          validationError.PropertyName,
                                          validationError.ErrorMessage);
                    }
                }
            }
        }
예제 #2
0
        public void saveLoginInfo(TUsers user, bool correct)
        {
            TLastLogin ll = new TLastLogin();

            using (var dcx = new PTMessengerEntitiesModel())
            {
                try
                {
                    TUsers   tmpUser        = user;
                    DateTime dateTime1H     = DateTime.Now.AddHours(-1);
                    var      failLoginCount = (from c in dcx.TLastLogin
                                               where c.TLastLogin_TS > dateTime1H && c.TLastLogin_Success == false && c.TLastLogin_TUsers_id == user.TUsers_id
                                               select c).Count();
                    if (failLoginCount >= 3)
                    {
                        tmpUser.TUser_lock = true;
                        binWrite.Write("LOGIN_DENY");
                    }
                    else
                    {
                        tmpUser.TUser_lock = false;
                    }

                    dcx.Entry(tmpUser).State = System.Data.Entity.EntityState.Modified;

                    ll.TLastLogin_TUsers_id = user.TUsers_id;
                    var ip_add = tcp_client.Client.RemoteEndPoint.ToString().Split(':');
                    ll.TLastLogin_UserIP  = ip_add[0];
                    ll.TLastLogin_TS      = DateTime.Now;
                    ll.TLastLogin_Success = correct;

                    dcx.TLastLogin.Add(ll);
                    dcx.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Console.WriteLine("Property: {0} Error: {1}",
                                              validationError.PropertyName,
                                              validationError.ErrorMessage);
                        }
                    }
                }
            }
        }