Exemple #1
0
        private void Login(string key)
        {
            var tokenRepository = new TokenRepository();
            var token           = tokenRepository.GetToken(key);

            BusinessPrincipal.LoadPrincipal(token.UserName);
        }
Exemple #2
0
        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            if (!(HttpContext.Current.Handler is IRequiresSessionState))
            {
                return;
            }

            if (Csla.ApplicationContext.AuthenticationType == "Windows")
            {
                return;
            }

            IPrincipal principal = null;

            try
            {
                principal = (IPrincipal)HttpContext.Current.Session["EPIWORXUSER"];
            }
            catch
            {
                principal = null;
            }

            if (principal == null)
            {
                if (this.User.Identity.IsAuthenticated &&
                    this.User.Identity is FormsIdentity)
                {
                    BusinessPrincipal.LoadPrincipal(this.User.Identity.Name);

                    HttpContext.Current.Session["EPIWORXUSER"] = Csla.ApplicationContext.User;

                    this.Response.Redirect(this.Request.Url.PathAndQuery);
                }

                FormsAuthentication.SignOut();

                BusinessPrincipal.Logout();
            }
            else
            {
                Csla.ApplicationContext.User = principal;
            }
        }
        public ActionResult Register(RegisterModel model)
        {
            if (this.ModelState.IsValid)
            {
                BusinessPrincipal.Login();

                var user = UserService.UserNew();

                user.Name      = model.UserName;
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;
                user.Email     = model.Email;
                user.Role      = Role.Review;

                user.SetPassword(model.Password);

                user = UserService.UserSave(user);

                if (user.IsValid)
                {
                    BusinessPrincipal.Logout();

                    BusinessPrincipal.LoadPrincipal(model.UserName);

                    this.FormsService.SignIn(model.UserName, false);

                    this.Session["EPIWORXUSER"] = Csla.ApplicationContext.User;

                    return(this.RedirectToAction("Index", "Home"));
                }

                this.ModelState.AddModelError(string.Empty, user.BrokenRulesCollection.ToString(","));
            }

            return(this.View(model));
        }