コード例 #1
0
        public HttpResponseMessage ForgotPassword(Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
        {
            if (earthwatcher != null)
            {
                var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(earthwatcher.Name, false);
                if (earthwatcherDb == null)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NotFound);
                    return(response);
                }

                //Mando el mail
                try
                {
                    var    dateToEncode = System.Text.Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString());
                    string encodedDate  = System.Convert.ToBase64String(dateToEncode);

                    if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
                    {
                        List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();

                        System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(earthwatcherDb.Name);
                        System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], "Guardianes - Greenpeace");
                        System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                        message.From = addressFrom;
                        message.To.Add(address);
                        message.Subject = "Reseteá tu contraseña de Guardianes - Reset your Guardians Password";

                        string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);

                        string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                        message.Body = string.Format(htmlTemplate, "Estimado Guardian,", "Para resetear tu contraseña hacé un click en el botón verde [Resetear Contraseña].<br><br> Por motivos de seguridad, este cambio se podrá hacer en el transcurso de las próximas 24 horas"
                                                     , string.Format("{0}/resetpwd.html?guid={1}&ed={2}", domain, earthwatcherDb.Guid, encodedDate), "Click aquí para resetear tu contraseña", "Resetear Contraseña", "Este mensaje se envío a", earthwatcherDb.Name
                                                     , ". Si no quieres recibir más notificaciones en un futuro podés acceder al Panel de Control del usuario y deshabilitar la opción de recibir notificaciones."
                                                     , "Greenpeace Argentina. Todos los derechos reservados.", domain);
                        message.IsBodyHtml   = true;
                        message.BodyEncoding = System.Text.Encoding.UTF8;
                        message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                        messages.Add(message);

                        SendMails.Send(messages);
                    }
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    });
                }
                catch (Exception ex)
                {
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message
                    });
                }
            }
            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadRequest
            });
        }
