コード例 #1
0
        public static void SendNewRegistrationEmail(RegisterModel model)
        {
            string subj = "Welcome to Rocket League Wars";
            string body = String.Empty;

            StringBuilder sbBody = new StringBuilder();
            sbBody.Append("Hello, ");
            sbBody.Append(model.UserName + "!");
            sbBody.Append("<br> <br>");
            sbBody.Append("Thanks for joining. The Admin Team will now assign you to a team. You will be emailed when this happens.");
            sbBody.Append("<br> <br>");
            sbBody.Append("Thanks,");
            sbBody.Append("<br>");
            sbBody.Append("RocketLeagueWars.com");
            body = sbBody.ToString();

            MailMessage email = new MailMessage();
            email.IsBodyHtml = true;
            email.Subject = subj;
            email.Body = body;
            email.From = GetSupportEmail();
            email.To.Add(model.Email.Trim());

            SmtpClient smtp = new SmtpClient();
            smtp.Port = 587;
            smtp.Credentials = new NetworkCredential(GetSupportEmailUsername(), GetSupportEmailPassword());
            smtp.Host = GetSupportEmailHost();
            smtp.Send(email);

            InsertEmailTrackingRow(smtp, AccountLogic.GetUserID(model.UserName));
        }
コード例 #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    int userID = AccountLogic.Register(model);
                    if (userID > 0)
                    {
                        EmailLogic.SendNewRegistrationEmail(model);
                        Session["Username"] = model.UserName;
                        return RedirectToAction("Index", "Home");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #3
0
        public static int Register(RegisterModel user)
        {
            int result = 0;
            string sql = @"insert into Users (Username, Email, Password) values (@Username, @Email, @Password)
                            select scope_identity()";

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DSN"].ConnectionString))
            {
                SqlCommand command = new SqlCommand(sql, conn);
                command.Parameters.AddWithValue("@Username", user.UserName);
                command.Parameters.AddWithValue("@Email", user.Email);
                command.Parameters.AddWithValue("@Password", PasswordHash.CreateHash(user.Password));
                conn.Open();
                object userID = command.ExecuteScalar();
                if (userID != null)
                {
                    result = Convert.ToInt32(userID);
                }
                conn.Close();
            }

            return result;
        }