コード例 #1
0
 public ActionResult SendRegistrationEmail(RegisterViewModel model)
 {
     var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
     var message = new MailMessage();
     message.To.Add(new MailAddress(model.Email));
     message.Subject = "Your email subject";
     message.Body = string.Format(body, "teamtiger", "*****@*****.**", "Hej på dig!");
     message.IsBodyHtml = true;
     using (var smtp = new SmtpClient())
     {
         smtp.Send(message);
         return View("Sent");
     }
 }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: No-ops/YH-Admin
        public ActionResult Register(Guid guid, RegisterViewModel model)
        {
            using (var inviteRepository = new InviteRepository())
            {
                InviteModel invite = null;
                try
                {
                    invite = inviteRepository.Get(guid);
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, "Kunde inte hitta din inbjudan.");
                }

                if (invite.Status != "Sent" || DateTime.Now > invite.DateCreated.AddMonths(1))
                    ModelState.AddModelError(string.Empty, "Det här är inte en giltig inbjudan.");
                using (var profileRepository = new UserProfileRepository())
                {
                    if (profileRepository.IsEmailInUse(invite.Email))
                        ModelState.AddModelError(string.Empty, "Denna email är redan i bruk.");
                }
                if (ModelState.IsValid)
                {
                    WebSecurity.CreateUserAndAccount(model.Username, model.Password,
                        new
                        {
                            FirstName = model.FirstName,
                            LastName = model.LastName,
                            Email = invite.Email
                        });
                    Roles.AddUserToRole(model.Username, invite.Role);
                    WebSecurity.Login(model.Username, model.Password);
                    Session["guid"] = null;
                    invite.Status = "Accepted";
                    inviteRepository.Update(invite);
                    return View("AccountCreated");
                }
                return View(model);
            }
        }