public ActionResult Create([Bind(Include = "UsuarioId,UsuDocumento,UsuNombre,UsuEmail,UsuTelefono,aspnetusersId,EmpresaId,Estado,CreadoPor,FechaCreacion,ModificadoPor,FechaModificacion")] usuario usuario, string RoleId) { if (RoleId.Equals("")) { ModelState.AddModelError("RoleId", String.Format("Debe seleccionar un Roll")); } if (db.aspnetusers.Any(c => c.UserName.Trim().ToUpper() == usuario.UsuEmail)) { ModelState.AddModelError("", String.Format("Este correo ya se encuentra registrado")); } if (ModelState.IsValid) { HomeController home = new HomeController(); string[] arr1 = home.crearUsuario(RoleId, usuario.UsuEmail, UserManager).Split(','); string AspUserId = arr1[0]; string AspUserPasswd = arr1[1]; if (!AspUserId.Equals("")) { string mensaje = "<p <span style=\"font-size: 10pt;\">Apreciado " + usuario.UsuNombre + "</span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Ingresando a <a style=\"font-family: Calibri, sans-serif; font-size: 11pt;\" href=\"http://google.com\">CrediAdmin.com</a><span style=\"color: #1f497d; font-family: Calibri, sans-serif;\">, </span><span style=\"color: #1f497d; font-family: Calibri, sans-serif;\"> </span>podrás utilizar nuestra plataforma.</span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Nombre de Usuario: " + usuario.UsuEmail + "</span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Clave: " + AspUserPasswd + "</span></p>"; mensaje = mensaje + "<p><span style=\"font-size: 10pt;\"> </span></p>"; //Nombre + "" + AspUserPasswd; if (EnviarCorreoController.enviarCorreo(1, usuario.UsuEmail, "Bienvenido a CrediAdmin", mensaje)) { usuario.aspnetusersId = AspUserId; db.usuario.Add(usuario); db.SaveChanges(); return(RedirectToAction("Index")); } else { home.eliminarUsuarioAspNet(AspUserId); ModelState.AddModelError("UsuEmail", String.Format("No fue posible enviar correo electronico con credenciales")); } } else { ModelState.AddModelError("RoleId", String.Format("No fue posible crear usuario, vuelva a intentarlo")); } } if (usuario.EmpresaId == 1) { ViewBag.RoleId = new SelectList(context.Roles.OrderBy(r => r.Name).ToList(), "Name", "Name"); } else { ViewBag.RoleId = new SelectList(context.Roles.Where(r => r.Name != "Master").OrderBy(r => r.Name).ToList(), "Name", "Name"); } ViewBag.EmpresaId = new SelectList(db.empresa.Where(c => c.Estado == true).OrderBy(e => e.Nit), "EmpresaId", "Nit", usuario.EmpresaId); return(View(usuario)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null)// || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // 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); //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); //return RedirectToAction("ForgotPasswordConfirmation", "Account"); // HomeController home = new HomeController(); // string correoUsuario = u.USU_Email; // UserManager manager = new UserManager(); string claveInicial = HomeController.GenerarContrasena(); string mensaje = "<p>Su nombre de usuario es: " + model.Email + "<p>"; mensaje = mensaje += "<p>Su nueva contraseña es: " + claveInicial + "<p>"; // HomeController.enviarCorreo(model.Email, "Recordatorio de contraseña CrediAdmin", mensaje); if (EnviarCorreoController.enviarFromAWS(1, model.Email, "Recordatorio de contraseña CrediAdmin", mensaje)) { UserManager.RemovePassword(user.Id); UserManager.AddPassword(user.Id, claveInicial); ViewBag.Layout = 1; ViewBag.action = "index"; ViewBag.controller = "Home"; ViewBag.tipo = "bg-success"; ViewBag.mensaje = "Se envio un mensaje a su correo electronico con una nueva contraseña para ingresar a nuestra plataform"; return(View("../Shared/Mensaje")); } else { ViewBag.Layout = 1; ViewBag.action = "ForgotPassword"; ViewBag.controller = "Account"; ViewBag.tipo = "bg-warning"; ViewBag.mensaje = "No fue posible enviar correo electronico"; return(View("../Shared/Mensaje")); } } // If we got this far, something failed, redisplay form return(View(model)); }
public JsonResult CrearEmpresa(string Nombre, string EmpEmail) { ModelState.Clear(); empresa e = new empresa(); e.Nombre = Nombre; e.EmpEmail = EmpEmail; e.Nit = ""; e.EmpAnioActual = DateTime.Now.Year; e.EmpMesActual = DateTime.Now.Month; //FechaCreacion=new DateTime(DateTime.Now.Year, DateTime.Now.Month,DateTime.Now.Day) string s = ""; bool ok = false; if (TryValidateModel(e)) { if (ModelState.IsValid) { string AspUserId = ""; try { string email = EmpEmail.Trim().ToUpper(); if (!db.aspnetusers.Any(c => c.UserName.Trim().ToUpper() == email)) { string[] arr1 = crearUsuario("Administrador", EmpEmail, UserManager).Split(','); AspUserId = arr1[0]; string AspUserPasswd = arr1[1]; if (!AspUserId.Equals("")) { string url = "http://" + ConfigurationManager.AppSettings["URLServer"].ToString() + "/icredit"; string mensaje = "<p <span style=\"font-size: 10pt;\">Apreciado " + Nombre + "</span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Ingresando a <a style=\"font-family: Calibri, sans-serif; font-size: 11pt;\" href=\"" + url + "\">iCredit.com</a><span style=\"color: #1f497d; font-family: Calibri, sans-serif;\">, </span><span style=\"color: #1f497d; font-family: Calibri, sans-serif;\"> </span>podrás utilizar nuestra plataforma para administrar tus creditos </span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Nombre de Usuario: " + EmpEmail + "</span></p>"; mensaje = mensaje + "<p <span style=\"font-size: 10pt;\">Clave: " + AspUserPasswd + "</span></p>"; mensaje = mensaje + "<p><span style=\"font-size: 10pt;\"> </span></p>"; //Nombre + "" + AspUserPasswd; if (EnviarCorreoController.enviarFromAWS(1, EmpEmail, "Bienvenido a iCredit", mensaje)) { using (System.Data.Entity.DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { db.empresa.Add(e); usuario uxe = new usuario(); consecutivo con = new consecutivo(); con.empresa = e; con.CreditoNro = 0; con.RetiroInteresNro = 0; con.AbonoNro = 0; db.consecutivo.Add(con); uxe.UsuNombre = Nombre; uxe.aspnetusersId = AspUserId; uxe.UsuEmail = EmpEmail; uxe.empresa = e; db.usuario.Add(uxe); db.SaveChanges(); // EnviarCorreoController.sendVerificationEmailAmazonSES(EmpEmail); dbTran.Commit(); ok = true; iniciarEmpresa(e.EmpresaId); } catch (Exception ex) { ok = false; eliminarUsuarioAspNet(AspUserId); s = String.Format(ex.ToString()); dbTran.Rollback(); } } } else { s = "No fue posible enviar correo electronico"; eliminarUsuarioAspNet(AspUserId); } } } else { s = "Este Correo Electronico ya se encuentra Registrado"; } } catch (Exception ex) { s = ex.ToString().Substring(0, 200); // ViewBag.mensaje = "Exception caught in CreateTestMessage2(): {0}" + ex.ToString(); // Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString()); eliminarUsuarioAspNet(AspUserId); } } } if (!ok) { foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { s = s + error.ErrorMessage; } } } // return Json(new { success = false }); return(Json(new { success = ok, Error = s }, JsonRequestBehavior.AllowGet)); }