Beispiel #1
0
        public ActionResult Edit(int id)
        {
            var user = new UserD().ViewDetail(id);

            SetViewBag();
            return(View(user));
        }
Beispiel #2
0
        public IHttpActionResult AddUser([FromBody] UserViewModel newUser)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Please provide a valid model"));
                }

                UserD model = new UserD();
                model.FirstName   = newUser.FirstName;
                model.LastName    = newUser.LastName;
                model.Dob         = newUser.Dob;
                model.Designation = newUser.Designation;

                context.UserDs.Add(model);
                context.SaveChanges();

                return(Ok(model));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
0
        public ActionResult Index(string searchString, int page = 1, int pageSize = 10)
        {
            var dao   = new UserD();
            var model = dao.ListAllPaging(searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            return(View(model));
        }
Beispiel #4
0
        public JsonResult ChangeStatus(long id)
        {
            var result = new UserD().ChangeStatus(id);

            return(Json(new
            {
                status = result
            }));
        }
Beispiel #5
0
        public List <UserInformation> GetUserFriendshipOffers(UserD user)
        {
            var userFriendshipOffers      = new List <UserInformation>();
            var foundUserFriendshipOffers = _friends.Where(friend => friend.ToUser.UserId == user.UserId && friend.SendDate > user.LastVisit && friend.Status != 3);

            foreach (var friendshipOffer in foundUserFriendshipOffers)
            {
                userFriendshipOffers.Add(UserInf(friendshipOffer.FromUser.UserId));
            }

            return(userFriendshipOffers.Distinct().ToList());
        }
        public static UserD open(string email)
        {
            string           connetion_string = null;
            string           database_name    = "MyDatabase.sqlite";
            SQLiteConnection connection;
            SQLiteCommand    command;

            connetion_string = $"Data Source={database_name};Version=3;";
            connection       = new SQLiteConnection(connetion_string);
            SQLiteDataReader dataReader;

            UserD userD = null;

            try
            {
                connection.Open();

                string sql = "select * from UserTable WHERE UserID ='" + email + "'";
                command    = new SQLiteCommand(sql, connection);
                dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    Boolean login;
                    if (dataReader["Login"].Equals("true"))
                    {
                        login = true;
                    }
                    else
                    {
                        login = false;
                    }
                    string userName   = (string)dataReader.GetValue(0);
                    string password   = (string)dataReader.GetValue(1);
                    int    numOfTasks = (int)((long)dataReader.GetValue(3));
                    string lastBoard  = (string)dataReader.GetValue(4);
                    userD = new UserD(userName, password, login, numOfTasks, lastBoard);
                }
                dataReader.Close();
                command.Dispose();
                Log.Info("Open user: "******"Failed to Open user: " + email);
                return(null);
            }
            finally
            {
                connection.Close();
            }
        }
        public IHttpActionResult Post(UserD value)
        {
            try
            {
                if (value == null)
                {
                    return(NotFound());
                }

                context.UserDs.Add(value);
                context.SaveChanges();

                return(Ok(value));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #8
0
        public List <News> GetUserNews(UserD user)
        {
            var userNews      = new List <News>();
            var foundUserNews = _messages.Where(message => message.SendDate > user.LastVisit);

            foreach (var currentUserNews in foundUserNews)
            {
                var newsInf = new News
                {
                    AuthorId   = currentUserNews.User.UserId,
                    AuthorName = UserInf(currentUserNews.User.UserId).Name,
                    Likes      = currentUserNews.Likes,
                    Text       = currentUserNews.Text
                };

                userNews.Add(newsInf);
            }

            return(userNews);
        }
Beispiel #9
0
 public ActionResult Login(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         var dao    = new UserD();
         var result = dao.login(model.UserName, Encryptor.MD5Hash(model.Password), true);
         if (result == 1)
         {
             var user        = dao.GetById(model.UserName);
             var userSession = new UserLogin();
             userSession.UserName = user.UserName;
             userSession.UserID   = user.ID;
             userSession.GroupID  = user.GroupID;
             var listCredentials = dao.GetListCreadential(model.UserName);
             Session.Add(Common.CommonConstants.SESSION_CREDENTIALS, listCredentials);
             Session.Add(Common.CommonConstants.USER_SESSION, userSession);
             return(RedirectToAction("Index", "Home"));
         }
         else if (result == 0)
         {
             ModelState.AddModelError("", "Tài khoản không tồn tại");
         }
         else if (result == -1)
         {
             ModelState.AddModelError("", "Tài khoản đang bị khóa");
         }
         else if (result == -2)
         {
             ModelState.AddModelError("", "Mật Khẩu không đúng");
         }
         else if (result == -3)
         {
             ModelState.AddModelError("", "Tài khoản của bạn không có quyền đăng nhập");
         }
         else
         {
             ModelState.AddModelError("", "Đăng Nhập Không Đúng");
         }
     }
     return(View("Index"));
 }
Beispiel #10
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                var dao             = new UserD();
                var encryptedMd5Pas = Encryptor.MD5Hash(user.Password);
                user.Password = encryptedMd5Pas;
                long id = dao.Insert(user);
                if (id > 0)
                {
                    SetAlert("Thêm user thành công", "success");
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm User không thành công");
                }
            }

            return(View("Index"));
        }
