コード例 #1
0
        internal EmailResult ForgotPasswordMail(ForgotPasswordMailModel model)
        {
            To.Add(model.User.Email);
            Subject = "Passwort zurücksetzen";

            return(Email("ForgotPassword", model));
        }
コード例 #2
0
        internal EmailResult ForgotPasswordMail(ForgotPasswordMailModel model)
        {
            InitSenderTopic(MAIL_SECTION_ACCOUNT);

            To.Add(model.User.Email);
            Subject = "Passwort zurücksetzen";

            return(Email("ForgotPassword", model));
        }
コード例 #3
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await _userManager.FindByEmailAsync(model.Email);

                    if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                    {
                        // Don't reveal that the user does not exist or is not confirmed
                        return(View("ForgotPasswordConfirmation"));
                    }

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                    string callbackUrl = Url.Action(nameof(ResetPassword), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    ForgotPasswordMailModel mailModel = new ForgotPasswordMailModel();
                    mailModel.Name              = user.FullName;
                    mailModel.message           = callbackUrl;
                    mailModel.ValidHours        = _localizer["Use this link to reset your password. The link is only valid for 24 hours."];
                    mailModel.HeaderInformation = _localizer["You recently requested to reset your password for your The Renewal Center account. Use the button below to reset it."];
                    mailModel.ResetLink         = _localizer["Reset your password"];
                    mailModel.Hi          = _localizer["Hi there!"];
                    mailModel.Thanks      = _localizer["Thank you!"];
                    mailModel.RenewalTeam = _localizer["The Renewal Center Team"];

                    string template = await _viewRenderService.RenderToStringAsync("Shared/_ForgotPasswordMail", mailModel);

                    await _emailSender.SendEmailAsync(model.Email, _localizer["Reset Password"], callbackUrl, user.FullName, template);

                    return(View("ForgotPasswordConfirmation"));
                }

                // If we got this far, something failed, redisplay form
                return(View(model));
            }
            catch (Exception ex)
            {
                log = new EventLog()
                {
                    EventId = (int)LoggingEvents.GET_ITEM, LogLevel = LogLevel.Error.ToString(), Message = ex.Message, StackTrace = ex.StackTrace, Source = ex.Source
                };
                _loggerService.SaveEventLogAsync(log);
                return(RedirectToAction("Error", "Error500", new ErrorViewModel()
                {
                    Error = ex.Message
                }));
            }
        }
コード例 #4
0
        internal EmailResult InvitationMail(ForgotPasswordMailModel model, ApplicationUser sender, string language)
        {
            From = new MailAddress(sender.Email,
                                   sender.FirstName + " " + sender.LastName + " (via NINE)").ToString();

            To.Add(model.User.Email);
            Subject = model.CustomSubject;

            foreach (var attachment in model.Attachments)
            {
                Attachments.Add(attachment.FileName, attachment.Bytes);
            }


            return(Email(GetTemplate("Invitation", language), model));
        }
