public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); MailHelper.EnviarEmail(user.Email, user.UserProfileInfo.Nome, "[WebVans] - Restauração de senha", "Para restaurar sua senha de acesso clique <a href=\"" + callbackUrl + "\">aqui</a>"); //await UserManager.SendEmailAsync(user.Id, "[WebVans] - Restauração de senha", "Para restaurar sua senha de acesso clique <a href=\"" + callbackUrl + "\">aqui</a>"); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, UserProfileInfo = new UserProfileInfo { CPF = model.CPF, CNPJ = model.CNPJ, Nome = model.Nome, Telefone = model.Telefone, UsuarioValidado = false } }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("Email: {0}", model.Email)); sb.AppendLine(string.Format("Nome: {0}", model.Nome)); sb.AppendLine(string.Format("CPF: {0}", model.CPF)); sb.AppendLine(string.Format("CNPJ: {0}", model.CNPJ)); sb.AppendLine(string.Format("Telefone: {0}", model.Telefone)); sb.AppendLine(string.Empty); sb.AppendLine("Para aprovar vá para: http://www.webvans.com.br/AprovaUsuario.asmx?op=Aprova"); MailHelper.EnviarEmail(model.Email, model.Nome, "[WebVans] - Novo usuário cadastrado, aguardando aprovação", sb.ToString()); return(RedirectToAction("Index", "AguardeValidacao")); //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Solicitar(SolicitarVanViewModel viewModel) { if (ModelState.IsValid) { var solicitacaoModel = new SolicitacaoModel { DataSolicitacao = DateTime.Now, Descricao = viewModel.Descricao, Solicitante = db.Users.Find(User.Identity.GetUserId()), Van = db.Vans.Find(viewModel.ID) }; db.Solicitacaos.Add(solicitacaoModel); db.SaveChanges(); var vanSolicitada = db.Vans.Find(viewModel.ID); var solicitante = db.Users.Find(User.Identity.GetUserId()); StringBuilder sb = new StringBuilder(); sb.AppendLine("Sua van foi solicitada. Seguem abaixo os dados da Solicitação:"); sb.AppendLine(string.Empty); sb.AppendLine(string.Format("Data: {0}", DateTime.Now)); sb.AppendLine(string.Format("Van: {0} - {1}", vanSolicitada.Modelo.Marca.Nome, vanSolicitada.Modelo.Nome)); sb.AppendLine(string.Format("Placa: {0}", vanSolicitada.Placa)); sb.AppendLine(string.Empty); sb.AppendLine(string.Format("Usuário: {0}", solicitante.UserProfileInfo.Nome)); sb.AppendLine(string.Format("E-mail: {0}", solicitante.Email)); sb.AppendLine(string.Format("CPF: {0}", solicitante.UserProfileInfo.CPF)); sb.AppendLine(string.Format("CNPJ: {0}", solicitante.UserProfileInfo.CNPJ)); sb.AppendLine(string.Format("Telefone: {0}", solicitante.UserProfileInfo.Telefone)); sb.AppendLine(string.Empty); sb.AppendLine(string.Format("Descrição: {0}", viewModel.Descricao)); MailHelper.EnviarEmail(vanSolicitada.Proprietario.Email, vanSolicitada.Proprietario.UserProfileInfo.Nome, "[WebVans] - Van Solicitada!", sb.ToString()); viewModel.SolicitacaoConcluida = true; } return(View(viewModel)); }
public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email, UserProfileInfo = new UserProfileInfo { CPF = model.CPF, CNPJ = model.CNPJ, Nome = model.Nome, Telefone = model.Telefone } }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("Email: {0}", model.Email)); sb.AppendLine(string.Format("Nome: {0}", model.Nome)); sb.AppendLine(string.Format("CPF: {0}", model.CPF)); sb.AppendLine(string.Format("CNPJ: {0}", model.CNPJ)); sb.AppendLine(string.Format("Telefone: {0}", model.Telefone)); sb.AppendLine(string.Empty); sb.AppendLine("Para aprovar vá para: http://www.webvans.com.br/AprovaUsuario.asmx?op=Aprova"); MailHelper.EnviarEmail(model.Email, model.Nome, "[WebVans] - Novo usuário cadastrado, aguardando aprovação", sb.ToString()); return(RedirectToAction("Index", "AguardeValidacao")); //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); //return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }