Example #1
0
 /// <summary>
 /// 根据登录名查询用户
 /// </summary>
 /// <returns></returns>
 public User GetUserNames(string loginid)
 {
     using (ChatEntities db = new ChatEntities())
     {
         return(db.User.FirstOrDefault(u => u.LoginID == loginid));
     }
 }
Example #2
0
 /// <summary>
 /// 根据登录名搜索联系人
 /// </summary>
 /// <returns></returns>
 public User GetUserName(string loginid)
 {
     using (ChatEntities db = new ChatEntities())
     {
         return(db.User.FirstOrDefault(u => u.LoginID == loginid && u.USearchState == true));
     }
 }
Example #3
0
 /// <summary>
 /// 根据电话号码查询用户
 /// </summary>
 /// <returns></returns>
 public User GetPhoneNumber(string loginid)
 {
     using (ChatEntities db = new ChatEntities())
     {
         return(db.User.FirstOrDefault(u => u.PhoneNumber == loginid && u.PSearchState == true));
     }
 }
Example #4
0
 //根据ID查询用户信息
 public User GetUserById(int Id)
 {
     using (ChatEntities db = new ChatEntities())
     {
         return(db.User.FirstOrDefault(i => i.ID == Id && i.Shape != -1));
     }
 }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ChatEntities   context  = new ChatEntities();
            List <Message> messages = context.Messages.Take(100).ToList <Message>();

            RepeaterMessages.DataSource = messages;
        }
Example #6
0
 /// <summary>
 /// 获取所有的Logo
 /// </summary>
 /// <returns></returns>
 public List <Logo> GetAll()
 {
     using (ChatEntities db = new ChatEntities())
     {
         return(db.Logo.ToList());
     }
 }
Example #7
0
        public ActionResult Index(LoginModel login)
        {
            if (ModelState.IsValid)
            {
                ChatEntities db   = new ChatEntities();
                var          user = (from userlist in db.Users
                                     where userlist.NickName == login.UserName && userlist.Password == login.Password
                                     select new
                {
                    userlist.Id,
                    userlist.NickName,
                    userlist.Role
                }).ToList();
                var result = IChat.GetRooms();


                if (user.FirstOrDefault() != null && user.FirstOrDefault().Role != "Admin")
                {
                    Session["UserName"] = user.FirstOrDefault().NickName;
                    Session["UserID"]   = user.FirstOrDefault().Id;
                    return(Redirect("/Home/Rooms"));
                }
                else if (user.FirstOrDefault() != null && user.FirstOrDefault().Role == "Admin")
                {
                    Session["UserName"] = user.FirstOrDefault().NickName;
                    Session["UserID"]   = user.FirstOrDefault().Id;
                    return(Redirect("/Home/Admin"));
                }
                else
                {
                    ModelState.AddModelError("", "login credenciales Invalidas.");
                }
            }
            return(View(login));
        }
 /// <summary>
 /// 查询当前用户一个星期的聊天记录并分页
 /// </summary>
 /// <param name="pageindex">当前页的索引</param>
 /// <param name="pagesize">每页大小</param>
 /// <returns></returns>
 public List <Messages> PageMessages(int pageindex, int pagesize, int fromuserid)
 {
     using (ChatEntities db = new ChatEntities())
     {
         DateTime time = DateTime.Now.AddDays(-7);
         return(db.Messages.Where(m => m.FromUserID == fromuserid && m.Time > time).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList());
     }
 }
 /// <summary>
 /// 获取当前用户的聊天记录
 /// </summary>
 /// <param name="userid"></param>
 /// <returns></returns>
 public List <Messages> GetMessages(int userid, DateTime time)
 {
     using (ChatEntities db = new ChatEntities())
     {
         List <Messages> listmessage = db.Messages.Where(m => m.FromUserID == userid && m.Time > time).ToList();
         return(listmessage);
     }
 }
 /// <summary>
 /// 获取所有的聊天记录
 /// </summary>
 /// <returns></returns>
 public List <Messages> GetMessagesAll()
 {
     using (ChatEntities db = new ChatEntities())
     {
         List <Messages> listmessage = db.Messages.ToList();
         return(listmessage);
     }
 }
 /// <summary>
 /// 添加消息记录
 /// </summary>
 /// <param name="ms"></param>
 /// <returns></returns>
 public bool CreateMessages(Messages ms)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.Messages.Add(ms);
         return(db.SaveChanges() > 0);
     }
 }
Example #12
0
 /// <summary>
 /// 添加一条充值记录
 /// </summary>
 /// <param name="up"></param>
 /// <returns></returns>
 public bool AddUserPay(UserPay up)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.UserPay.Add(up);
         return(db.SaveChanges() > 0);
     }
 }
