Exemplo n.º 1
0
        private static MembershipUser GetUser(string keyEncoded)
        {
            var guid = UrlGuidHelper.GetGuid(keyEncoded);
            var user = Membership.GetUser(guid);

            return(user);
        }
Exemplo n.º 2
0
        public ActionResult SetUpAccountPost(string keyEncoded, BetaActivate m)
        {
            if (ModelState.IsValid)
            {
                var activationKey = UrlGuidHelper.GetGuid(keyEncoded);

                // using EF directly, as this is only temporary
                using (var ctx = new OpenGrooves.Data.OpenGroovesEntities())
                {
                    var usernameExists = ctx.Users.Where(u => u.UserName == m.Username && u.UserId != activationKey).Any();

                    if (usernameExists)
                    {
                        ModelState.AddModelError("UsernameExists", "The username you have chosen is taken. Please choose another.");
                        return(View("BetaUsers", m));
                    }

                    var user = ctx.Users.SingleOrDefault(u => u.UserId == activationKey);
                    user.UserName        = m.Username;
                    user.LoweredUserName = m.Username.ToLower();
                    user.SetupRequired   = false;
                    ctx.SaveChanges();
                }

                var newPass = m.NewPassword;

                var newUser = Membership.GetUser(activationKey);

                if (!newPass.IsNullOrWhiteSpace())
                {
                    var tempPass = newUser.ResetPassword();
                    var changed  = newUser.ChangePassword(tempPass, newPass);
                    newUser.IsApproved = true;

                    Membership.UpdateUser(newUser);

                    SendBetaWelcomeEmail(newUser.UserName, newUser.Email, newPass);
                    FormsAuthentication.SetAuthCookie(newUser.UserName, true);
                }

                return(View("Index", (object)newUser.UserName));
            }

            return(View("BetaUsers", m));
        }