Пример #1
0
        public IActionResult register(string name, string email, string password)
        {
            string zpravaProUzivatele = String.Empty;

            var pripojeni = ConnectToDatabase.Connector();
            var data      = ConnectToDatabase.LoginRegisterNameCheck(name, pripojeni);

            //Console.WriteLine(modelError.GetType());

            if (!data.Read())
            {
                pripojeni.Close();
                pripojeni.Open();

                try
                {
                    ConnectToDatabase.RegisterNewUser(name, email, password, pripojeni);
                    var modelError = modelCreate.infoMessageModel("Uspesna registrace");
                    return(View("register", modelError));
                }
                catch
                {
                    var modelError = modelCreate.infoMessageModel("Registrace se nezdarila");
                    return(View("register", modelError));
                }
            }
            else
            {
                //Console.WriteLine(data["jmeno"]);
                var modelError = modelCreate.infoMessageModel("Jmeno nebo email uz existuje");
                return(View("register", modelError));
            }

            // return View("~/Views/loginRegister/register.cshtml");
        }
Пример #2
0
        public IActionResult Scoreboard()
        {
            var pripojeni = ConnectToDatabase.Connector();

            string sql    = $"SELECT score, jmeno FROM databazeUzivatelu ORDER BY score DESC LIMIT 50;";
            var    prikaz = new MySqlCommand(sql, pripojeni);
            var    data   = prikaz.ExecuteReader();

            // Dictionary<List<string>, string> values = new Dictionary<string, string>();
            List <string> jmenaList       = new List <string>();
            List <string> scoreList       = new List <string>();
            var           modelScoreBoard = new ScoreBoard {
                jmena = jmenaList,
                score = scoreList
            };

            while (data.Read())
            {
                /*
                 * var score = data[0].ToString();
                 * var jmeno = data[1].ToString();
                 * Console.WriteLine(jmeno);
                 */
                modelScoreBoard.jmena.Add(data[1].ToString());
                modelScoreBoard.score.Add(data[0].ToString());
                //Dictionary<int, string> dataList = new Dictionary<int, string>();
                //var jsonString = JsonConvert.SerializeObject(data);
            }
            //scoreList.ForEach(Console.WriteLine);
            //jmenaList.ForEach(Console.WriteLine);
            return(View(modelScoreBoard));
        }
Пример #3
0
        public IActionResult Trivia(string jmeno, string score) // trivia score funkce
        {
            var    pripojeni = ConnectToDatabase.Connector();
            string sql       = $"UPDATE databazeUzivatelu SET score = score + {score} WHERE jmeno = '{jmeno}';";

            try
            {
                var prikaz = new MySqlCommand(sql, pripojeni);
                prikaz.ExecuteNonQuery();
            }
            catch (MySqlException ex) { Console.WriteLine(ex); }


            pripojeni.Close();
            return(View());
        }
Пример #4
0
        public IActionResult user(string username)
        {
            var pripojeni = ConnectToDatabase.Connector();
            var data      = ConnectToDatabase.getInfoAboutUser(username, pripojeni);

            if (data.Read())
            {
                var modelUser = modelCreate.userInfoProfileModelCreator(data["jmeno"].ToString(), data["email"].ToString(), data["datumPripojeni"].ToString(), data["score"].ToString());

                return(View(modelUser));
            }
            else
            {
                Console.WriteLine("userNotFound");
                return(View());
            }
        }
Пример #5
0
        public IActionResult login(string name, string password)
        {
            var pripojeni = ConnectToDatabase.Connector();

            string hesloDatabaze = String.Empty;
            string scoreDatabaze = String.Empty;
            bool   verified      = false;

            var data = ConnectToDatabase.LoginRegisterNameCheck(name, pripojeni);

            if (data.Read())
            {
                hesloDatabaze = data["heslo"].ToString();
                verified      = BCrypt.Net.BCrypt.Verify(password, hesloDatabaze);
                Console.WriteLine(verified);
            }
            if (verified)
            {
                HttpContext.Session.SetString("username", name);

                var model = modelCreate.infoMessageModel(name);

                //Response.Cookies.Append("jmeno", name);
                //string cookie = Request.Cookies["jmeno"];
                //Console.WriteLine(cookie);

                return(View("login", model));
            }

            else
            {
                var modelError = new LoginRegisterModel {
                    errorMessage = "Spatne jmeno nebo heslo"
                };

                return(View("login", modelError));
            }
        }