Example #13
0
 /// <summary>
 /// 根据账号查询用户信息
 /// </summary>
 /// <param name="loginid">登陆账号</param>
 /// <returns></returns>
 public User GetUser(User us)
 {
     using (ChatEntities db = new ChatEntities())
     {
         User user = db.User.SingleOrDefault(u => u.LoginID == us.LoginID);
         return(user);
     }
 }
Example #14
0
 /// <summary>
 /// 获取所有邀请码
 /// </summary>
 /// <returns></returns>
 public List <Invitation> GetAll()
 {
     using (ChatEntities db = new ChatEntities())
     {
         List <Invitation> iv = db.Invitation.ToList();
         return(iv);
     }
 }
Example #15
0
 /// <summary>
 /// 添加用户
 /// </summary>
 /// <param name="us"></param>
 /// <returns></returns>
 public bool CreateUser(User us)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.User.Add(us);
         return(db.SaveChanges() > 0);
     }
 }
Example #16
0
 /// <summary>
 /// 添加当前用户生成的邀请码
 /// </summary>
 /// <param name="iv"></param>
 /// <returns></returns>
 public bool CreaeteInvitation(Invitation iv)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.Invitation.Add(iv);
         return(db.SaveChanges() > 0);
     }
 }
Example #17
0
 /// <summary>
 /// 添加一条代理关系
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public bool AddAgent(Agent a)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.Agent.Add(a);
         return(db.SaveChanges() > 0);
     }
 }
Example #18
0
        /// <summary>
        /// 获取当前用户的充值信息
        /// </summary>
        /// <param name="userpayid">充值id</param>
        /// <returns></returns>
        public List <UserPay> GetUserPay(int userpayid)
        {
            using (ChatEntities db = new ChatEntities())
            {
                return(db.UserPay.Where(u => u.UserID == userpayid).ToList());

                ;
            }
        }
Example #19
0
 /// <summary>
 /// 查询用户邀请码是否存在,返回值类型bool
 /// </summary>
 /// <param name="iv">邀请码实体</param>
 /// <returns></returns>
 public Invitation GetInvitation(Invitation iv)
 {
     using (ChatEntities db = new ChatEntities())
     {
         bool       flag       = false;
         Invitation invitation = db.Invitation.FirstOrDefault(i => i.InviteCode == iv.InviteCode);
         return(invitation);
     }
 }
Example #20
0
        string image;  // Information about current user.
        /// <summary>
        /// Ініціалізація потоків передачі даних, логін або реєстрація
        /// </summary>
        void SetupConn()  // Setup connection and login or register.
        {
            try
            {
                Console.WriteLine("[{0}] New connection!", DateTime.Now);
                netStream = client.GetStream();

                br = new BinaryReader(netStream, Encoding.UTF8);
                bw = new BinaryWriter(netStream, Encoding.UTF8);

                User user = new User();

                currentUser = br.ReadString();
                password    = br.ReadString();
                email       = br.ReadString();
                image       = br.ReadString();

                user.Login    = currentUser;
                user.Password = password;
                user.Email    = email;
                user.Image    = image;

                List <User> lst = new List <User>();
                using (ChatEntities db = new ChatEntities())
                {
                    foreach (User u in db.Users)
                    {
                        lst.Add(u);
                    }
                }
                if (lst.Any(x => x.Login == currentUser))
                {
                    if (password.Length > 3)
                    {
                        prog.users.Add(currentUser, this); // Add new user
                        lst.Add(user);                     // Add new user
                        Receiver();                        // Listen to client in loop.
                    }
                    else
                    {
                        Console.WriteLine($"{currentUser} tried to login with login length > 3");
                    }
                }
                else
                {
                    prog.AddUser(currentUser, email, password, image);
                    prog.users.Add(currentUser, this); // Add new user
                    lst.Add(user);                     // Add new user
                    Console.WriteLine($"{currentUser} successfully registered!!!");
                }
                CloseConn();
            }
            catch
            {
                CloseConn();
            }
        }
Example #21
0
 /// <summary>
 /// 如果没有迷惑密码,默认1111
 /// </summary>
 public bool UpdatePassword(User user)
 {
     using (ChatEntities db = new ChatEntities())
     {
         User us = db.User.SingleOrDefault(u => u.ID == user.ID);
         us.PassWords = user.PassWords;
         return(db.SaveChanges() > 0);
     }
 }
Example #22
0
 /// <summary>
 /// 根据ID删除用户,修改状态
 /// </summary>
 /// <param name="user">当前选中的用户</param>
 /// <returns></returns>
 public bool DeleteUser(int id)
 {
     using (ChatEntities db = new ChatEntities())
     {
         User us = db.User.SingleOrDefault(u => u.ID == id);
         db.User.Remove(us);
         return(db.SaveChanges() > 0);
     }
 }
Example #23
0
 /// <summary>
 /// 修改用户登陆时间
 /// </summary>
 public void UpdateUser(int userid, DateTime time)
 {
     using (ChatEntities db = new ChatEntities())
     {
         User user = db.User.SingleOrDefault(u => u.ID == userid);
         user.LastLoginAt = time;
         db.SaveChanges();
     }
 }
