Example #1
0
        public async Task <ViewResult> Create(SignupData signupData)
        {
            var ip = HttpContext.Connection.RemoteIpAddress.ToString();

            if (_config.UseReCaptcha)
            {
                var reCaptchaResponse = await _reCaptchaService.VerifyToken(signupData.Token, ip);

                if (!reCaptchaResponse.IsSuccess)
                {
                    ModelState.AddModelError("Email", Resources.BotError);
                }
            }
            await ValidateSignupData(signupData, ModelState, ip);

            if (ModelState.IsValid)
            {
                var user = await _userService.CreateUser(signupData, ip);

                await _profileService.Create(user, signupData);

                // TODO: get rid of FullUrlHelper extension
                var verifyUrl = this.FullUrlHelper("Verify", "Account");
                var result    = _newAccountMailer.Send(user, verifyUrl);
                if (result != SmtpStatusCode.Ok)
                {
                    ViewData["EmailProblem"] = Resources.EmailProblemAccount + (result?.ToString() ?? "App exception") + ".";
                }
                if (_settingsManager.Current.IsNewUserApproved)
                {
                    ViewData["Result"] = Resources.AccountReady;
                    await _userService.Login(user, ip);
                }
                else
                {
                    ViewData["Result"] = Resources.AccountReadyCheckEmail;
                }

                var loginState = _externalLoginTempService.Read();
                if (loginState != null)
                {
                    var externalLoginInfo = new ExternalLoginInfo(loginState.ProviderType.ToString(), loginState.ResultData.ID, loginState.ResultData.Name);
                    await _externalUserAssociationManager.Associate(user, externalLoginInfo, ip);

                    _externalLoginTempService.Remove();
                }

                await IdentityController.PerformSignInAsync(user, HttpContext);

                return(View("AccountCreated"));
            }
            SetupCreateData();
            return(View(signupData));
        }
Example #2
0
        public async Task <ViewResult> Create(SignupData signupData)
        {
            var ip = HttpContext.Connection.RemoteIpAddress.ToString();

            ValidateSignupData(signupData, ModelState, ip);
            if (ModelState.IsValid)
            {
                var user = _userService.CreateUser(signupData, ip);
                _profileService.Create(user, signupData);
                // TODO: get rid of FullUrlHelper extension
                var verifyUrl = this.FullUrlHelper("Verify", "Account");
                var result    = _newAccountMailer.Send(user, verifyUrl);
                if (result != SmtpStatusCode.Ok)
                {
                    ViewData["EmailProblem"] = Resources.EmailProblemAccount + (result?.ToString() ?? "App exception") + ".";
                }
                if (_settingsManager.Current.IsNewUserApproved)
                {
                    ViewData["Result"] = Resources.AccountReady;
                    _userService.Login(user, ip);
                }
                else
                {
                    ViewData["Result"] = Resources.AccountReadyCheckEmail;
                }

                var authResult = await AuthorizationController.GetExternalLoginInfoAsync(HttpContext);

                if (authResult != null)
                {
                    _externalUserAssociationManager.Associate(user, authResult, ip);
                }

                await AuthorizationController.PerformSignInAsync(user, HttpContext);

                return(View("AccountCreated"));
            }
            SetupCreateData();
            return(View(signupData));
        }
Example #3
0
        public async Task <ViewResult> Create(SignupData signupData)
        {
            signupData.Validate(ModelState, _userService, HttpContext.Request.UserHostAddress);
            if (ModelState.IsValid)
            {
                var user = _userService.CreateUser(signupData, HttpContext.Request.UserHostAddress);
                _profileService.Create(user, signupData);
                var verifyUrl = this.FullUrlHelper("Verify", "Account");
                var result    = _newAccountMailer.Send(user, verifyUrl);
                if (result != System.Net.Mail.SmtpStatusCode.Ok)
                {
                    ViewData["EmailProblem"] = Resources.EmailProblemAccount + result + ".";
                }
                if (_settingsManager.Current.IsNewUserApproved)
                {
                    ViewData["Result"] = Resources.AccountReady;
                    _userService.Login(user.Email, signupData.Password, false, HttpContext);
                }
                else
                {
                    ViewData["Result"] = Resources.AccountReadyCheckEmail;
                }

                var authentication = _owinContext.Authentication;
                var authResult     = await _externalAuthentication.GetAuthenticationResult(authentication);

                if (authResult != null)
                {
                    _userAssociationManager.Associate(user, authResult, HttpContext.Request.UserHostAddress);
                }

                return(View("AccountCreated"));
            }
            SetupCreateData();
            return(View(signupData));
        }
        public async Task <ViewResult> ChangeEmail(UserEditSecurity userEdit)
        {
            var user = _userRetrievalShim.GetUser();

            if (user == null)
            {
                return(View("EditAccountNoUser"));
            }
            if (string.IsNullOrWhiteSpace(userEdit.NewEmail) || !userEdit.NewEmail.IsEmailAddress())
            {
                ViewBag.EmailResult = Resources.ValidEmailAddressRequired;
            }
            else if (userEdit.NewEmail != userEdit.NewEmailRetype)
            {
                ViewBag.EmailResult = Resources.EmailsMustMatch;
            }
            else if (await _userService.IsEmailInUseByDifferentUser(user, userEdit.NewEmail))
            {
                ViewBag.EmailResult = Resources.EmailInUse;
            }
            else
            {
                await _userService.ChangeEmail(user, userEdit.NewEmail, user, HttpContext.Connection.RemoteIpAddress.ToString());

                if (_settingsManager.Current.IsNewUserApproved)
                {
                    ViewBag.EmailResult = Resources.EmailChangeSuccess;
                }
                else
                {
                    ViewBag.EmailResult = Resources.VerificationEmailSent;
                    var verifyUrl = this.FullUrlHelper("Verify", "Account");
                    var result    = _newAccountMailer.Send(user, verifyUrl);
                    if (result != SmtpStatusCode.Ok)
                    {
                        ViewBag.EmailResult = Resources.EmailProblemAccount + result;
                    }
                }
            }
            return(View("Security", new UserEditSecurity {
                NewEmail = String.Empty, NewEmailRetype = String.Empty, IsNewUserApproved = _settingsManager.Current.IsNewUserApproved
            }));
        }