Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. <form action="@Url.Action(" Index ","Home ")" method="post" class="m-t" role="form" name="LoginForm">
  2. <!-- Ocultamos el input con el nombre del subdominio -->
  3. <input type="hidden" name="subdominio" value="@Model.subdominio" />
  4. @{ if (Model.subdominio != null) {
  5. <input type="hidden" value="@Model.rfcCompany" name="rfcCompany" id="rfcCompany" />
  6. <input type="hidden" value="@Model.nameCompany" name="nameCompany" id="nameCompany" />
  7. <input type="hidden" value="@Model.urlLogo" name="urlLogo" id="urlLogo" />
  8. } }
  9. <div class="form-group">
  10. <div class="input-group">
  11. <span class="input-group-addon b-r-md"><span class="glyphicon glyphicon-user"></span></span>
  12. <input type="email" name="email" class="form-control b-r-md" placeholder="Usuario">
  13. </div>
  14. <p class="help-block" id="LemailErr"></p>
  15. </div>
  16. <div class="form-group">
  17. <div class="input-group">
  18. <span class="input-group-addon b-r-md"><span class="fa fa-key"></span></span>
  19. <input type="password" name="portalPassword" class="form-control b-r-md" placeholder="Contraseña">
  20. </div>
  21. <p class="help-block" id="LportalPassword"></p>
  22. </div>
  23. <button type="submit" class="btn btn-primary block full-width m-b b-r-md">Entrar</button>
  24. @{ if (Model.subdominio != null) {
  25. <a href="/RestaurarContraseña/RestaurarPass/EnviarCorreo/@Model.rfcCompany"><small>¿Olvidaste tu contraseña?</small></a>
  26. if (Model.permitirAcceso > 1) {
  27. <p class="text-muted text-center"><small>¿No tienes una cuenta?</small></p>
  28. <a class="btn btn-sm btn-white btn-block" href="@Url.Action(" Nuevo ", "Registro ", new { area = "DescargaU " })/@Model.rfcCompany">Registrarse</a>
  29. }
  30. } }
  31. </form>
  32.  
  33. <script>
  34. $('form[name="LoginForm"]').validate({
  35. //cambiando la posicion del mensaje de error
  36. errorPlacement: function(error, element) {
  37. error.appendTo(element.parent(".input-group").next("p"));
  38. },
  39.  
  40. rules: {
  41. email: {
  42. required: true,
  43. email: true
  44. },
  45. portalPassword: {
  46. required: true,
  47. minlength: 6
  48. }
  49. },
  50. messages: {
  51. email: {
  52. required: "Ingresa tu Usuario",
  53. email: "Tu Usuario debe seguir este formato name@domain.com"
  54. },
  55. portalPassword: {
  56. required: "No deje este campo vacio",
  57. minlength: jQuery.validator.format("Minimo {0} caracteres")
  58. }
  59. }
  60. });
  61. </script>
  62.  
  63. public ActionResult Index(string Subdominio)
  64. {
  65. AdministrarModel model = new AdministrarModel();
  66. model.subdominio = Subdominio;
  67. return view(model);
  68. }
  69.  
  70. [HttpPost]
  71. public ActionResult Index(AdministrarModel model)
  72. {
  73. LogOnClient webClient = new LogOnClient();
  74. AdministrarModel model = new AdministrarModel();
  75. LRDMResponse respuesta = null;
  76. LMNGRequest datosSession = new LMNGRequest()
  77. {
  78. AdmixProduct = LogOn.AdmixProduct.AdmixManagement,
  79. Username = model.email,
  80. Password = model.portalPassword,
  81. DeviceName = WSConfiguration.HostName,
  82. IpAddress = WSConfiguration.IpAddress,
  83. TypeDivice = LogOn.TypeDevice.Web
  84. };
  85. if (webClient.LoginManagement(datosSession, out respuesta))
  86. {
  87. sesionManage.cuenta = model.email.ToLower();
  88. sesionManage.devKey = respuesta.DeviceKey;
  89. sesionManage.mobileKey = respuesta.MobileKey;
  90. HttpContext.Session["sessionManage"] = sesionManage;
  91. return RedirectToAction("Apps", "MenuApps");//llega correctamente hasta aquí
  92. }else{
  93. model.error = "Usuario y contraseña incorrectos, intente nuevamente";
  94. return View(model);
  95. }
  96. }
  97.  
  98. public class SubdomainRoute: RouteBase {
  99. public override RouteData GetRouteData(HttpContextBase httpContext) {
  100. if (httpContext.Request == null || httpContext.Request.Url == null) {
  101. return null;
  102. }
  103.  
  104. var host = httpContext.Request.Url.Host;
  105. var index = host.IndexOf(".");
  106. string[] segments = httpContext.Request.Url.PathAndQuery.TrimStart('/').Split('/');
  107.  
  108. if (index < 0) {
  109. return null;
  110. }
  111.  
  112. var subdomain = host.Substring(0, index);
  113. string[] blacklist = {
  114. "www",
  115. "admix",
  116. "mail"
  117. };
  118.  
  119. if (blacklist.Contains(subdomain)) {
  120. return null;
  121. }
  122.  
  123. string controller = "Home";
  124. string action = "Index";
  125.  
  126. var routeData = new RouteData(this, new MvcRouteHandler());
  127. routeData.Values.Add("controller", controller); //Goes to the relevant Controller class
  128. routeData.Values.Add("action", action); //Goes to the relevant action method on the specified Controller
  129. routeData.Values.Add("Subdominio", subdomain); //pass subdomain as argument to action method
  130. return routeData;
  131. }
  132.  
  133. public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
  134. //Implement your formating Url formating here
  135. return null;
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement