예제 #1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var emailExists = this.userProfileRepository.FindByEmail(model.Email);
            if (emailExists != null)
            {
                this.ModelState.AddModelError("", "Sorry, unable to register with this email address.");
                return this.View(model);
            }

            var mailAddress = new MailAddress(model.Email);
            var institution = this.institutionRepository.All.FirstOrDefault(i => mailAddress.Host.Contains(i.ShortName));
            if (institution == null)
            {
                this.ModelState.AddModelError("", "Sorry, the domain name in your email address does not match the name of an academic institution known to us. If you want your institution to be included in our list, please enter it’s name and web address in our contact box and we will respond promptly.");
                return this.View(model);
            }

            model.InstitutionId = institution.Id;
            model.DisplayName = model.UserName;
            model.DateRegistered = DateTime.Now;

            try
            {
                var confirmationToken = this.authentication.CreateUserAndAccount(model.UserName, model.Password, new { model.Email, model.DisplayName, model.DateRegistered, model.InstitutionId, model.OrcId });

                if (string.IsNullOrEmpty(model.AddLink))
                {
                    dynamic email = new Email("RegistrationEmail");
                    email.To = model.Email;
                    email.DisplayName = model.DisplayName;
                    email.Url = this.Url.Action("RegisterConfirmation", "Account", new { token = confirmationToken }, this.Request.Url.Scheme);
                    email.Send();

                    return this.RedirectToAction("RegistrationPending");
                }

                if (!this.Authentication.ConfirmAccount(confirmationToken))
                {
                    return this.RedirectToAction("RegisterFailure");
                }

                var loginViewModel = new LoginViewModel { Email = model.Email, Password = model.Password, RememberMe = false };

                this.Login(loginViewModel, model.AddLink);

                return this.RedirectToAction("RegisterSuccessWithLink", "Account", new { addLink = model.AddLink });
            }
            catch (MembershipCreateUserException)
            {
                this.ModelState.AddModelError("", "Can't create the user.");
            }

            return View(model);
        }
예제 #2
0
        public ActionResult Register(string addLink, string loginAddress)
        {
            if (string.IsNullOrEmpty(addLink) && string.IsNullOrEmpty(loginAddress))
            {
                return this.View();
            }

            var model = new RegisterViewModel { AddLink = addLink, Email = loginAddress };
            this.ViewBag.ShortRegistration = true;

            return this.View(model);
        }