Пример #1
0
        public ActionResult ForgotPassword(RegisterModel model)
        {
            _log.Info("ForgotPassword Entered");
            _log.Debug("Parameter "+JsonConvert.SerializeObject(model,Formatting.Indented));

            string Password             = string.Empty;
            RegisterModel AccountData   = null;
            var userData                = model;
            try
            {
                var Data        = JsonConvert.DeserializeObject(Utilities.HttpRequest.GetHttpRequest(url + "AccountService.svc/Retrieve", "POST", JsonConvert.SerializeObject(userData))) as JToken;
                AccountData     = JsonConvert.DeserializeObject<RegisterModel>(Data["RetrievePasswordResult"].ToString());

                if (string.IsNullOrEmpty(AccountData.Password))
                {
                    ViewBag.ErrorMessage    = "Wrong Username or Email ID";
                    ViewBag.Password        = string.Empty;
                }
                else
                {
                    ViewBag.ErrorMessage    = string.Empty;
                    ViewBag.Password        = "******" + AccountData.Password;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return RedirectToAction("ErrorPage", "Home", new { ex = ex.Message });
            }
            finally
            {
                _log.Info("Forgot Password Exited");
            }
            return View();
        }
Пример #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public void Register_Post_ReturnsViewIfRegistrationFails()
        {
            // Disponer
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Actuar
            ActionResult result = controller.Register(model);

            // Declarar
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("El nombre de usuario ya existe. Escriba otro nombre de usuario.", controller.ModelState[""].Errors[0].ErrorMessage);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
        public void Register_Post_ReturnsViewIfModelStateIsInvalid()
        {
            // Disponer
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Mensaje de error ficticio.");

            // Actuar
            ActionResult result = controller.Register(model);

            // Declarar
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]);
        }
        public void Register_Post_ReturnsRedirectOnSuccess()
        {
            // Disponer
            AccountController controller = GetAccountController();
            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Actuar
            ActionResult result = controller.Register(model);

            // Declarar
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("Home", redirectResult.RouteValues["controller"]);
            Assert.AreEqual("Index", redirectResult.RouteValues["action"]);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Intento de registrar al usuario
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
Пример #9
0
        public ActionResult Register(RegisterModel model)
        {
            _log.Info("Register HttpPost entered");
            _log.Debug("Parameter :"+JsonConvert.SerializeObject(model,Formatting.Indented));
            try
            {
                var accountData         = model;
                var Data                = JsonConvert.DeserializeObject(Utilities.HttpRequest.GetHttpRequest(url + "AccountService.svc/Register", "POST", JsonConvert.SerializeObject(accountData))) as JToken;
                string ResponseData     = Data["RegisterResult"].ToString();

                _log.Debug("Response :" + ResponseData);
                if (ResponseData.Equals("Success"))
                {
                    return RedirectToAction("Login", "Home");
                }
                else
                    return View();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return RedirectToAction("ErrorPage", "Home", new { ex = ex.Message });
            }
            finally
            {
                _log.Info("Register Exited");
            }
        }