public ActionResult Contact(ContactViewModel model)
        {
            bool captchaValid = ReCaptcha.Validate(SiteConfiguration.ReCaptchaSecretKey);

            if(!captchaValid)
            {
                DisplayMessage(Translations.Validations.CaptchaMessageError, MessageType.Warning);
                AddError("Captcha", Translations.Validations.CaptchaMessageError);
                return RedirectToAction("Contact");
            }

            if (ModelState.IsValid)
            {
                var message = Mapper.Map<ContactMessage>(model);
                message.IPAddress = Request.UserHostAddress;
                contactService.SaveMessage(message);

                var mailer = new UserMailer();
                mailer.Contact(model).Send();

                DisplayMessage("Su mensaje ha sido enviado.", MessageType.OK);
                TempData["HideForm"] = true;
            }

            return RedirectToAction("Contact");
        }
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByNameAsync(model.Email);

                if (user != null)
                {
                    if (!await userManager.IsEmailConfirmedAsync(user.Id))
                    {
                        var token = await userManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = token }, protocol: Request.Url.Scheme);
                        var mailer = new UserMailer();
                        mailer.ConfirmEmail(user, callbackUrl).Send();

                        AddError("Error", Translations.Validations.ComfirmEmailError);
                        DisplayMessage(Translations.Validations.ComfirmEmailError, MessageType.Warning);
                        return RedirectToAction("Login");
                    }

                    var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

                    if (result == SignInStatus.Success)
                    {
                        if (!string.IsNullOrEmpty(returnUrl))
                            return RedirectToLocal(returnUrl);
                        else
                            return RedirectToRole();
                    }
                }
            }

            AddError("Error", Translations.Validations.LoginAttemptError);
            return RedirectToAction("Login");
        }
        public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByNameAsync(model.Email);

                if (user == null) // || !(await userManager.IsEmailConfirmedAsync(AppMember.Id)))
                {
                    return View("ForgotPasswordConfirmation");
                }


                string code = await userManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                var mailer = new UserMailer();
                mailer.PasswordReset(user, callbackUrl).Send();

                //await userManager.SendEmailAsync(AppMember.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                return RedirectToAction("ForgotPasswordConfirmation");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var appMember = new AppMember
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    PictureUrl = "/img/profiles/default.png"
                };

                var result = await userManager.CreateAsync(appMember, model.Password);
                
                if (result.Succeeded)
                {
                    var currentUser = await userManager.FindByNameAsync(model.Email);
                    await userManager.AddToRoleAsync(currentUser.Id, "Autor");
                    //await signInManager.SignInAsync(currentUser, isPersistent: false, rememberBrowser: false);

                    var token = await userManager.GenerateEmailConfirmationTokenAsync(currentUser.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = currentUser.Id, code = token }, protocol: Request.Url.Scheme);

                    var mailer = new UserMailer();
                    mailer.ConfirmEmail(currentUser, callbackUrl).Send();
                    ViewBag.Email = currentUser.Email;
                    return View("CheckEmail");
                }

                AddErrors(result);
            }

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