コード例 #2
0
        private void VerificationScoring(LandMini landMini)
        {
            if (landMini != null)
            {
                try
                {
                    //Mando los mails notificando
                    if (!string.IsNullOrEmpty(landMini.Email))
                    {
                        if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
                        {
                            List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();

                            System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(landMini.Email);
                            System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], Labels.Labels.GuardiansGreenpeace);
                            System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                            message.From = addressFrom;
                            message.To.Add(address);
                            message.Subject = Labels.Labels.LandVerifications.ToString();

                            string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);

                            string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                            message.Body = string.Format(htmlTemplate, Labels.Labels.LandVerifications2
                                                         , Labels.Labels.LandVerifications3
                                                         , string.Format("{0}/index.html?geohexcode={1}", domain, landMini.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, landMini.Email
                                                         , Labels.Labels.LandVerifications7
                                                         , Labels.Labels.LandVerifications8, domain);
                            message.IsBodyHtml   = true;
                            message.BodyEncoding = System.Text.Encoding.UTF8;
                            message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                            messages.Add(message);

                            SendMails.Send(messages);
                        }
                    }

                    //Genero la imagen de este land
                    ImagesGeneratorTool.Run(landRepository, true, landMini.GeohexKey);

                    //Notify the land owner if logged in
                    var context = GlobalHost.ConnectionManager.GetHubContext <Hubs>();
                    context.Clients.All.LandVerified(landMini.EarthwatcherId);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
コード例 #3
0
        public HttpResponseMessage <Earthwatcher> Post(Earthwatcher earthwatcher, HttpRequestMessage <Earthwatcher> request)
        {
            // quick and easy model validation
            if (String.IsNullOrEmpty(earthwatcher.Name) |
                String.IsNullOrEmpty(earthwatcher.Password) |
                String.IsNullOrEmpty(earthwatcher.Country))
            {
                return(new HttpResponseMessage <Earthwatcher>(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "Model is not valid"
                });
            }

            var earthwatcherDb = earthwatcherRepository.GetEarthwatcher(earthwatcher.Name, false);

            if (earthwatcherDb == null)
            {
                //set localization preferences
                var    locSrv = new LocalizationService();
                string locale = locSrv.GetLocale();
                if (locSrv.IsLocaleSetted())
                {
                    earthwatcher.Country        = (locale != null) ? locale.Substring(3, 2) : "es-AR";
                    earthwatcher.Language       = (locale != null) ? locale.Substring(0, 5) : "en-CA";
                    earthwatcher.PlayingRegion  = (locale != null) ? Convert.ToInt32(locale.Substring(6, 1)) : 1;
                    earthwatcher.PlayingCountry = (regionRepository.GetById(earthwatcher.PlayingRegion)).CountryCode;
                }

                earthwatcher.Guid = Guid.NewGuid();
                earthwatcherRepository.CreateEarthwatcher(earthwatcher);
                // assign land

                var  newLand    = earthwatcherRepository.AssignLandToEarthwatcher(earthwatcher.Id, string.Empty);
                Land newLandObj = null;
                if (newLand == null) //Si la region esta completa le asigno la land del tutor
                {
                    newLandObj = landRepository.GetTutorLand(earthwatcher.PlayingRegion);
                }
                if (newLandObj == null) //Si no esta completa la region
                {
                    newLandObj = landRepository.GetLandByGeoHexKey(newLand.GeohexKey);
                }
                earthwatcher.Lands = new List <Land>();
                earthwatcher.Lands.Add(newLandObj);
                //Comunico a los usuarios conectados si es que la nueva land es de un usuario existente
                NotificateUsers(newLand, earthwatcher.Id);

                //Mando el mail de bienvenida
                try
                {
                    if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
                    {
                        List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();

                        System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(earthwatcher.Name);
                        System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], "Guardianes - Greenpeace");
                        System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                        message.From = addressFrom;
                        message.To.Add(address);
                        message.Subject = Labels.Labels.MailBienvenidaAsunto;

                        string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);

                        string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                        message.Body = string.Format(htmlTemplate, Labels.Labels.MailBienvenidaTitulo
                                                     , Labels.Labels.MailBienvenidaCuerpo
                                                     , string.Format("{0}/index.html", domain), Labels.Labels.MailBienvenidaBotonTooltip, Labels.Labels.MailBienvenidaBoton, Labels.Labels.LandVerifications6, earthwatcher.Name
                                                     , Labels.Labels.LandVerifications7
                                                     , Labels.Labels.LandVerifications8, domain);
                        message.IsBodyHtml   = true;
                        message.BodyEncoding = System.Text.Encoding.UTF8;
                        message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                        messages.Add(message);
                        SendMails.Send(messages);
                    }

                    return(new HttpResponseMessage <Earthwatcher>(earthwatcher)
                    {
                        StatusCode = HttpStatusCode.Created
                    });
                }
                catch (Exception ex)
                {
                    return(new HttpResponseMessage <Earthwatcher>(earthwatcher)
                    {
                        StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message
                    });
                }
            }
            throw new HttpResponseException("error: user already exists");
        }
