コード例 #1
0
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            AuthorizationCode Code = UserBL.AuthCode(model.Email);

            if (Code.UserID >= 1)
            {
                Emails Email = new Emails();

                Email.FromEmail    = "*****@*****.**";
                Email.ToEmail      = model.Email;
                Email.SubjectEmail = Code.FullName + " - Restablecer contraseña";
                Email.BodyEmail    = "Para restablecer su contraseña, utilice el siguiente link http://localhost:61214/Account/ResetPassword?GUID=" + Code.GUID;
                //Email.BodyEmail = "Para restablecer su contraseña, utilice el siguiente link http://localhost:61214/Account/ResetPassword?GUID=" + Code.GUID;

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail);
                mm.Subject    = Email.SubjectEmail;
                mm.Body       = Email.BodyEmail;
                mm.IsBodyHtml = false;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mm);

                ViewBag.GUID = Code.GUID;
                return(this.RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            else
            {
                this.ModelState.AddModelError(String.Empty, "Este correo no esta registrado en la aplicación.");
            }

            return(this.View(model));
        }
コード例 #2
0
        public HttpResponseMessage ForgotPassword([FromBody] ForgotPasswordModel model)
        {
            string GUID;

            Users User = UBL.DetailsbyEmail(model.Email);

            if (User.UserID > 0)
            {
                AuthorizationCode Code = UBL.AuthCode(model.Email);
                string            body = string.Empty;
                using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Views/EmailTemplates/ForgotPassword.html")))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{FullName}", User.FullName);
                body = body.Replace("{GUID}", Code.GUID);

                Emails Email = new Emails()
                {
                    FromEmail    = ConfigurationManager.AppSettings["AdminEmail"].ToString(),
                    ToEmail      = model.Email,
                    SubjectEmail = "Oasis Alajuela - Restablecer Contraseña",
                    BodyEmail    = body
                };

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail)
                {
                    Subject      = Email.SubjectEmail,
                    Body         = Email.BodyEmail,
                    IsBodyHtml   = true,
                    BodyEncoding = Encoding.GetEncoding("utf-8")
                };

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mm);
                GUID = Code.GUID;
                return(this.Request.CreateResponse(HttpStatusCode.OK, GUID));
            }
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
コード例 #3
0
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            AuthorizationCode Code = UserBL.AuthCode(model.Email);

            if (Code.UserID >= 1)
            {
                Emails Email = new Emails();

                Email.FromEmail    = "*****@*****.**";
                Email.ToEmail      = model.Email;
                Email.SubjectEmail = Code.FullName + " - Restablecer contraseña";
                Email.BodyEmail    = "Para restablecer su contraseña, utilice el siguiente link https://mmoasisalajuela.azurewebsites.net/Account/ResetPassword?GUID=" + Code.GUID;
                //Email.BodyEmail = "Para restablecer su contraseña, utilice el siguiente link https://localhost:56593/Account/ResetPassword?GUID=" + Code.GUID;

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail);
                mm.Subject    = Email.SubjectEmail;
                mm.Body       = Email.BodyEmail;
                mm.IsBodyHtml = false;

                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp.gmail.com";
                smtp.Port      = 587;
                smtp.EnableSsl = true;
                //smtp.Host = "smtp.office365.com";
                //smtp.Port = 587;
                //smtp.EnableSsl = true;

                NetworkCredential nc = new NetworkCredential("*****@*****.**", "Jonitapc1985N");
                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = nc;
                smtp.Send(mm);

                ViewBag.GUID = Code.GUID;
                return(this.RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            else
            {
                this.ModelState.AddModelError(String.Empty, "Este correo no esta registrado en la aplicación.");
            }

            return(this.View(model));
        }