Beispiel #1
0
        public string EmailFromArvixe(RegisteredUser message, string confirmEmail)
        {
            // Use credentials of the Mail account that you created with the steps above.
            const string FROM = "*****@*****.**";
            const string FROM_PWD = "Websitesdragons93";
            const bool USE_HTML = true;

            // Get the mail server obtained in the steps described above.
            const string SMTP_SERVER = "143.95.249.35";
            try
            {
                MailMessage mailMsg = new MailMessage(FROM, message.Email);
                mailMsg.Subject = "Confirmation Email!";
                mailMsg.Body =  confirmEmail+"<br/>sent by:" + message.UserName;
                mailMsg.IsBodyHtml = USE_HTML;

                SmtpClient smtp = new SmtpClient();
                smtp.Port = 587;
                smtp.Host = SMTP_SERVER;
                smtp.Credentials = new System.Net.NetworkCredential(FROM, FROM_PWD);
                smtp.Send(mailMsg);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return SUCCESS;
        }
        public ActionResult Register(RegisteredUser newUser)
        {
            CaptchaHelper captchaHelper = new CaptchaHelper();
            string captchaResponse = captchaHelper.CheckRecaptcha();
            ViewBag.CaptchaResponse = captchaResponse;
            TempData["captcha"] = captchaResponse;
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new System.TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };
            var identityUser = new IdentityUser()
            {
                UserName = newUser.UserName,
                Email = newUser.Email
            };
            IdentityResult result = manager.Create(identityUser, newUser.Password);

            if (result.Succeeded && captchaResponse == VALID_CAPTCHA)
            {
                CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                                new { userId = identityUser.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                string email = "<h3>Please confirm your account by clicking this link:</h3><a href=\""
                                + callbackUrl + "\">Confirm Registration</a>";
                MailHelper mailer = new MailHelper();
                string response = mailer.EmailFromArvixe(newUser, email);
                ViewBag.Response = response;
                TempData["response"] = response;
            }
                return RedirectToAction("Index","Home");
        }