Beispiel #11
0
        public UserD GetUserInformation(string userName)
        {
            var userInformation = new UserD();
            var foundUser       = _users.Where(user => user.Name == userName);

            try
            {
                userInformation.Name        = foundUser.Single().Name;
                userInformation.UserId      = foundUser.Single().UserId;
                userInformation.DateOfBirth = foundUser.Single().DateOfBirth;
                userInformation.Gender      = foundUser.Single().Gender;
                userInformation.LastVisit   = foundUser.Single().LastVisit;
                userInformation.Online      = foundUser.Single().Online;
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Такого имени пользователя нет в БД или таких имен несколько");
            }

            return(userInformation);
        }
Beispiel #12
0
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         var dao = new UserD();
         if (dao.CheckUserName(model.UserName))
         {
             ModelState.AddModelError("", "Tên đăng nhập đã tồn tại");
         }
         else if (dao.CheckEmail(model.Email))
         {
             ModelState.AddModelError("", "Email đã tồn tại");
         }
         else
         {
             var user = new User();
             user.Name        = model.Name;
             user.UserName    = model.UserName;
             user.Password    = Encryptor.MD5Hash(model.Password);
             user.Phone       = model.Phone;
             user.Email       = model.Email;
             user.Address     = model.Address;
             user.CreatedDate = DateTime.Now;
             user.Status      = true;
             var result = dao.Insert(user);
             if (result > 0)
             {
                 ViewBag.Success = "Đăng ký thành công";
                 model           = new RegisterModel();
             }
             else
             {
                 ModelState.AddModelError("", "Đăng ký không thành công");
             }
         }
     }
     return(View(model));
 }
Beispiel #13
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                var dao = new UserD();
                if (!string.IsNullOrEmpty(user.Password))
                {
                    var encryptedMd5Pas = Encryptor.MD5Hash(user.Password);
                    user.Password = encryptedMd5Pas;
                }

                var result = dao.Update(user);
                if (result)
                {
                    SetAlert("Sửa user thành công", "success");
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập Nhật User không thành công");
                }
            }
            return(View("Index"));
        }
