Ejemplo n.º 1
0
        public ActionResult ResetPassword(RegisterModel model)
        {
            var db = new DataContext();
            var user = db.Users.FirstOrDefault(x => x.Email == model.Email);

            if(user != null)
            {
                var password = RandomPassword.Generate();
                var membership = new CodeFirstMembershipProvider();
                if (Request.Url != null)
                {
                    MailUtil.SendNewPassword(password, model.Email, Request.Url.Host + Url.Action("ChangePassword"), user.Username);
                    if(membership.ChangePasswordForce(user.Email, password))
                    {
                        return View("ResetSuccess", model);
                    }
                }
            }
            ViewBag.Fail = "Fant ikke noen bruker med den epost-adressen. Har du skrevet feil?";
            return View();
        }
Ejemplo n.º 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                _membershipProvider.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    MailUtil.SendRegisteredEmail(model.Email, model.UserName);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }