示例#1
0
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Redirect("/Identity/Account/Errors/AccessDenied"));
            }

            var userId = await _userManager.GetUserIdAsync(user);

            var email = await _userManager.GetEmailAsync(user);

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { userId = userId, code = code },
                protocol: Request.Scheme);

            await _senderService.SendEmailAsync(email,
                                                "Потвърди емайл адрес",
                                                $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'> <img src='https://i.imgur.com/MOYSeFJ.jpg'> </a> <br>Изпратено с <3 от GrandJob.eu <br>София, Младост 4.");

            _baseService.ToastNotify(ToastMessageState.Info, "Информация", "Емайлът за потвърждение е изпратен. Моля проверете!", 4000);
            return(RedirectToPage());
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Input.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    _baseService.ToastNotify(ToastMessageState.Error, "Грешка", "Този емайл не съществува или операцията не може да бъде изпълнена! Моля уведомете администратор.", 10000);
                    return(Page());
                }


                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.Page(
                    "/Account/ResetPassword",
                    pageHandler: null,
                    values: new { code },
                    protocol: Request.Scheme);

                await _senderService.SendEmailAsync(Input.Email,
                                                    "Нулирай паролата си",
                                                    $"Можете да зададете нова парола, като кликнете на този <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>линк</a>.");

                _baseService.ToastNotify(ToastMessageState.Info, "", "Изпратихме ви емайл с линк към посочената от вас поща.", 3000);

                return(RedirectToAction("Index", "Home"));
            }

            return(Page());
        }
示例#3
0
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }


            var userId = await _userManager.GetUserIdAsync(user);

            var email = await _userManager.GetEmailAsync(user);

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { userId = userId, code = code },
                protocol: Request.Scheme);

            await _senderService.SendEmailAsync(email,
                                                "Потвърди емайл адрес",
                                                $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Потвърждаване</a>.");

            _baseService.ToastNotify(ToastMessageState.Info, "Информация", "Емайлът за потвърждение е изпратен. Моля проверете!", 4000);
            return(RedirectToPage());
        }
示例#4
0
        public async Task <IActionResult> OnGetAsync(string email, bool isemployer, string returnUrl = null)
        {
            if (email == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userManager.FindByEmailAsync(email);

            if (user == null)
            {
                return(NotFound($"Unable to load user with email '{email}'."));
            }

            Email      = email;
            isEmployer = isemployer;

            await _sender.SendEmailAsync(email,
                                         "Потвърди емайл адрес",
                                         $"<a href='{HtmlEncoder.Default.Encode(returnUrl)}'>Потвърждаване</a>.");

            // Once you add a real email sender, you should remove this code that lets you confirm the account
            DisplayConfirmAccountLink = true;
            if (DisplayConfirmAccountLink)
            {
                var userId = await _userManager.GetUserIdAsync(user);

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                EmailConfirmationUrl = Url.Page(
                    "/Account/ConfirmEmail",
                    pageHandler: null,
                    values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
                    protocol: Request.Scheme);
            }

            return(Page());
        }
示例#5
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (_signInManager.IsSignedIn(User))
            {
                return(LocalRedirect(returnUrl));
            }

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new User
                {
                    isExternal  = false,
                    Email       = Input.Email,
                    UserName    = StringHelper.GetUntilOrEmpty(Input.Email, "@"),
                    PictureName = null
                };



                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var email = await _userManager.GetEmailAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _senderService.SendEmailAsync(email,
                                                        "Потвърди емайл адрес",
                                                        $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Потвърждаване</a>.");

                    var count = await _userManager.Users.CountAsync().ConfigureAwait(false);

                    if (count == 1)
                    {
                        await CreateRole();

                        await _userManager.AddToRoleAsync(user, "Admin");

                        await _userManager.RemoveFromRoleAsync(user, "User");

                        user.profileConfirmed = true;
                        user.EmailConfirmed   = true;
                        user.Role             = Roles.Admin;
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, "User");

                        user.Role = Roles.User;
                    }


                    await _notifyService.Create("Моля попълнете личните си данни.", "identity/account/manage/editprofile", DateTime.Now, NotifyType.Information, "fas fa-edit", user);

                    _baseService.ToastNotify(ToastMessageState.Alert, "Детайли", "Моля попълнете личните си данни.", 9000);
                    _baseService.ToastNotify(ToastMessageState.Success, "Успешно", "се регистрирахте. Благодарим ви за отделеното време !", 5000);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
示例#6
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = Input.Email, Email = Input.Email, isEmployer = Input.IsEmployer
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        var userId = await _userManager.GetUserIdAsync(user);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);

                        await _senderService.SendEmailAsync(Input.Email,
                                                            "Потвърди емайл адрес",
                                                            $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Потвърждаване</a>.");


                        if (_userManager.Users.Count() == 1)
                        {
                            await _userManager.AddToRoleAsync(user, "Admin");

                            await _userManager.RemoveFromRoleAsync(user, "User");
                        }
                        else
                        {
                            if (Input.IsEmployer)
                            {
                                await _userManager.AddToRoleAsync(user, "Employer");
                            }
                            else
                            {
                                await _userManager.AddToRoleAsync(user, "User");
                            }
                        }

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _signInManager.SignInAsync(user, isPersistent : false, info.LoginProvider);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ProviderDisplayName = info.ProviderDisplayName;
            ReturnUrl           = returnUrl;
            return(Page());
        }
示例#7
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = StringHelper.GetUntilOrEmpty(Input.Email, "@"), Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, PictureName = Input.PictureName, Role = ((Roles)(Input.IsEmployer ? 3 : 0)), isExternal = true
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        var userId = await _userManager.GetUserIdAsync(user);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);


                        if (Input.Email != Input.EmailFromSocial)
                        {
                            await _senderService.SendEmailAsync(Input.Email,
                                                                "Потвърди емайл адрес",
                                                                $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'> <img src='https://i.imgur.com/MOYSeFJ.jpg'> </a> <br>Изпратено с <3 от GrandJob.eu <br>София, Младост 4.");
                        }
                        else
                        {
                            user.profileConfirmed = true;
                            user.EmailConfirmed   = true;

                            await _userManager.UpdateAsync(user);
                        }


                        if (_userManager.Users.Count() == 1)
                        {
                            await CreateRole();

                            await _userManager.AddToRoleAsync(user, "Admin");

                            await _userManager.RemoveFromRoleAsync(user, "User");

                            user.profileConfirmed = true;
                            user.EmailConfirmed   = true;
                            user.Role             = Roles.Admin;
                        }
                        else
                        {
                            if (Input.IsEmployer)
                            {
                                await _userManager.AddToRoleAsync(user, "Employer");

                                //user.Role = Roles.Employer;
                            }
                            else
                            {
                                await _userManager.AddToRoleAsync(user, "User");

                                //user.Role = Roles.User;
                            }
                        }

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _userManager.UpdateAsync(user);

                        await _signInManager.RefreshSignInAsync(user);

                        await _signInManager.SignInAsync(user, isPersistent : false, info.LoginProvider);


                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ProviderDisplayName = info.ProviderDisplayName;
            ReturnUrl           = returnUrl;
            return(Page());
        }