Beispiel #14
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new UserD();
                var result = dao.login(model.UserName, Encryptor.MD5Hash(model.Password));
                if (result == 1)
                {
                    var user        = dao.GetById(model.UserName);
                    var userSession = new UserLogin();
                    userSession.UserName = user.UserName;
                    userSession.UserID   = user.ID;
                    userSession.GroupID  = user.GroupID;
                    Session.Add(Common.CommonConstants.USER_SESSION, userSession);

                    return(Redirect("/"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại.");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Tài khoản đang bị khoá.");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Mật khẩu không đúng.");
                }
                else
                {
                    ModelState.AddModelError("", "đăng nhập không đúng.");
                }
            }
            return(View(model));
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            #region LoadChannel
            _channel   = ChannelD.GetChannel();
            _channelId = _channel._id;
            #endregion

            #region LoadStream
            _stream = StreamD.GetStreamByUser(_channelId);
            if (_stream.stream == null)
            {
                _streamUptime = new DateTime();
            }
            else
            {
                _streamUptime = _stream.stream.created_at.ToLocalTime();
            }

            #endregion

            _irc = new IrcClient("irc.twitch.tv", 6667, ChatBot.botName, _password, _channel.name);
            TwitchApi  api      = new TwitchApi();
            TmiApi     tmi      = new TmiApi();
            ViewerList chatters = new ViewerList();
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            TwitchSocket twitchSocket = new TwitchSocket();
            ChatBot.init();

            #region LoadBroadCasterInfo
            _broadcaster = UserD.GetUser(_broadcasterName);
            #endregion

            _moderators.Add("gaelLevel");
            _moderators.Add("terror_seeds");
            _moderators.Add("nebulea");
            _moderators.Add("novaevermoon");

            #region LoadCommands
            List <CommandO> commands = new List <CommandO>();
            commands = CommandD.LoadCommands();
            LaunchTimer launchTimer = new LaunchTimer(_irc);
            foreach (CommandO command in commands)
            {
                if (command.type == "timed")
                {
                    launchTimer.createTimer(command);
                }
            }


            if (commands.Count != 0)
            {
                _commandsText = new StringBuilder();
                foreach (CommandO command in commands)
                {
                    if (command.userLevel == "everyone" && command.timer == 0)
                    {
                        _commandsText.Append("!" + command.keyword + ", ");
                    }
                }
                _commandsText.Length = _commandsText.Length - 2;
            }


            #endregion

            //chatters = tmi.getViewerList(_channel);

            //_viewers = tmi.getViewers(chatters);
            twitchSocket.ClientWebSocket = twitchSocket.WebSocketConnectAsync().Result;
            var testSocket = twitchSocket.WhisperSubscribeAsync(twitchSocket.ClientWebSocket, _broadcaster.users[0]._id);
            //ClientWebSocket webSocket = twitchSocket.WebSocketConnectAsync().Result;

            //var testWebSocket = twitchSocket.WhisperSubscribeAsync(twitchSocket.whisperWebSocket,_broadcaster.users[0]._id).Result;


            PingSender ping = new PingSender(_irc);
            ping.Start();

            while (true)
            {
                string   fullMessage  = _irc.ReadMessage();
                CommandO foundCommand = new CommandO();
                if (fullMessage.Contains("PRIVMSG"))
                {
                    _username = UserD.GetUsername(fullMessage);
                    string message = ChatBot.GetMessage(fullMessage);
                    _user = UserD.GetUser(_username);
                    UserD.InsertUser(_user);

                    bool isSubscriber = SubscriberD.IsSubscriber(_user.users[0]._id, _broadcaster.users[0]._id);


                    if (isSubscriber == false && _user.isPermit == false)
                    {
                        bool link = ChatBot.checkLink(message);
                        if (link == true)
                        {
                            _irc.WriteChatMessage(".timeout " + _username + " 15");
                            _irc.WriteChatMessage("Posting links is not allowed here for non-subs, if you think this link might interest me, just whisper me or one of my mods ♡");
                        }
                    }

                    char firstCharacter = message[0];

                    try
                    {
                        if (firstCharacter == '!')
                        {
                            string commandMessage = message.Substring(message.IndexOf('!') + 1);

                            bool kappamonCommand = CommandD.IsKappamonCommand(commandMessage);

                            if (!kappamonCommand)
                            {
                                if (commandMessage.Contains(" "))
                                {
                                    _command = commandMessage.Split(' ');
                                    if (_command.Length == 2)
                                    {
                                        commandMessage   = _command[0];
                                        _chatterUsername = _command[1];
                                    }
                                }
                                else
                                {
                                    _command[0] = commandMessage;
                                }

                                if (commands.Any(c => c.keyword == commandMessage))
                                {
                                    foundCommand = commands.Single(c => c.keyword == commandMessage);

                                    if (foundCommand.parameters != 0)
                                    {
                                        Type testType = typeof(Program);
                                        Dictionary <string, dynamic> newDic = new Dictionary <string, dynamic>();

                                        foreach (KeyValuePair <string, dynamic> dic in foundCommand.parameterList)
                                        {
                                            var fieldInfo = testType.GetField(dic.Key.ToString(), BindingFlags.Static | BindingFlags.Public).GetValue(testType);
                                            newDic.Add(dic.Key.ToString(), fieldInfo.ToString());
                                        }

                                        foundCommand.parameterList = newDic;
                                    }

                                    if (foundCommand.userLevel == "moderator" && !_moderators.Contains(_username))
                                    {
                                        _irc.WriteChatMessage("You are not allowed to use this command !");
                                    }
                                    else
                                    {
                                        DateTime date = DateTime.Now;

                                        if (foundCommand.startedTime.AddMilliseconds(foundCommand.cooldown) < DateTime.Now)

                                        {
                                            foundCommand.startedTime = DateTime.Now;
                                            if (foundCommand.keyword == "commands")
                                            {
                                                foundCommand.message += _commandsText;
                                            }

                                            switch (foundCommand.type)
                                            {
                                            case "request":
                                                string query = foundCommand.request;
                                                using (MySqlConnection mySqlConnection = new MySqlConnection("" /*connectionString*/))
                                                {
                                                    if (foundCommand.condition != "")
                                                    {
                                                        switch (foundCommand.condition)
                                                        {
                                                        case "userName":
                                                            foundCommand.request = string.Format(foundCommand.request, _username);
                                                            foundCommand.message = string.Format(foundCommand.message, _username);
                                                            break;
                                                        }
                                                    }

                                                    if (foundCommand.request.Contains("SELECT"))
                                                    {
                                                        Tuple <int, string> test = CommandD.ExecuteSelectCommand(foundCommand.request);
                                                        if (foundCommand.message.Contains("@"))
                                                        {
                                                            _irc.WriteChatMessage(foundCommand.message.Replace("@", test.Item1.ToString()));
                                                        }
                                                        else
                                                        {
                                                            _irc.WriteChatMessage(test.Item2);
                                                        }
                                                    }
                                                    else if (foundCommand.request.Contains("UPDATE"))
                                                    {
                                                        Tuple <int, string> result = CommandD.ExecuteUpdateCommand(foundCommand.request, foundCommand.message);
                                                        mySqlConnection.Close();
                                                        if (result.Item1 < 0)
                                                        {
                                                        }
                                                        else
                                                        {
                                                            _irc.WriteChatMessage(result.Item2);
                                                        }
                                                    }
                                                }
                                                break;

                                            case "regular":
                                                if (foundCommand.message.Contains("{"))
                                                {
                                                    _irc.WriteChatMessage(string.Format(foundCommand.message, _username));
                                                }
                                                else
                                                {
                                                    _irc.WriteChatMessage(foundCommand.message);
                                                }
                                                break;

                                            case "api":
                                                MethodInfo mInfo;
                                                Type       type = Assembly.Load("MoonBot_Data").GetType(foundCommand.assembly, false, true);
                                                mInfo = type.GetMethod(foundCommand.message);
                                                object[] parameters;

                                                if (foundCommand.parameters == 0)
                                                {
                                                    parameters = new object[] {};
                                                }
                                                else
                                                {
                                                    //Type testType = typeof(Program);
                                                    parameters = new object[] { foundCommand.parameterList };
                                                }

                                                object apiAnswer = mInfo.Invoke(null, parameters);
                                                _irc.WriteChatMessage(apiAnswer.ToString());
                                                break;

                                            case "moonlights":
                                                _irc.WriteChatMessage("Switching color to : " + foundCommand.keyword);
                                                _port.Open();
                                                _port.Write(foundCommand.message);
                                                _port.Close();
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            TimeSpan span = date - foundCommand.startedTime;
                                            int      ms   = (int)span.TotalMilliseconds;
                                            if (ms <= foundCommand.cooldown)
                                            {
                                                _irc.WriteChatMessage("This command is in cooldown right now, be patient !");
                                            }
                                            else
                                            {
                                                _irc.WriteChatMessage(foundCommand.message);
                                                foundCommand.startedTime = DateTime.Now;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _irc.WriteChatMessage("This command does not exist, type !commands to know what commands are available");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        StringBuilder sb = new StringBuilder(DateTime.Now.ToString("dd-MM-yyyy") + " : " + ex.Message);
                        Console.WriteLine(sb);
                    }
                }
            }
        }