예제 #1
0
 public ActionResult ResetCode(string email)
 {
     Models.ResetCode resetCode = new ResetCode {
         Email = email
     };
     return(View("ResetCode", resetCode));
 }
        public void RemoveResetPasswordCode(ResetCode resetCode, string email)
        {
            var sql = "DELETE FROM dbo.ResetPasswordCode WHERE ResetCode = @ResetCode AND Email = @Email";

            using (var connection = new SqlConnection(_settings.ConnectionString))
            {
                connection.Open();
                connection.Execute(sql, new { ResetCode = resetCode.Value, Email = email });
            }
        }
        //[HttpPost]
        //public ActionResult PurchaseTicketsWithCreditCard(String concertId, String customerId, String ticketPrice, String ticketCount, String seatMapId)
        //{
        //    #region Capture Information
        //    if (String.IsNullOrEmpty(concertId) || String.IsNullOrEmpty(customerId) || String.IsNullOrEmpty(ticketPrice) || String.IsNullOrEmpty(ticketCount) || String.IsNullOrEmpty(seatMapId))
        //        return RedirectToAction("Index", "Home");
        //    if (ticketPrice.IndexOf(".") > 0) ticketPrice = ticketPrice.Substring(0, ticketPrice.IndexOf("."));
        //    #endregion Capture Information

        //    #region Purchase Tickets and Display Result
        //    var ticketsPurchased = _ticketsRepository.concertTicketDbContext.WriteNewTicketToDb(new Customer { CustomerId = Int32.Parse(customerId) },
        //        Int32.Parse(concertId), Int32.Parse(seatMapId), Int32.Parse(ticketPrice), Int32.Parse(ticketCount));
        //    if (ticketsPurchased != null)
        //        DisplayMessage(string.Format("Successfully purchased tickets. You now have {0} tickets for this concert. Confirmation # {1}", ticketsPurchased.Count, ticketsPurchased[0].TicketId));
        //    else
        //        DisplayMessage("Failed to purchase tickets.");
        //    #endregion Purchase Tickets and Display Result

        //    return RedirectToAction("Index", "Home");
        //}

        public ActionResult Reset(bool fullReset = false)
        {
            var noErrors = true;
            var reset    = new ResetCode();

            noErrors = reset.RefreshConcerts(fullReset);

            if (noErrors)
            {
                DisplayMessage("Finished Resetting Environment");
            }

            return(new RedirectResult("http://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port));
        }
        public ResetCodeRepresentation FindResetPasswordCode(ResetCode resetCode, string email)
        {
            var sql = "SELECT TOP 1 Id, ResetCode, DateCreated, Checked, Email FROM dbo.ResetPasswordCode " +
                      "WHERE ResetCode = @ResetCode AND Email = @Email " +
                      "ORDER BY DateCreated DESC";

            using (var connection = new SqlConnection(_settings.ConnectionString))
            {
                connection.Open();
                var found = connection.QueryFirstOrDefault <ResetCodeRepresentation>(sql,
                                                                                     new
                {
                    ResetCode = resetCode.Value,
                    Email     = email
                });
                return(found);
            }
        }
예제 #5
0
        public ActionResult ResetCode(ResetCode resetCode)
        {
            if (ModelState.IsValid)
            {
                HttpCookie cookie = HttpContext.Request.Cookies.Get("code");
                if (resetCode.Code != cookie.Value.ToString())
                {
                    ModelState.AddModelError("", "Код для сброса неверен");
                    return(View(resetCode));
                }

                string password = "";
                Random random   = new Random();

                while (password.Length < 10)
                {
                    char c = (char)random.Next(33, 125);
                    if (char.IsLetterOrDigit(c))
                    {
                        password += c;
                    }
                }

                MailTools mail = new MailTools();

                var result = mail.SendMailToUser(resetCode.Email, "Сброс пароля", $"<p>Ваш новый пароль: <b>{ password }</b></p>");

                if (result != null)
                {
                    ModelState.AddModelError("", result);
                    return(View(resetCode));
                }

                var user = unitOfWork.Users.GetUserByLoginData(resetCode.Email);
                user.Password = password;
                unitOfWork.Dispose();
                unitOfWork = new UnitOfWork();
                unitOfWork.Users.UpdateItem(user);
                unitOfWork.Save();

                ViewBag.SuccessMessage = "Ваш пароль был отправлен на почту";
            }
            return(View(resetCode));
        }
예제 #6
0
 // Use this for initialization
 void Start()
 {
     instance = this;
 }
예제 #7
0
 public CheckResetCodeCommand(ResetCode resetCode, string email)
 {
     ResetCode = resetCode;
     Email     = email;
 }
예제 #8
0
 public ResetPasswordCommand(string newPassword, ResetCode resetCode, string email)
 {
     NewPassword = newPassword;
     ResetCode   = resetCode;
     Email       = email;
 }