コード例 #5
0
        /// <summary>
        /// Versand von Einladungen als Benutzer
        /// </summary>
        /// <param name="model"></param>
        /// <param name="sender"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        internal EmailResult InvitationMail(ForgotPasswordMailModel model, ApplicationUser sender, string language)
        {
            InitSenderTopic(MAIL_SECTION_ACCOUNT);


            To.Add(model.User.Email);
            CC.Add(sender.Email);
            Subject = model.CustomSubject;

            foreach (var attachment in model.Attachments)
            {
                Attachments.Add(attachment.FileName, attachment.Bytes);
            }


            return(Email(GetTemplate("Invitation", language), model));
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: sbrinkhorst/NINE
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                // ACHTUNG:
                // die alten Benutzerkonten haben einen eigenen Benutzernamen
                // bei den neuen Benutzerkonten sind Benutzername und Email in sync!
                // d.h. wenn der Benutzer seine E-Mail Adresse ändert, so wird auch sein
                // Benutzername geändert!
                // wenn jetzt der Benutzer noch seinen Benutzernamen weiss, dann auch das prüfen
                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    user = await UserManager.FindByNameAsync(model.Email);
                }

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                //var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                var mailModel = new ForgotPasswordMailModel
                {
                    User  = user,
                    Token = code,
                };

                new MailController().ForgotPasswordMail(mailModel).Deliver();

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #7
0
        public ActionResult SendInvitations(OccurrenceMailingModel model)
        {
            var host = AppUser;

            var invitationList = Session["InvitationList"] as InvitationCheckModel;

            var semSubService = new SemesterSubscriptionService();

            // Keine Liste
            // Vermutung, die Session ist abgelaufen
            if (invitationList == null)
            {
                return(View("SendInvitationsError"));
            }

            var attachmentList = new List <CustomMailAttachtmentModel>();

            foreach (var attachment in model.Attachments)
            {
                if (attachment != null)
                {
                    var bytes = new byte[attachment.ContentLength];
                    attachment.InputStream.Read(bytes, 0, attachment.ContentLength);

                    attachmentList.Add(new CustomMailAttachtmentModel
                    {
                        FileName = Path.GetFileName(attachment.FileName),
                        Bytes    = bytes,
                    });
                }
            }



            foreach (var invitation in invitationList.Invitations.Where(i => i.Invite))
            {
                invitation.Invited = false;

                var now  = DateTime.Now;
                var user = new ApplicationUser
                {
                    UserName       = invitation.Email,
                    Email          = invitation.Email,
                    FirstName      = invitation.FirstName,
                    LastName       = invitation.LastName,
                    Registered     = now,
                    MemberState    = MemberState.Student,
                    Remark         = "Einladung von " + host.FullName,
                    ExpiryDate     = null,   // Einladung bleibt dauerhaft bestehen - Deprovisionierung automatisch
                    Submitted      = now,
                    EmailConfirmed = true,   // damit ist auch ein "ForgotPassword" möglich, auch wenn er die Einladung nicht angenommen hat.
                    IsApproved     = true,   // Damit bekommt der Nutzer von Anfang an E-Mails
                    Faculty        = host.Id // Benutzer der eingeladen hat
                };

                // Benutzer anlegen, mit Dummy Passwort


                //string pswd = Membership.GeneratePassword(10, 2);

                var result = UserManager.Create(user, "Pas1234?");
                if (result.Succeeded)
                {
                    // analog Forget E-Mail Versand
                    string code = UserManager.GeneratePasswordResetToken(user.Id);

                    var mailModel = new ForgotPasswordMailModel
                    {
                        User          = user,
                        Token         = code,
                        CustomSubject = model.Subject,
                        CustomBody    = model.Body,
                        Attachments   = attachmentList,
                        IsNewAccount  = true,
                    };


                    try
                    {
                        new MailController().InvitationMail(mailModel, host, model.TemplateLanguage).Deliver();

                        // Student anlegen
                        var student = Db.Students.FirstOrDefault(x => x.UserId.Equals(user.Id));

                        if (student == null)
                        {
                            var sem = SemesterService.GetSemester(invitation.Semester);

                            var org = Db.Organisers.SingleOrDefault(x =>
                                                                    x.ShortName.Equals(invitation.Organiser));

                            var curr = org.Curricula.SingleOrDefault(c => c.ShortName.Equals(invitation.Curriculum));


                            student = new Student
                            {
                                Created       = DateTime.Now,
                                Curriculum    = curr,
                                FirstSemester = sem,
                                UserId        = user.Id
                            };

                            Db.Students.Add(student);
                            Db.SaveChanges();
                        }

                        //semSubService.Subscribe(user.Id, invitation.SemGroup.Id);

                        invitation.Invited = true;
                    }
                    catch (SmtpFailedRecipientException ex)
                    {
                        invitation.Remark = ex.Message;
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        invitation.Remark += error;
                    }
                }
            }


            var deliveryMailModel = new GenericMailDeliveryModel
            {
                Subject         = model.Subject,
                Receiver        = host,
                TemplateContent = new UserMailModel
                {
                    CustomBody = model.Body,
                }
            };


            // Mail an Einladenden versenden
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms, Encoding.Default);


            writer.Write(
                "Name;Vorname;E-Mail;Versand;Bemerkung");

            writer.Write(Environment.NewLine);

            foreach (var delivery in invitationList.Invitations)
            {
                writer.Write("{0};{1};{2};{3};{4}",
                             delivery.LastName, delivery.FirstName, delivery.Email,
                             (delivery.Invite && delivery.Invited) ? "OK" : "FEHLER",
                             delivery.Remark);
                writer.Write(Environment.NewLine);
            }

            writer.Flush();
            writer.Dispose();

            var sb = new StringBuilder();

            sb.Append("Versandbericht");
            sb.Append(".csv");

            deliveryMailModel.Attachments.Add(new CustomMailAttachtmentModel
            {
                FileName = sb.ToString(),
                Bytes    = ms.GetBuffer()
            });

            try
            {
                new MailController().GenericMail(deliveryMailModel).Deliver();
            }
            catch (Exception ex)
            {
                var logger = LogManager.GetLogger("SendMail");
                logger.ErrorFormat("Mailsent failed: {0}", ex.Message);
            }

            return(View("SendInvitationsSuccess", invitationList));
        }