コード例 #4
0
        private void SendEmail_GreenpeaceConfirmation(List <Land> lands, Earthwatcher earthwatcher)
        {
            //Mando los mails notificando (solo envio si es que tengo habilitado via web.config el envio
            //TODO: Push Notifications para actualizar
            if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["smtp.enabled"]))
            {
                List <System.Net.Mail.MailMessage> messages = new List <System.Net.Mail.MailMessage>();
                foreach (var land in lands)
                {
                    string lawYear = land.RegionId == 1? "2008" : "2013";

                    if (land.Confirmed.HasValue)
                    {
                        System.Net.Mail.MailAddress address     = new System.Net.Mail.MailAddress(land.EarthwatcherName);
                        System.Net.Mail.MailAddress addressFrom = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["smtp.user"], Labels.Labels.GuardiansGreenpeace);
                        System.Net.Mail.MailMessage message     = new System.Net.Mail.MailMessage();
                        message.From = addressFrom;
                        message.To.Add(address);
                        string domain       = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority);
                        string htmlTemplate = System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mail.html"));
                        //Confirmados en Amarillo
                        if (land.Confirmed.Value && land.LandStatus == LandStatus.Alert)
                        {
                            message.Subject = Labels.Labels.LandVerified;
                            message.Body    = string.Format(htmlTemplate, Labels.Labels.Congrats
                                                            , Labels.Labels.LandVerified2
                                                            , string.Format("{0}/index.html?geohexcode={1}", domain, land.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, land.EarthwatcherName
                                                            , Labels.Labels.LandVerifications7
                                                            , Labels.Labels.LandVerifications8, domain);
                        }

                        //Confirmados en Verde
                        if (land.Confirmed.Value && land.LandStatus == LandStatus.Ok)
                        {
                            message.Subject = Labels.Labels.LandVerified;
                            message.Body    = string.Format(htmlTemplate, Labels.Labels.Congrats
                                                            , Labels.Labels.ReportVerifiedCorrect
                                                            , string.Format("{0}/index.html?geohexcode={1}", domain, land.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, land.EarthwatcherName
                                                            , Labels.Labels.LandVerifications7
                                                            , Labels.Labels.LandVerifications8, domain);
                        }

                        //Rechazados en Verde
                        if (!land.Confirmed.Value && land.LandStatus == LandStatus.Ok)
                        {
                            message.Subject = Labels.Labels.VerificationReport;
                            message.Body    = string.Format(htmlTemplate, Labels.Labels.IncorrectReport
                                                            , Labels.Labels.IncorrectReport2 +
                                                            @"<table style='padding: 10px; margin: 10px; border-collapse: collapse;' cellpadding='10' cellspacing='0'>
                                        <tr>
                                    <td><img src='" + domain + "/SatelliteImages/demand/" + land.GeohexKey + "-a.jpg' galleryimg='no' /></td><td><img src='" + domain + "/SatelliteImages/demand/" + land.GeohexKey + "-a.jpg' galleryimg='no' /></td></tr><tr><td style='font-family: Arial; font-size: 11px;'>" + lawYear + "</td><td style='font-family: Arial; font-size: 11px;'>" + Labels.Labels.Now + "</td></tr></table><br /><br />"
                                                            , string.Format("{0}/index.html?geohexcode={1}", domain, land.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, land.EarthwatcherName
                                                            , Labels.Labels.LandVerifications7
                                                            , Labels.Labels.LandVerifications8, domain);
                        }

                        //Rechazados en Amarillo
                        if (!land.Confirmed.Value && land.LandStatus == LandStatus.Alert)
                        {
                            message.Subject = Labels.Labels.VerificationReport;
                            message.Body    = string.Format(htmlTemplate, Labels.Labels.IncorrectReport
                                                            , string.Format(Labels.Labels.IncorrectReport3, lawYear, lawYear) +
                                                            @"<table style='padding: 10px; margin: 10px; border-collapse: collapse;' cellpadding='10' cellspacing='0'>
                                        <tr>
                                    <td><img src='" + domain + "/SatelliteImages/demand/" + land.GeohexKey + "-a.jpg' galleryimg='no' /></td><td><img src='" + domain + "/SatelliteImages/demand/" + land.GeohexKey + "-a.jpg' galleryimg='no' /></td></tr><tr><td style='font-family: Arial; font-size: 11px;'>" + lawYear + "</td><td style='font-family: Arial; font-size: 11px;'>" + Labels.Labels.Now + "</td></tr></table><br /><br />"
                                                            , string.Format("{0}/index.html?geohexcode={1}", domain, land.GeohexKey), Labels.Labels.LandVerifications4, Labels.Labels.LandVerifications5, Labels.Labels.LandVerifications6, land.EarthwatcherName
                                                            , Labels.Labels.LandVerifications7
                                                            , Labels.Labels.LandVerifications8, domain);
                        }

                        message.IsBodyHtml   = true;
                        message.BodyEncoding = System.Text.Encoding.UTF8;
                        message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.None;
                        messages.Add(message);
                    }
                }

                SendMails.Send(messages);
            }
        }