Ejemplo n.º 1
0
        private void SendRegistrationConfirnationEmail(Prepper prepper)
        {
            if (Request.Url == null) return;

            var host = Request.Url.Authority.ToLower();
            var fullLink = string.Format("http://{0}/Account/ConfirmRegistration?guid={1}", host,
                prepper.ConfirmationGuid);
            var body = string.Format("Click the following link to confirm your bPrep.net registration; {0}", fullLink);
            BpFunctions.SendEmail(prepper.Email, "bPrep Registration Confirmation", body);
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public string SendRegistration(string userName, string emailAddress, string password)
        {
            var db = new BP_ModelContainer();

            userName = userName.Trim();
            emailAddress = emailAddress.Trim();
            password = password.Trim();

            //Check for matching username
            var prepper = (from p in db.Preppers where p.Name.Equals(userName, StringComparison.InvariantCultureIgnoreCase) select p).FirstOrDefault();
            if (prepper != null) return "Username already exists";

            //Check for matching email
            prepper = (from p in db.Preppers where p.Email.Equals(emailAddress, StringComparison.InvariantCultureIgnoreCase) select p).FirstOrDefault();
            if (prepper != null) return "Email already registered";

            var user = new ApplicationUser { UserName = userName };
            var result = UserManager.Create(user, password);
            if (!result.Succeeded) return result.Errors.FirstOrDefault();

            //Save info as Prepper
            prepper = new Prepper
            {
                Name = user.UserName,
                Email = emailAddress,
                ConfirmationRequestSent = DateTime.Now,
                ConfirmationGuid = Guid.NewGuid().ToString(),
                ShowTipKit = true,
                ShowTipKitItems = true,
                UnsubscribeGuid = Guid.NewGuid().ToString()
            };
            db.Preppers.Add(prepper);
            db.SaveChanges();

            SendRegistrationConfirnationEmail(prepper);

            return "";
        }