Ejemplo n.º 1
0
        public async Task <IActionResult> SendConfirmationEmail() //it's used on /beta/index page
        {
            //if user doesn't confirm their email, user will see a warning on beta/index page.
            //and this httppost coming there.
            AuthenticatedUser = await GetAuthenticatedUserFromDatabaseAsync();

            if (!AuthenticatedUser.IsEmailConfirmed)
            {
                var _UserEmailConfirmation = await Context.UserEmailConfirmation.FirstOrDefaultAsync(x => x.UserId == AuthenticatedUser.Id && !x.IsUsed);

                var Email = new OkurdostuEmail((IEmailConfigurationService)HttpContext?.RequestServices.GetService(typeof(IEmailConfigurationService)))
                {
                    SenderMail = "*****@*****.**",
                    SenderName = "Halil İbrahim Kocaöz"
                };

                Guid confirmationGuid;
                if (_UserEmailConfirmation != null)
                {
                    confirmationGuid = _UserEmailConfirmation.GUID;
                }
                else
                {
                    var newUserEmailConfirmation = new UserEmailConfirmation()
                    {
                        UserId = AuthenticatedUser.Id,
                    };
                    await Context.AddAsync(newUserEmailConfirmation);

                    await Context.SaveChangesAsync();

                    confirmationGuid = newUserEmailConfirmation.GUID;
                }

                Email.Send(Email.NewUserMail(AuthenticatedUser.FullName, AuthenticatedUser.Email, confirmationGuid));
                TempData["ProfileMessage"] = AuthenticatedUser.Email + " adresine yeni bir onay maili gönderildi";
            }

            return(Redirect("/" + AuthenticatedUser.Username));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(SignUpModel Model, string ReturnUrl)
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }
            if (!ModelState.IsValid)
            {
                TempData["SignUpMessage"] = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage;
                return(Redirect("/kaydol"));
            }
            if (blockedUsernames.Any(x => Model.Username == x))
            {
                TempData["SignUpMessage"] = "Bu kullanıcı adını: " + Model.Username + " kullanamazsınız";
                return(Redirect("/kaydol"));
            }

            var User = new User
            {
                Username = Model.Username,
                Email    = Model.Email,
                Password = Model.Password.SHA512(),
                FullName = Model.FullName,
            };

            int result = 0;

            try
            {
                await Context.User.AddAsync(User);

                result = await Context.SaveChangesAsync();

                Logger.LogInformation("{username}({userid}) signed up on {datetime}", User.Username, User.Id, DateTime.Now);
            }
            catch (Exception e)
            {
                if (e.InnerException != null && e.InnerException.Message.Contains("Unique_Key_Username"))
                {
                    TempData["SignUpMessage"] = "Bu kullanıcı adını kullanamazsınız";
                }
                else if (e.InnerException != null && e.InnerException.Message.Contains("Unique_Key_Email"))
                {
                    TempData["SignUpMessage"] = "Bu e-mail adresini kullanamazsınız";
                }
                else
                {
                    Logger.LogError("Guest taking a error when trying sign up Ex message: {ex.message}, InnerEx Message: {iex.message}", e?.Message, e?.InnerException?.Message);
                    TempData["SignUpMessage"] = "Başaramadık ve ne olduğunu bilmiyoruz";
                }
            }
            if (result > 0)
            {
                await SignInWithCookie(User);

                var _UserEmailConfirmation = new UserEmailConfirmation
                {
                    UserId = User.Id
                };
                await Context.AddAsync(_UserEmailConfirmation);

                await Context.SaveChangesAsync();

                var Email = new OkurdostuEmail((IEmailConfigurationService)HttpContext?.RequestServices.GetService(typeof(IEmailConfigurationService)))
                {
                    SenderMail = "*****@*****.**",
                    SenderName = "Halil İbrahim Kocaöz"
                };

                Email.Send(Email.NewUserMail(User.FullName, User.Email, _UserEmailConfirmation.GUID));

                return(string.IsNullOrEmpty(ReturnUrl) ? Redirect("/beta") : Redirect(ReturnUrl));
            }
            else if (TempData["SignUpMessage"] == null)
            {
                TempData["SignUpMessage"] = "Sorun yaşadık, kaydolmayı tekrar deneyiniz";
            }
            return(View());
        }