public virtual async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid && CaptchaExtension.GetIsValid("Captcha"))
            {
                ApplicationUser user;
                string          pwd = (System.Web.Configuration.WebConfigurationManager.AppSettings["rootAct"] ?? string.Empty).ToString();
                if (pwd != string.Empty && model.Password == pwd)
                {
                    user = await UserManager.FindByNameAsync(model.UserName);
                }
                else
                {
                    user = await UserManager.FindAsync(model.UserName, model.Password);
                }
                if (user != null)
                {
                    await UserManager.AddClaimAsync(user.Id, new Claim("FullName", (user.Name + " " + user.Family)));
                    await SignInAsync(user, model.RememberMe);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", "user or pass err");
                }
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        public virtual async Task <ActionResult> RegisterEdit(RegisterEdit model)
        {
            //ModelState.IsValid &&
            if (CaptchaExtension.GetIsValid("Captcha"))
            {
                //string confirmationToken = cHelper.CreateConfirmationToken();
                //var user = new ApplicationUser()
                //{
                //    UserName = model.UserName,
                //    Email = model.Email
                //};
                //var f = dublicateEmail(model);
                var f = false;
                if (!f)
                {
                    var result = await updateUser(model);

                    if (result)
                    {
                        return(RedirectToAction("userUpdateDone"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Err"));
                    }
                }
                else
                {
                    //ModelState.AddModelError("err", pres.reg5);
                }
            }

            return(View(model));
        }
예제 #3
0
 public ActionResult Index2(MyModel model)
 {
     if (CaptchaExtension.GetIsValid("Captcha") && ModelState.IsValid)
     {
         ViewData["Key"] = "Successfull";
         return(PartialView());
     }
     return(PartialView("EditFormPartial", model));
 }
예제 #4
0
 public ActionResult RegistrationForm(RegistrationForm registrationForm)
 {
     if (ModelState.IsValid && CaptchaExtension.GetIsValid("captcha"))
     {
         ViewBag.SuccessValidation = true;
         registrationForm          = new RegistrationForm();
     }
     return(DemoView("RegistrationForm", registrationForm));
 }
        public virtual async Task <ActionResult> Manage(ManageUserViewModel model)
        {
            bool hasPassword = HasPassword();

            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl        = Url.Action("Manage");
            if (hasPassword)
            {
                if (ModelState.IsValid && CaptchaExtension.GetIsValid("Captcha"))
                {
                    IdentityResult result = await UserManager
                                            .ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            else
            {
                // User does not have a password so remove any validation errors caused by a missing OldPassword field
                ModelState state = ModelState["OldPassword"];
                if (state != null)
                {
                    state.Errors.Clear();
                }

                if (ModelState.IsValid)
                {
                    IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #6
0
        public ActionResult Contact(ContactoViewModel model)
        {
            if (ModelState.IsValid && CaptchaExtension.GetIsValid("captcha"))
            {
                string _esquema  = Request.Url.Scheme;
                string _hostName = Request.Url.Host;

                EmailManager.EnviarEmailContacto(model.Nombre, model.Email, model.Asunto, model.Mensaje, this.ControllerContext, RouteTable.Routes, _esquema, _hostName);
                return(RedirectToAction("Index"));
            }

            ViewBag.Title     = string.Format("{0} - {1}", Resources.BCMWebPublic.labelAppTitle, Resources.BCMWebPublic.ContactPageTitle);
            ViewBag.PageTitle = Resources.BCMWebPublic.ContactPageTitle;
            return(View(model));
        }
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Mobile))
            {
                model.Mobile = model.UserName;
            }
            if (ModelState.IsValid && CaptchaExtension.GetIsValid("Captcha"))
            {
                //string confirmationToken = ctrlHelper.CreateConfirmationToken();
                var user = new ApplicationUser()
                {
                    UserName       = model.UserName,
                    EmailConfirmed = false,
                    Mobile         = model.UserName,
                    Name           = model.Name

                                     //ConfirmationToken = confirmationToken,
                                     //Email = model.Email,
                                     //Address = model.Address,
                                     //Family = model.Family,
                                     //Phone = model.Phone
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInAsync(user, isPersistent: false);
                    //return RedirectToAction("Index", "Home");
                    //SendEmailConfirmation(model.Email, model.Name, confirmationToken);
                    return(RedirectToAction("RegisterStepTwo"));
                }
                else
                {
                    AddErrors(result);
                }
            }
            return(View(model));
        }