예제 #1
0
 public ActionResult EditUser(ProfileViewModel user)
 {
     if (ModelState.IsValid)
     {
         using (UsersContext context = new UsersContext())
         {
             var user2 = context.GetUser(User.Identity.Name);
             if (context.GetUsers().Any(m => m.login == user.login && m.id != user.id))
             {
                 ViewBag.ErrorMessage = "Taki login już istnieje";
             }
             else
             {
                 user.id = user2.id;
                 profileModel.EditProfile(user);
             }
         }
     }
     UserModel model = new UserModel()
     {
         PasswordModel = new LocalPasswordModel(),
         ProfileModel = user
     };
     return View("Manage", model);
 }
예제 #2
0
 public override string[] FindUsersInRole(string roleName, string usernameToMatch)
 {
     using (var usersContext = new UsersContext())
     {
         return usersContext.GetUsers().Where(m => m.type == roleName && m.login.Contains(usernameToMatch)).Select(m => m.login).ToArray();
     }
 }
예제 #3
0
 public int GetUserId()
 {
     var userName = User.Identity.Name;
     using (UsersContext context = new UsersContext())
     {
         var user = context.GetUsers().First(m => m.login == userName);
         return user.id;
     }
 }
예제 #4
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    using (UsersContext context = new UsersContext())
                    {
                        if (!context.GetUsers().Any(m => m.login == model.Login))
                        {
                            context.AddUser(new Profile()
                            {
                                firstname = model.Firstname,
                                surname = model.Surname,
                                password = model.Password,
                                type = "user",
                                login = model.Login
                            });
                            return RedirectToAction("Index", "Home");
                        }
                        else
                        {
                            ModelState.AddModelError("", "Istnieje już użytkownik o takim loginie!");
                        }
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #5
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                using (UsersContext context = new UsersContext())
                {
                    var user = context.GetUsers().SingleOrDefault(m => m.login == model.Login && m.password == model.Password);
                    if (user != null)
                    {
                        // FormsAuthentication.SetAuthCookie(user.UzytkownikID, model.RememberMe);
                        FormsAuthentication.SetAuthCookie(model.Login, model.RememberMe);
                        return RedirectToLocal(returnUrl);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Login lub hasło jest niepoprawne!");
            return View(model);
        }
예제 #6
0
 public override string[] GetUsersInRole(string roleName)
 {
     using (var usersContext = new UsersContext())
     {
         return usersContext.GetUsers().Where(m => m.type == roleName).Select(m => m.login).ToArray();
     }
 }