Ejemplo n.º 1
0
        public ActionResult Index(RegisterModel model)
        {
            if (ModelState.IsValidField("Email"))
            {
                // check uniqueness on the server
                var index = Global.Client.GetSingleton<LoginsIndexView>();
                if (index.ContainsLogin(model.Email))
                {
                    // could this customer be already registered???
                    // people don't confuse their emails often
                    var result = Global.Auth.PerformLoginAuth(model.Email, model.Password);
                    // OK, this could be customer trying to re-register
                    // let's log him in
                    if (result.IsSuccess)
                    {
                        return Global.Forms.HandleLogin(result.Identity, false);
                    }
                    else
                    {
                        ModelState.AddModelError("Email", string.Format("Email {0} is taken", model.Email));
                    }
                }
            }

            if (!ModelState.IsValid)
                return View("index", model);

            var newGuid = Guid.NewGuid();

            var coll = new NameValueCollection(Request.Headers);

            if (!string.IsNullOrEmpty(Request.UserHostAddress))
            {
                coll.Add("UserHostAddress", Request.UserHostAddress);
            }
            foreach (var language in Request.UserLanguages ?? new string[0])
            {
                coll.Add("UserLanguages", language);
            }

            var reg = new RegistrationInfoBuilder(model.Email, model.CompanyName)
            {
                OptionalUserPassword = model.Password,
                OptionalCompanyPhone = model.ContactPhone,
                Headers = coll,
                OptionalUserName = model.RealName
            };
            Global.Client.SendOne(new CreateRegistration(new RegistrationId(newGuid), reg.Build()));

            return View("wait", new RegisterWaitModel
            {
                RegistrationId = newGuid,
                CompanyName = model.CompanyName,
                ContactPhone = model.ContactPhone,
                Email = model.Email,
                Password = model.Password,
                RealName = model.RealName
            });
        }
Ejemplo n.º 2
0
        public ActionResult Index(RegisterModel model)
        {
            if (ModelState.IsValidField("Email"))
            {
                // check uniqueness on the server
                var index = Global.Client.GetSingleton <LoginsIndexView>();
                if (index.ContainsLogin(model.Email))
                {
                    // could this customer be already registered???
                    // people don't confuse their emails often
                    var result = Global.Auth.PerformLoginAuth(model.Email, model.Password);
                    // OK, this could be customer trying to re-register
                    // let's log him in
                    if (result.IsSuccess)
                    {
                        return(Global.Forms.HandleLogin(result.Identity, false));
                    }
                    else
                    {
                        ModelState.AddModelError("Email", string.Format("Email {0} is taken", model.Email));
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(View("index", model));
            }



            var newGuid = Guid.NewGuid();

            var coll = new NameValueCollection(Request.Headers);

            if (!string.IsNullOrEmpty(Request.UserHostAddress))
            {
                coll.Add("UserHostAddress", Request.UserHostAddress);
            }
            foreach (var language in Request.UserLanguages ?? new string[0])
            {
                coll.Add("UserLanguages", language);
            }

            var reg = new RegistrationInfoBuilder(model.Email, model.CompanyName)
            {
                OptionalUserPassword = model.Password,
                OptionalCompanyPhone = model.ContactPhone,
                Headers          = coll,
                OptionalUserName = model.RealName
            };

            Global.Client.SendOne(new CreateRegistration(new RegistrationId(newGuid), reg.Build()));

            return(View("wait", new RegisterWaitModel
            {
                RegistrationId = newGuid,
                CompanyName = model.CompanyName,
                ContactPhone = model.ContactPhone,
                Email = model.Email,
                Password = model.Password,
                RealName = model.RealName
            }));
        }