Example #1
0
        public ActionResult Index(UserRegister user)
        {
            UDbTable model = new UDbTable
            {
                Username = user.Username,
                Password = user.Password,
                Email    = user.Email
            };

            model.LastLogin = DateTime.Now;
            if (ModelState.IsValid)
            {
                using (DBModels db = new DBModels())
                {
                    if (db.UDbTables.Any(x => x.Username == model.Username))
                    {
                        return(View("Index"));
                    }
                    else
                    {
                        db.UDbTables.Add(model);
                        db.SaveChanges();
                    }
                }


                return(RedirectToAction("Stream", "Home", user));
            }
            return(View("Index"));
        }
        public ActionResult Index(UserLogin login)
        {
            if (ModelState.IsValid)
            {
                UDbTable data = null;
                using (DBModels db = new DBModels())
                {
                    data = db.UDbTables.FirstOrDefault(u => u.Email == login.Credential && u.Password == login.Password);
                }
                if (data != null)
                {
                    FormsAuthentication.SetAuthCookie(login.Credential, true);
                    return(RedirectToAction("Stream", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "L’adresse e-mail ou le mot de passe que vous avez entré n’est pas valide. Veuillez recommencer.");
                }
            }

            return(View());
        }