Ejemplo n.º 1
0
 private void SendVerificationMail(RegisterModel model, string token)
 {
     var smtp = new SmtpClient
     {
         Host = "smtp.live.com", // google: "smtp.gmail.com",
         Port = 587,
         EnableSsl = true,
         DeliveryMethod = SmtpDeliveryMethod.Network,
         UseDefaultCredentials = false,
         Credentials = new NetworkCredential("*****@*****.**", "cris0725")
     };
     using (var message = new MailMessage("*****@*****.**", model.Email)
     {
         Subject = "Account Verification",
         Body = "Hello, " + model.UserName +
             "\n\nYour account was succesfully created. Please verify it by clicking on the link below:\n\n" +
             "Activation link: http://localhost:15564/Account/Verify/" + token
     })
     {
         smtp.Send(message);
     }
 }
Ejemplo n.º 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
                    //WebSecurity.Login(model.UserName, model.Password);

                    // Send Verification Mail
                    SendVerificationMail(model, confirmationToken);

                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());

                    byte[] imageByte = System.IO.File.ReadAllBytes(Server.MapPath("~/Images/defaultProfile.png"));
                    user.Picture = imageByte;
                    user.MimeType = "image/png";

                    user.Email = model.Email;

                    db.SaveChanges();

                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }