コード例 #1
0
        public ActionResult PasswordReset(PasswordResetModel model)
        {
            if (ModelState.IsValid)
            {
                // Check if the student exists.
                var student = StudentRepository.GetByEmail(model.Email);
                if (student != null)
                {
                    // Generate a password for the student and hash it.
                    string password = PasswordGenerator.CreateRandomPassword();
                    student.Password = Crypto.HashPassword(password);
                    StudentRepository.Update(student);

                    // Create a mail message with the password and mail it to the student.
                    var msg = new EmailMessage
                    {
                        text = string.Format("Beste {1},{0}Er is een aavraag gedaan om je wachtwoord te resetten.{0}Inlognaam: {3} {0}Wachtwoord: {2}{0}{0}",
                                             Environment.NewLine,
                                             student.FirstName,
                                             password,
                                             student.Email),
                        subject = "Studenten Volg Systeem wachtwoord reset",
                        to      = new List <EmailAddress>
                        {
                            new EmailAddress(student.Email, string.Format("{0} {1}", student.FirstName, student.LastName)),
                            new EmailAddress(student.SchoolEmail, string.Format("{0} {1}", student.FirstName, student.LastName), "cc"),
                        },
                    };
                    _mailEngine.Send(msg);
                }
            }

            model.Success = true;
            return(View(model));
        }
コード例 #2
0
ファイル: UserCommand.cs プロジェクト: nethojs29/CoTech.BI
 public CreateUserCmd(CreateUserReq req, long userId)
 {
     Name     = req.Name;
     Lastname = req.Lastname;
     Email    = req.Email.ToLower();
     UserId   = userId;
     Password = PasswordGenerator.CreateRandomPassword(8);
 }
コード例 #3
0
        public ActionResult Import(string csv)
        {
            // A csv is supplied, try to parse it.
            foreach (string[] d in csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                     .Skip(1)
                     .Select(line => line.Split(new[] { ';' })))
            {
                // Try to parse the student number.
                int studentNr;
                if (!int.TryParse(d[1], out studentNr))
                {
                    ModelState.AddModelError("", string.Format("StudentNr '{0}' is geen geldig nummer", d[1]));
                    continue;
                }

                var existing = StudentRepository.GetByStudentNr(studentNr);
                if (existing != null)
                {
                    // Skip existing students.
                    continue;
                }

                // Create a new student from the csv data.
                var student = new Student
                {
                    StudentNr       = studentNr,
                    FirstName       = d[2],
                    LastName        = d[4],
                    SchoolEmail     = d[5].ToLower(),
                    Email           = d[6].ToLower(),
                    ClassId         = int.Parse(d[7]),
                    Telephone       = d[8],
                    StreetNumber    = int.Parse(d[9]),
                    StreetName      = d[10],
                    ZipCode         = d[11],
                    City            = d[12],
                    PreStudy        = d[13],
                    Status          = (Status)Enum.Parse(typeof(Status), d[14]),
                    Active          = d[15] == "1",
                    EnrollDate      = DateTime.Parse(d[16]),
                    LastAppointment = DateTime.Parse(d[16]),
                    BirthDate       = DateTime.Parse(d[17])
                };

                // Generate a password.
                string password = PasswordGenerator.CreateRandomPassword();
                student.Password = Crypto.HashPassword(password);

                // todo: mail

                StudentRepository.Add(student);
            }

            return(View());
        }
コード例 #4
0
        public ActionResult Create(StudentModel model)
        {
            if (ModelState.IsValid)
            {
                // Check for duplicate students.
                var duplicate = StudentRepository.GetByStudentNr(model.StudentNr.GetValueOrDefault());
                if (duplicate == null)
                {
                    // Map the  student view model to the domain model.
                    var student = Mapper.Map <Student>(model);
                    student.Active = true;

                    // Generate a password for the student and hash it.
                    string password = PasswordGenerator.CreateRandomPassword();
                    student.Password = Crypto.HashPassword(password);
                    StudentRepository.Add(student);

                    // Create a mail message with the password and mail it to the student.
                    var msg = new EmailMessage
                    {
                        text = string.Format("Beste {1},{0}{0}NHL Hogeschool maakt gebruikt van het Studenten Volg Systeem.{0}Hier kunnen studenten en SLB'ers de studie voortgang bekijken en bijhouden. {0}De NHL heeft een acount voor je aangenaakt. Dit zijn de gegevens: {0}{0}Inlognaam: {3} {0}Wachtwoord: {2}{0}{0}Met vriendelijke groet,{0}{0}NHL Hogeschool",
                                             Environment.NewLine,
                                             student.FirstName,
                                             password,
                                             student.Email),
                        subject = "Studenten Volg Systeem account",
                        to      = new List <EmailAddress>
                        {
                            new EmailAddress(student.Email, string.Format("{0} {1}", student.FirstName, student.LastName)),
                            new EmailAddress(student.SchoolEmail, string.Format("{0} {1}", student.FirstName, student.LastName), "cc")
                        },
                    };
                    _mailEngine.Send(msg);

                    return(RedirectToAction("List"));
                }

                // Student is a duplicate.
                ModelState.AddModelError("", "Studentnummer komt al voor in de database.");
            }

            PrepareStudentModel(model);
            return(View(model));
        }
