public ActionResult Add(string username, string password)
        {
            var user = Users.Get(username);

            if (user != null)
            {
                ModelState.AddModelError("user-exists", "user already exists");

                ViewBag.Title = "Create Account";
                return View("AddOrAuthenticateForm");
            }

            user = new User(username, password);

            Users.Add(user);
            CreateSession(user);

            return RedirectHome();
        }
        private void CreateSession(User user)
        {
            Session = new Session(user);
            Sessions.Add(Session);

            Response.Cookies.Set(new HttpCookie(SessionIdCookieName)
            {
                Value = Session.Id
            });
        }
Пример #3
0
 public Session(User user)
 {
     Id = Guid.NewGuid().ToString();
     User = user;
 }
 public void Add(User user)
 {
     _users.Add(user);
 }