예제 #1
0
        protected virtual async Task RegisterExternalUserAsync(ExternalLoginInfo externalLoginInfo, string emailAddress)
        {
            var userDto = await AccountAppService.RegisterAsync(
                new RegisterDto
            {
                AppName      = "MVC",
                EmailAddress = Input.EmailAddress,
                Password     = Input.Password,
                UserName     = Input.UserName
            }
                );

            var user = await UserManager.GetByIdAsync(userDto.Id);

            var userLoginAlreadyExists = user.Logins.Any(x =>
                                                         x.TenantId == user.TenantId &&
                                                         x.LoginProvider == externalLoginInfo.LoginProvider &&
                                                         x.ProviderKey == externalLoginInfo.ProviderKey);

            if (!userLoginAlreadyExists)
            {
                (await UserManager.AddLoginAsync(user, new UserLoginInfo(
                                                     externalLoginInfo.LoginProvider,
                                                     externalLoginInfo.ProviderKey,
                                                     externalLoginInfo.ProviderDisplayName
                                                     ))).CheckErrors();
            }

            await SignInManager.SignInAsync(user, true);
        }
        protected virtual async Task RegisterLocalUserAsync()
        {
            ValidateModel();

            var userDto = await AccountAppService.RegisterAsync(
                new RegisterDto
                {
                    AppName = "MVC",
                    EmailAddress = Input.EmailAddress,
                    Password = Input.Password,
                    UserName = Input.UserName
                }
            );

            var user = await UserManager.GetByIdAsync(userDto.Id);
            await SignInManager.SignInAsync(user, isPersistent: true);
        }
예제 #3
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            await CheckSelfRegistrationAsync();

            var registerDto = new RegisterDto()
            {
                AppName = "MVC"
            };

            if (IsExternalLogin)
            {
                var externalLoginInfo = await SignInManager.GetExternalLoginInfoAsync();

                if (externalLoginInfo == null)
                {
                    Logger.LogWarning("External login info is not available");
                    return(RedirectToPage("./Login"));
                }

                registerDto.EmailAddress = Input.EmailAddress;
                registerDto.UserName     = Input.EmailAddress;
                registerDto.Password     = GeneratePassword();
            }
            else
            {
                ValidateModel();

                registerDto.EmailAddress = Input.EmailAddress;
                registerDto.Password     = Input.Password;
                registerDto.UserName     = Input.UserName;
            }

            var userDto = await AccountAppService.RegisterAsync(registerDto);

            var user = await UserManager.GetByIdAsync(userDto.Id);

            await SignInManager.SignInAsync(user, isPersistent : false);

            if (IsExternalLogin)
            {
                await AddToUserLogins(user);
            }

            return(Redirect(ReturnUrl ?? "~/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow!
        }
예제 #4
0
        protected override async Task RegisterLocalUserAsync()
        {
            ValidateModel();

            var userDto = await AccountAppService.RegisterAsync(
                new RegisterDto
            {
                AppName      = "Abp.EmailMarketing",
                EmailAddress = Input.EmailAddress,
                Password     = Input.Password,
                UserName     = Input.UserName
            }
                );

            _abpIdentityUser = await UserManager.GetByIdAsync(userDto.Id);

            // Send user an email to confirm email address
            await SendEmailToAskForEmailConfirmationAsync(_abpIdentityUser);
        }
예제 #5
0
        [UnitOfWork] //TODO: Will be removed when we implement action filter
        public virtual async Task <IActionResult> OnPostAsync()
        {
            ValidateModel();

            await CheckSelfRegistrationAsync();

            var registerDto = new RegisterDto {
                AppName      = "MVC",
                EmailAddress = Input.EmailAddress,
                Password     = Input.Password,
                UserName     = Input.UserName
            };

            var userDto = await AccountAppService.RegisterAsync(registerDto);

            var user = await UserManager.GetByIdAsync(userDto.Id);

            await UserManager.SetEmailAsync(user, Input.EmailAddress);

            await SignInManager.SignInAsync(user, isPersistent : false);

            return(Redirect(ReturnUrl ?? "/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow!
        }