Ejemplo n.º 1
0
        public ActionResult Register(ASPHotel.Models.User user)
        {
            if (ModelState.IsValid)
            {

                using(var db = new ASPHotel.Models.HotelEntities()){

                    //Checks if the username doesn't already exist
                    if (db.Users.Find(user.Username) != null && user.Username.Equals(db.Users.Find(user.Username).Username))
                    {
                        ViewData["error"] = "Please choose a different username.";
                        return View(user);
                    }
                    //If the username is unique, registers the new user
                    else
                    {
                        var newUser = db.Users.Create();
                        newUser.Username = user.Username;
                        newUser.Password = user.Password;
                        newUser.Role_Name = "guest";
                        newUser.IsAuthorised = 0;
                        db.Users.Add(newUser);
                        db.SaveChanges();
                        return RedirectToAction("Login", "Account");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(user);
        }
Ejemplo n.º 2
0
        public ActionResult Login(ASPHotel.Models.User user, string returnUrl)
        {
            {
                try
                {
                    if (IsValid(user.Username, user.Password))
                    {
                        FormsAuthentication.SetAuthCookie(user.Username, false);
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        return RedirectToAction("Login", "Account");
                    }
                }
                catch (HttpException s)
                {
                   return View(s.GetHtmlErrorMessage());
                }
            }

            /**if (ModelState.IsValid && WebSecurity.Login(user.Username, user.Password))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(user);*/
        }