コード例 #1
0
        public ActionResult ShowAll()
        {
            AiLabForumEntities db = new AiLabForumEntities();
            var data = db.Topics.ToList();

            ViewBag.userdetails = data;
            return(View());
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: sebag93/AILABFORUM
 public bool IsLoginExist(string LOGIN)
 {
     using (AiLabForumEntities db = new AiLabForumEntities())
     {
         var v = db.Users.Where(x => x.login == LOGIN).FirstOrDefault();
         return(v != null);
     }
 }
コード例 #3
0
 public bool IsTopicExist(string TYTUL)
 {
     using (AiLabForumEntities db = new AiLabForumEntities())
     {
         var v = db.Topics.Where(x => x.tytul == TYTUL).FirstOrDefault();
         return(v != null);
     }
 }
コード例 #4
0
ファイル: UserController.cs プロジェクト: sebag93/AILABFORUM
 public bool IsEmailExist(string EMAIL)
 {
     using (AiLabForumEntities db = new AiLabForumEntities())
     {
         var v = db.Users.Where(x => x.email == EMAIL).FirstOrDefault();
         return(v != null);
     }
 }
コード例 #5
0
ファイル: UserController.cs プロジェクト: sebag93/AILABFORUM
        public ActionResult Registration(User user)
        {
            bool   Status  = false;
            string message = "";

            //walidacja modelu
            if (ModelState.IsValid)
            {
                #region //email juz istnieje
                var emailExist = IsEmailExist(user.email);
                if (emailExist)
                {
                    ModelState.AddModelError("EmailExist", "Podany email został już zarejestrowany");
                    return(View(user));
                }
                #endregion

                #region //login juz istnieje
                var loginExist = IsLoginExist(user.login);
                if (loginExist)
                {
                    ModelState.AddModelError("LoginExist", "Podana nazwa użytkownika została już zarejestrowana");
                    return(View(user));
                }
                #endregion

                #region //zapis do bazy danych
                using (AiLabForumEntities db = new AiLabForumEntities())
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                    message = "Rejestracja zakończona pomyślnie. Możesz zalogować sie na swoje konto.";
                    Status  = true;
                }
                #endregion
            }
            else
            {
                message = "Nieprawidłowe żądanie";
            }
            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
コード例 #6
0
ファイル: UserController.cs プロジェクト: sebag93/AILABFORUM
        public ActionResult ManageAcc(User user)
        {
            bool   Status  = false;
            string message = "";

            user.login = User.Identity.Name;
            AiLabForumEntities db = new AiLabForumEntities();
            User do_zmiany        = db.Users.SingleOrDefault(x => x.login == user.login);

            do_zmiany.haslo        = user.haslo;
            do_zmiany.powtorzhaslo = user.powtorzhaslo;
            db.SaveChanges();
            message = "Hasło zmienione pomyślnie.";
            Status  = true;

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
コード例 #7
0
        public ActionResult NewTopic(Topic topic)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                #region //temat juz istnieje
                var topicExist = IsTopicExist(topic.tytul);
                if (topicExist)
                {
                    ModelState.AddModelError("TopicExist", "Temat o podanej nazwie już istnieje. Niemożliwe jest powielanie nazw tematów");
                    return(View(topic));
                }
                #endregion

                topic.data_dodania = DateTime.Now;
                topic.autor        = User.Identity.Name;

                #region //zapis do bazy danych
                using (AiLabForumEntities db = new AiLabForumEntities())
                {
                    db.Topics.Add(topic);
                    db.SaveChanges();
                    message = "Temat utworzony pomyślnie.";
                    Status  = true;
                }
                #endregion
            }
            else
            {
                message = "Nieprawidłowe żądanie";
            }
            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(topic));
        }
コード例 #8
0
ファイル: UserController.cs プロジェクト: sebag93/AILABFORUM
        public ActionResult Login(UserLogin dane, string ReturnUrl = "")
        {
            string message = "";

            using (AiLabForumEntities db = new AiLabForumEntities())
            {
                var v = db.Users.Where(x => x.login == dane.login && x.haslo == dane.haslo).FirstOrDefault();
                if (v != null)
                {
                    int    timeout   = dane.zapamietaj ? 525600 : 20; //525600 minut to 1 rok
                    var    ticket    = new FormsAuthenticationTicket(dane.login, dane.zapamietaj, timeout);
                    string encrypted = FormsAuthentication.Encrypt(ticket);
                    var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted)
                    {
                        Expires  = DateTime.Now.AddMinutes(timeout),
                        HttpOnly = true
                    };
                    Response.Cookies.Add(cookie);
                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        //return RedirectToAction(ReturnUrl);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    message = "Wprowadzono niepoprawne dane";
                }
            }
            ViewBag.Message = message;
            return(View());
        }