Exemplo n.º 1
0
        public virtual ActionResult LogIn(LogInUser model)
        {
            //string error;
            if (ModelState.IsValid)
            {
                var user = Security.CheckPasswordAndRole(model.Email, model.Password);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, false);
                    TempData["user"] = user;
                    var role = new MusicWaveRoleProviders();
                    bool isUser = role.IsUserInRole(user.Email, "user");
                    if (isUser)
                    {
                        return RedirectToAction("Index", "User", new {area="UserProfile"});
                    }
                    else
                    {
                        return RedirectToAction("Index", "Admin",new{area="AdminProfile"});
                    }
                }
                else
                {
                    //TODO исправить ошибку при вводе некоректного логина и пароля при входе на сайт
                    //TempData["Result"] = model;
                    ModelState.AddModelError("", "Login data is incorrect.");
                }

            }
            //return View("Index","Home", new{area="",model});
            return RedirectToAction("Index","Home", new{area="Home",model});
        }
Exemplo n.º 2
0
 public virtual ActionResult Index(LogInUser model)
 {
     if (Request.IsAuthenticated)
     {
         if (Roles.IsUserInRole("user"))
         {
             return RedirectToAction(MVC.UserProfile.User.Index());
         }
         if (Roles.IsUserInRole("admin"))
         {
             return RedirectToAction(MVC.AdminProfile.Admin.Index());
         }
     }
     //var error = TempData["Result"];
     return View(model);
 }