コード例 #5
0
        public async Task <IActionResult> ResetPassword([FromBody] ResetRequest request)
        {
            try
            {
                var user = await _userRepository.WithEmail(request.email);

                var password = PasswordGenerator.CreateRandomPassword(8);
                user.Password = _passwordHasher.HashPassword(user, password);
                var cmd    = new ChangePasswordCmd(user.Password, user.Id);
                var result = await _userRepository.ChangePassword(cmd);

                if (result)
                {
                    bool response = MailsHelpers.MailPassword(user.Email, password);
                    if (response)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(new JsonResult(new ResponseMail("Error al mandar correo", 0, 400))
                        {
                            StatusCode = 400
                        });
                    }
                }
                else
                {
                    return(new JsonResult(new ResponseMail("Error al actualizar", 0, 404))
                    {
                        StatusCode = 404
                    });
                }
            }
            catch (Exception e)
            {
                return(new JsonResult(e.Message)
                {
                    StatusCode = 500
                });
            }
        }
コード例 #6
0
ファイル: Add_NhanVien.cs プロジェクト: HaDangTu/ProjectOAD
        private void btGenerate_Click(object sender, EventArgs e)
        {
            PasswordGenerator generator = new PasswordGenerator();

            tbPassword.Text = generator.CreateRandomPassword(8);
        }
コード例 #7
0
        public ActionResult Create(ObjectId trackingId, Tracking tracking)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var trackingItem = _trackableItemsCollection.AsQueryable().FirstOrDefault(ti => ti.Id == tracking.TrackingItemId);

                    //delete customer info if tracking item does not support it
                    if (!trackingItem.SupportsUserInformation)
                    {
                        tracking.CustomerInformation = null;
                    }

                    tracking.CreatedDate = DateTime.Now.Date;
                    tracking.Id          = trackingId;
                    tracking.User        = User.Identity.Name;
                    tracking.History     = new List <TrackingHistoryRecord>()
                    {
                        new TrackingHistoryRecord()
                        {
                            Comment = tracking.Comment, CreatedDate = DateTime.Now, StateId = tracking.StateId
                        }
                    };

                    tracking.Password = trackingItem.IsSecured ? PasswordGenerator.CreateRandomPassword(8) : string.Empty;
                    _trackingCollection.Save(tracking);
                }
                try
                {
                    var username = Membership.GetUser().UserName.ToLower();
                    var user     =
                        _usersCollection.AsQueryable().FirstOrDefault(x => string.Equals(x.NameLowerSpace, username));
                    if (user.EnableSubscribersEmailNotifications)
                    {
                        if (tracking.CustomerInformation != null && !string.IsNullOrWhiteSpace(tracking.CustomerInformation.Email))
                        {
                            var trackingItem = _trackableItemsCollection.AsQueryable().FirstOrDefault(x => x.UserId == User.Identity.Name && x.Id == tracking.TrackingItemId);
                            var stateName    = trackingItem.States.FirstOrDefault(s => s.Id == tracking.StateId).Name;
                            SubscriberMailSettings emailSettings = new SubscriberMailSettings();
                            emailSettings.SourceEmailAddress      = user.SmtpUserName;
                            emailSettings.SmtpPassword            = user.SmtpPassword;
                            emailSettings.SmtpPort                = user.SmtpPort;
                            emailSettings.SmtpUrl                 = user.SmtpServerUrl;
                            emailSettings.UseSsl                  = user.SmtpHttps;
                            emailSettings.DestinationEmailAddress = tracking.CustomerInformation.Email;
                            emailSettings.SourceFullName          = string.Format("{0} {1}", user.FirstName, user.LastName);
                            emailSettings.DestinationFullName     = string.Format("{0} {1}", tracking.CustomerInformation.FirstName, tracking.CustomerInformation.LastName);
                            var trackingData = QRCodeHtmlHelper.CreateQrData(tracking.TrackingNumber, tracking.Password);

                            var qrUrl = QRCodeHtmlHelper.QRCode(null, trackingData, 150);

                            Mailer.NotifyNewTracking(emailSettings, tracking.TrackingNumber, stateName, tracking.Comment, trackingItem.Name, qrUrl.ToString(), tracking.Password);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TempData["errorsOccured"] = string.Format("Unable to send a notification email: {0}", ex.Message);
                }
                return(RedirectToAction("PrintableVersion", "Tracking", new { id = trackingId }));
            }
            catch
            {
                return(View());
            }
        }