コード例 #8
0
        public ActionResult Import(InvitationFileModel model)
        {
            var invitationList = CreateCheckModel(model);
            var host           = GetCurrentUser();

            var studentService = new StudentService(Db);

            /*
             * if (!string.IsNullOrEmpty(invitationList.Error))
             *  return View("InvitationList", invitationList);
             */


            foreach (var invitation in invitationList.Invitations)
            {
                var user = UserManager.FindByEmail(invitation.Email);

                if (user == null)
                {
                    var now = DateTime.Now;
                    user = new ApplicationUser
                    {
                        UserName       = invitation.Email,
                        Email          = invitation.Email,
                        FirstName      = invitation.FirstName,
                        LastName       = invitation.LastName,
                        Registered     = now,
                        MemberState    = MemberState.Student,
                        Remark         = "CIE",
                        ExpiryDate     = null, // Einladung bleibt dauerhaft bestehen - Deprovisionierung automatisch
                        Submitted      = now,
                        EmailConfirmed =
                            true,            // damit ist auch ein "ForgotPassword" möglich, auch wenn er die Einladung nicht angenommen hat.
                        IsApproved = true,   // Damit bekommt der Nutzer von Anfang an E-Mails
                        Faculty    = host.Id // Benutzer der eingeladen hat
                    };

                    // Benutzer anlegen, mit Dummy Passwort
                    var result = UserManager.Create(user, "Cie98#lcl?");

                    if (result.Succeeded)
                    {
                        // analog Forget E-Mail Versand
                        string code = UserManager.GeneratePasswordResetToken(user.Id);

                        var mailModel = new ForgotPasswordMailModel
                        {
                            User          = user,
                            Token         = code,
                            CustomSubject = "Your NINE Account",
                            CustomBody    = "",
                            Attachments   = null,
                            IsNewAccount  = true,
                        };


                        try
                        {
                            new MailController().InvitationMail(mailModel, host, "en").Deliver();
                        }
                        catch (SmtpFailedRecipientException ex)
                        {
                            invitation.Remark = ex.Message;
                        }
                    }
                }

                var student = studentService.GetCurrentStudent(user);
                if (student == null)
                {
                    student               = new Student();
                    student.Created       = DateTime.Now;
                    student.Curriculum    = invitation.Curriculum;
                    student.FirstSemester = invitation.Semester;
                    student.UserId        = user.Id;

                    Db.Students.Add(student);
                }


                if (invitation.Course != null)
                {
                    var subscription =
                        invitation.Course.Occurrence.Subscriptions.FirstOrDefault(x => x.UserId.Equals(user.Id));

                    if (subscription == null)
                    {
                        subscription               = new OccurrenceSubscription();
                        subscription.TimeStamp     = DateTime.Now;
                        subscription.UserId        = user.Id;
                        subscription.OnWaitingList = invitation.OnWaitinglist;
                        subscription.Occurrence    = invitation.Course.Occurrence;
                        subscription.HostRemark    = invitation.Remark;
                        invitation.Course.Occurrence.Subscriptions.Add(subscription);
                    }
                }
            }

            Db.SaveChanges();

            return(View("InvitationList", invitationList));
        }