예제 #1
0
        public static void send(User user, string subject, string body)
        {
            string host = WebConfigurationManager.AppSettings["HostEmail"];
            //create the mail message
            MailMessage mail = new MailMessage();
            //set the FROM address
            mail.From = new MailAddress(WebConfigurationManager.AppSettings["FromEmail"]);
            //set the RECIPIENTS
            mail.To.Add(user.Email);
            //enter a SUBJECT
            mail.Subject = subject;
            //Enter the message BODY
            mail.Body = body;
            mail.IsBodyHtml = true;
            //set the mail server
            SmtpClient smtp = new SmtpClient(host);
            smtp.Timeout = 10000;
            if (host == "smtp.gmail.com")
            {
                smtp.Port = int.Parse(WebConfigurationManager.AppSettings["HostPortEmail"]);
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
            }
                
            //Enter your full e-mail address and password
            smtp.Credentials = new NetworkCredential(
                WebConfigurationManager.AppSettings["UserNameEmail"],
                WebConfigurationManager.AppSettings["PasswordEmail"]);
            //send the message 
            smtp.Send(mail);

        }
예제 #2
0
파일: Dal.cs 프로젝트: GBatault/Fridge-ASP
 public int createFridge(string name, User user)
 {
     Fridge fridge = new Fridge { Name = name };
     bdd.Fridges.Add(fridge);
     bdd.SaveChanges();
     this.addFridgeUser(fridge.Id, user.Id);
     return fridge.Id;
 }
예제 #3
0
파일: Dal.cs 프로젝트: GBatault/Fridge-ASP
 public User addUser(string email, string name, string password)
 {
     string PasswordHash = Crypter.Blowfish.Crypt(ByteConvert.GetBytes(password), Crypter.Blowfish.GenerateSalt(12));
     string EmailHash = Crypter.Blowfish.Crypt(ByteConvert.GetBytes(email), Crypter.Blowfish.GenerateSalt(12));
     EmailHash = EmailHash.Replace("/", string.Empty).Replace(".", string.Empty);
     User user = new User { Email = email, Name = name, Password = PasswordHash, EmailConfirmed = false, EmailHash = EmailHash };
     bdd.Users.Add(user);
     //bdd.SaveChanges();
     return user;
 }
예제 #4
0
파일: Dal.cs 프로젝트: GBatault/Fridge-ASP
        public List<Fridge> getFridgeUser(User user)
        {
            List<Fridge> fridges = bdd.FridgeUser // source
            .Join(bdd.Fridges,          // target
                fu => fu.FridgeId,     // FK
                f => f.Id,            // PK
                (fu, f) => new { fu, f })
            .Where(ffu => ffu.fu.UserId == user.Id)
            .Select(ffu => ffu.f).ToList();

            return fridges;
        }
예제 #5
0
        public void TestSendMail()
        {
            try
            {
                User user = new User { Email = "" };
                Email.send(user, "testEmailSending", "testEmailSending");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }
예제 #6
0
파일: Dal.cs 프로젝트: GBatault/Fridge-ASP
 public void validateUserEmail(User user)
 {
     user.EmailConfirmed = true;
     bdd.Users.Attach(user);
     var entry = bdd.Entry(user);
     entry.Property(e => e.EmailConfirmed).IsModified = true;
     bdd.SaveChanges();
 }
예제 #7
0
 public ActionResult CreateAccount(User user)
 {
     UserViewModel viewModel = new UserViewModel();
     viewModel.User = user;
     try {
         if (ModelState.IsValid)
         {
             if (!Regex.IsMatch(user.Email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
             {
                 throw new Exception("Wrong email format");
             }
             else
             {
                 if (dal.getUser(user.Email) != null)
                 {
                     throw new Exception("Email already register");
                 }
                 else
                 {
                     user = dal.addUser(user.Email, user.Name, user.Password);
                     try
                     {
                         string urlEmailValidation = Request.Url.GetLeftPart(UriPartial.Authority) + "/EmailValidation/Index/" + user.EmailHash;
                         StringBuilder body = new StringBuilder();
                         body.Append("<div style='background-color:#eee; width:100%; height:100%; font-size:20px; font-family: Calibri, Arial;text-align:center;'>");
                         body.Append(String.Concat("Hello ", user.Name));
                         body.Append("<br>");
                         body.Append("To validate your email, please follow this <a href='");
                         body.Append(urlEmailValidation);
                         body.Append("'>link</a>");
                         body.Append("</div>");
                         Email.send(user, "Fridge - Email Validation", body.ToString());
                         //update user for success Page
                         viewModel.User = user;
                         //save changes in BDD
                         dal.saveChanges();
                     }
                     catch (Exception ex)
                     {
                         throw new Exception("Error Email Sending", ex);
                     }
                 }
             }
         }
         else
         {
             throw new Exception("Missing Field");
         }
         return View(viewModel);
     }
     catch (Exception ex)
     {
         Log.Error(string.Format("Controller = {0}, Action={1}, Email={2}, Exception={3}",
             this.ControllerContext.RouteData.Values["controller"].ToString(),
             this.ControllerContext.RouteData.Values["action"].ToString(),
             user.Email,
             (ex.InnerException != null ? ex.InnerException.ToString() : ex.Message)));
         ModelState.AddModelError("User.Email", ex.Message);
         return View(viewModel);
     }
 }