Example #24
0
 /// <summary>
 /// 删除当前用户的消费记录
 /// </summary>
 /// <param name="up"></param>
 /// <returns></returns>
 public bool DeleteUserPay(UserPay up)
 {
     using (ChatEntities db = new ChatEntities())
     {
         UserPay ups = db.UserPay.Find(up.ID);
         db.UserPay.Remove(ups);
         return(db.SaveChanges() > 0);
     }
 }
Example #25
0
 /// <summary>
 /// 设置用户的迷惑密码
 /// </summary>
 /// <returns></returns>
 public bool EditChatSwitch(int id)
 {
     using (ChatEntities db = new ChatEntities())
     {
         User us = db.User.SingleOrDefault(u => u.ID == id);
         us.ChatSwitch = true;
         return(db.SaveChanges() > 0);
     }
 }
        /// <summary>
        /// 获取所有的好友分组信息
        /// </summary>
        /// <returns></returns>
        public List <Friends> GetAll(int userid)
        {
            List <Friends> list = new List <Friends>();

            using (ChatEntities db = new ChatEntities())
            {
                list = db.Friends.Where(a => a.UserID == userid && a.Status == 1).ToList();
            }
            return(list);
        }
Example #27
0
 /// <summary>
 /// Добавляє користувача в БД
 /// </summary>
 /// <param name="login"></param>
 /// <param name="email"></param>
 /// <param name="password"></param>
 /// <param name="image"></param>
 public void AddUser(string login, string email, string password, string image)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.Users.Add(new User {
             Login = login, Email = email, Password = password, Image = image
         });
         db.SaveChanges();
     }
 }
Example #28
0
 /// <summary>
 /// Зберігає повідомлення в бд
 /// </summary>
 /// <param name="idFrom"></param>
 /// <param name="idTo"></param>
 /// <param name="date"></param>
 /// <param name="message"></param>
 public void SaveMessage(int idFrom, int idTo, DateTime date, string message)
 {
     using (ChatEntities db = new ChatEntities())
     {
         db.Messages.Add(new Message {
             Id_user_from = idFrom, Id_user_to = idTo, Created_at = date, Message1 = message
         });
         db.SaveChanges();
     }
 }
Example #29
0
        /// <summary>
        /// Получить токен для входа. Если строка начинается с "Error!" - ошибка
        /// </summary>
        /// <param name="email">Адрес электронной почты</param>
        /// <param name="password">Пароль</param>
        /// <returns>Токен</returns>
        public String LogIn(String email, String password)
        {
            if (String.IsNullOrWhiteSpace(email))
            {
                return($"Error! {nameof(email)} can't be null");
                //throw new ArgumentNullException($"Error! {nameof(email)} can't be null");
            }
            if (String.IsNullOrWhiteSpace(password))
            {
                return($"Error! {nameof(password)} can't be null");
                // throw new ArgumentNullException($"Error! {nameof(password)} can't be null");
            }
            RegexUtilities regex = new RegexUtilities();

            if (!regex.IsValidEmail(email))
            {
                return($"Error! Invalid Email adress");
                // throw new ArgumentException($"Error! Invalid Email adress");
            }
            if (!regex.IsValidPassword(password))
            {
                return("Error! Invalid password. This requires at least one digit, at least one alphabetic character, no special characters, and from 6-15 characters in length.");
                //throw new ArgumentException("Error! Invalid password. This requires at least one digit, at least one alphabetic character, no special characters, and from 6-15 characters in length.");
            }
            try
            {
                using (chatContext = new ChatEntities())
                {
                    var user = chatContext.Users.FirstOrDefault(x => x.Email == email);
                    if (user == null)
                    {
                        return("Error! User not found!");
                    }
                    if (user == null || !PasswordCrypt.ComparePasswords(password, user.PasswordHash, user.PasswordSalt))
                    {
                        return("Error! Login and/or password do not match");
                    }
                    var token = GenerateToken(user);
                    chatContext.AccessTokens.Add(token);
                    int res = chatContext.SaveChanges();
                    if (res == 1)
                    {
                        return(token.Token);
                    }
                    else
                    {
                        return("Error! Internal service Error");
                    }
                }
            }
            catch (Exception)
            {
                return("Error! Internal service Error");
            }
        }
 /// <summary>
 /// 修改消息状态
 /// </summary>
 public bool EditMessage(int touserid, DateTime time)
 {
     using (ChatEntities db = new ChatEntities())
     {
         List <Messages> list = db.Messages.Where(m => m.ToUserID == touserid && m.Time < time).ToList();
         foreach (var temp in list)
         {
             temp.Status = 1;
         }
         return(db.SaveChanges() > 0);
     }
 }