Пример #1
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));
            }
        }