示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var UserId = TempData.Get <string>("resetPasswordUserId");

            TempData.Remove("resetPasswordUserId");
            AppUser = Context.User.FirstOrDefault(x => x.Id == long.Parse(UserId) && x.IsActive);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }
            else if (AppUser == null)
            {
                TempData["PasswordResetMessage"] = "Kullanıcıya ulaşılamadı";
                return(Redirect("/account/passwordreset"));
            }

            var Email = new OkurdostuEmail((IEmailConfiguration)HttpContext?.RequestServices.GetService(typeof(IEmailConfiguration)))
            {
                SenderMail = "*****@*****.**",
                SenderName = "Okurdostu"
            };

            var preCreatedPaswordReset = Context.UserPasswordReset.Where(x => x.UserId == AppUser.Id && !x.IsUsed).Include(x => x.User).ToList().LastOrDefault();
            var elapsedTime            = DateTime.Now - preCreatedPaswordReset?.CreatedOn;

            if (preCreatedPaswordReset != null && elapsedTime.Value.Hours < 11.5)
            {
                Email.Send(Email.PasswordResetMail(preCreatedPaswordReset.User.FullName, preCreatedPaswordReset.User.Email, preCreatedPaswordReset.GUID));
            }
            else
            {
                var UserPaswordReset = new UserPasswordReset()
                {
                    UserId = AppUser.Id
                };
                await Context.AddAsync(UserPaswordReset);

                var result = await Context.SaveChangesAsync();

                if (result > 0)
                {
                    Email.Send(Email.PasswordResetMail(AppUser.FullName, AppUser.Email, UserPaswordReset.GUID));
                }
            }
            return(Redirect("/account/passwordreset/successent"));
        }
        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));
        }
        public async Task <IActionResult> CreateEmailChangeRequest(ProfileModel Model)
        {
            AuthenticatedUser = await GetAuthenticatedUserFromDatabaseAsync();

            if (TempData.Get <bool>("IsEmailChangingConfirmedwithPasswordForPost"))
            {
                TempData.Clear();

                Model.Email = Model.Email.ToLower();

                bool IsThereAnyUserWithThatEmailAdress = await Context.User.AnyAsync(x => x.Email == Model.Email);

                if (IsThereAnyUserWithThatEmailAdress is false)
                {
                    if (AuthenticatedUser.Email != Model.Email)
                    {
                        var Email = new OkurdostuEmail((IEmailConfigurationService)HttpContext?.RequestServices.GetService(typeof(IEmailConfigurationService)))
                        {
                            SenderMail = "*****@*****.**",
                            SenderName = "Okurdostu"
                        };

                        var RequestWithSameEmailandUser = await Context.UserEmailConfirmation.FirstOrDefaultAsync(x => x.NewEmail == Model.Email && x.UserId == AuthenticatedUser.Id && !x.IsUsed);

                        if (RequestWithSameEmailandUser == null)
                        {
                            var UserEmailConfirmation = new UserEmailConfirmation() //UserEmailConfirmation'u oluştur
                            {
                                UserId   = AuthenticatedUser.Id,
                                NewEmail = Model.Email,
                            };

                            await Context.AddAsync(UserEmailConfirmation);

                            var result = await Context.SaveChangesAsync();

                            if (result > 0)
                            {
                                Email.Send(Email.EmailAddressChangeMail(AuthenticatedUser.FullName, UserEmailConfirmation.NewEmail, UserEmailConfirmation.GUID));
                                TempData["ProfileMessage"] = "Yeni e-mail adresinize (" + UserEmailConfirmation.NewEmail + ") onaylamanız için bir e-mail gönderildi" +
                                                             "<br>" +
                                                             "Onaylayana kadar şuan ki e-mail adresiniz geçerli kalacaktır.";
                            }
                            else
                            {
                                TempData["ProfileMessage"] = "Bir değişiklik yapılamadı";
                            }
                        }
                        else
                        {
                            Email.Send(Email.EmailAddressChangeMail(AuthenticatedUser.FullName, RequestWithSameEmailandUser.NewEmail, RequestWithSameEmailandUser.GUID));
                            TempData["ProfileMessage"] = "Yeni e-mail adresinize (" + RequestWithSameEmailandUser.NewEmail + ") onaylamanız için bir e-mail gönderildi";
                        }
                    }
                    else
                    {
                        TempData["ProfileMessage"] = "Şuan ki e-mail adresiniz ile aynı değeri giriyorsunuz";
                    }
                }
                else
                {
                    TempData["ProfileMessage"] = "Bu email adresini kullanamazsınız";
                }
            }

            return(Redirect("/" + AuthenticatedUser.Username));
        }
示例#4
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());
        }