예제 #1
0
        public ActionResult EnableUserBlock(UserBlockViewModel model)
        {
            var user = db.Users.Find(model.UserId);

            if (user != null)
            {
                //same user
                user.IsBlocked       = false;
                user.BlockedbyUserId = 0;
                user.BlockingReason  = "";
                db.Entry(user).State = EntityState.Modified;
                if (SaveDatabase(ViewStates.EditPost, user))
                {
                    var currentUserName = UserManager.GetCurrentUser().DisplayName;

                    var mailBody = MailHtml.ReleasedFromBlockEmailHtml(user, currentUserName, true);

                    AppVar.Mailer.Send(user.Email, "You have been re-enabled.", mailBody, "Enabled");

                    return(RedirectToAction("Index"));
                }
                AppVar.SetErrorStatus(ViewBag, EditedError);
                return(View(user));
            }
            AppVar.SetErrorStatus(ViewBag, EditedError);
            return(View(user));
        }
예제 #2
0
        public ActionResult UserBlock(UserBlockViewModel model)
        {
            var user = db.Users.Find(model.UserId);

            if (user != null)
            {
                //same user
                user.IsBlocked       = true;
                user.BlockedbyUserId = UserManager.GetLoggedUserId();
                db.Entry(user).State = EntityState.Modified;
                if (SaveDatabase(ViewStates.EditPost, user))
                {
                    var currentUserName = UserManager.GetCurrentUser().DisplayName;

                    var mailBody = MailHtml.BlockEmailHtml(user, model.Reason, currentUserName);

                    AppVar.Mailer.Send(user.Email, "You have been blocked.", mailBody, "Blocking");

                    return(RedirectToAction("Index"));
                }
                AppVar.SetErrorStatus(ViewBag, EditedError);
                return(View(user));
            }
            AppVar.SetErrorStatus(ViewBag, EditedError);
            return(View("_404"));
        }
예제 #3
0
        private string GetEmailBody(Feedback feedback, string department = "Administrator")
        {
            var sb   = new StringBuilder(100);
            var user = UserManager.GetUser(feedback.Username);

            MailHtml.AddGreetingsToStringBuilder(user, sb);
            sb.AppendLine("Status:");
            sb.AppendLine("<q><strong>");
            sb.AppendLine(feedback.GetStatus().Status);
            sb.AppendLine("</strong></q>");
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine("In response to your:");
            sb.AppendLine("<q><strong>");
            sb.AppendLine(feedback.Message);
            sb.AppendLine("</strong></q>");
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine("Our response:");
            sb.AppendLine("<q><strong>");
            sb.AppendLine(feedback.Response);
            sb.AppendLine("</strong></q>");
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine(MailHtml.LineBreak);
            MailHtml.AddContactUsToStringBuilder(sb);
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine(MailHtml.LineBreak);
            MailHtml.AddThanksFooterOnStringBuilder(AppVar.Setting.AdminName, department, sb);
            var mail = sb.ToString();

            sb = null;
            GC.Collect();
            return(mail);
        }
예제 #4
0
        private void SendEmailToAppDeveloper(ApplicationUser developerUser, AppModerateViewModel model)
        {
            var loggedUser     = User.GetUser();
            var loggedUsername = loggedUser.DisplayName;
            var sb             = new StringBuilder(50);

            MailHtml.AddGreetingsToStringBuilder(developerUser, sb);
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine(model.Message);
            sb.AppendLine(MailHtml.LineBreak);
            if (model.LikeToHearFromYou)
            {
                sb.AppendLine(MailHtml.LineBreak);
                sb.AppendLine(
                    MailHtml.GetStrongTag(
                        "Note: ** We would like to hear back from you. Please send your replies to '" +
                        AppVar.Setting.OfficeEmail + "' **"));
                sb.AppendLine(MailHtml.LineBreak);
            }
            sb.AppendLine(MailHtml.LineBreak);
            sb.AppendLine();
            MailHtml.AddThanksFooterOnStringBuilder(loggedUser.DisplayName, "Administrator", sb);
            var message = sb.ToString();

            sb = null;
            GC.Collect();
            var subjectToDeveloper = "A message from admin : " + loggedUsername;
            var subjectToAdmin     = "An email sent to : " + developerUser.Email + " [this mail contains the sample]";

            AppVar.Mailer.Send(developerUser.Email, subjectToDeveloper, message);
            AppVar.Mailer.Send(loggedUser.Email, subjectToAdmin, message);
        }
예제 #5
0
        private async void SendResetPasswordLinkToUser(ApplicationUser user)
        {
            var code        = Manager.GenerateUserToken(TokenPurpose.ResetPassword, user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Account",
                                         new { userId = user.Id, email = user.Email, code, guid = user.GeneratedGuid }, Request.Url.Scheme);
            var mailString = MailHtml.PasswordResetHtml(user, callbackUrl);

            AppVar.Mailer.Send(user.Email, "Reset Password", mailString);
        }
예제 #6
0
        private async void SendConfirmationEmail(ApplicationUser user)
        {
            var code        = Manager.GenerateEmailConfirmationToken(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                         new { userId = user.Id, code, codeHashed = user.GeneratedGuid }, Request.Url.Scheme);
            var mailString = MailHtml.EmailConfirmHtml(user, callbackUrl);

            AppVar.Mailer.Send(user.Email, "Email Confirmation", mailString);
        }
        //[CompressFilter(Order = 1)]
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var errors = new ErrorCollector();
            //External Validation.
            var validOtherConditions = await UserManager.ExternalUserValidation(model, _db, errors);

            if (ModelState.IsValid && validOtherConditions)
            {
                var user   = UserManager.GetUserFromViewModel(model); // get user from view model.
                var result = await Manager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    SignInProgrammatically(user, false);
                    if (model.Role == -1)
                    {
                    }
                    RoleManager.AddTempRoleInfo(user, model.Role);

                    if (AppVar.Setting.IsConfirmMailRequired && AppVar.Setting.IsFirstUserFound)
                    {
                        // mail needs to be confirmed.
                        // first user is already registered
                        #region Send an email to the user about mail confirmation

                        var code        = Manager.GenerateEmailConfirmationToken(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                                     new { userId = user.Id, code, codeHashed = user.GeneratedGuid }, Request.Url.Scheme);
                        var mailString = MailHtml.EmailConfirmHtml(user, callbackUrl);
                        AppVar.Mailer.Send(user.Email, "Email Confirmation", mailString);

                        #endregion

                        #region Sign out because registration is not complete

                        return(SignOutProgrammatically());

                        #endregion
                    }
                    if (!AppVar.Setting.IsFirstUserFound)
                    {
                        // first user is not registered yet
                        #region Send an email to the user about mail confirmation

                        var code        = Manager.GenerateEmailConfirmationToken(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                                     new { userId = user.Id, code, codeHashed = user.GeneratedGuid }, Request.Url.Scheme);
                        var mailString = MailHtml.EmailConfirmHtml(user, callbackUrl);
                        AppVar.Mailer.Send(user.Email, "Email Confirmation", mailString);

                        #endregion
                    }
                    CallCompleteRegistration(user.UserID);
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            ViewBag.Roles = new SelectList(RoleManager.GetRoles(), "Id", "Name");
            return(View(model));
        }