/// <summary> /// Autentica un Usuario /// </summary> /// <param name="strUsername">Usuario</param> /// <param name="strPassword">Contraseña</param> public static String Authenticate(String userName, String passsword, BizServer bizServer) { List<string> lstRoles = new List<string>(); UserInfo userInfo = new UserInfo(); String LoginSuccess = ValidateUser(userName, passsword, ref lstRoles, ref userInfo, bizServer); if (LoginSuccess == String.Empty) { FormsAuthentication.Initialize(); String strRole = AssignRoles(userName, lstRoles); StringWriter writer = new StringWriter(); XmlSerializer xsl = new XmlSerializer(userInfo.GetType()); xsl.Serialize(writer, userInfo); strRole += "#" + writer.ToString(); //AddMinutes determina cuanto tiempo el usuario estará logueado despues de dejar el sitio si no se deslogueo. FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(60), false, strRole, FormsAuthentication.FormsCookiePath); HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat))); return LoginSuccess; } else return LoginSuccess; }
/// <summary> /// Validate WebClientApp User /// </summary> /// <param name="prefix"></param> /// <param name="mobile"></param> /// <param name="password"></param> /// <param name="companyID"></param> /// <param name="userInfo"></param> /// <param name="bizServer"></param> /// <returns></returns> private static String ValidateUser(String userName, String password, ref List<string> lstRoles, ref UserInfo userInfo, BizServer bizServer) { DataTable users; using (User user = new User(bizServer)) { object result = new DataTable(); user.Login(userName, password, ref result); users = (DataTable)result; } if (users.Rows.Count > 0) { //Get ClientApp UserInfo userInfo.IdClub = Convert.ToInt32(users.Rows[0]["ClubID"]); userInfo.Nombre = users.Rows[0]["ClubName"].ToString(); userInfo.Email = users.Rows[0]["Mail"].ToString(); userInfo.InternalPath = WebConfigurationManager.AppSettings["InternalMainPath"] + userName + "_" + userInfo.IdClub.ToString() + "\\"; userInfo.ExternalPath = WebConfigurationManager.AppSettings["ExternalMainPath"] + userName + "_" + userInfo.IdClub.ToString() + "/"; userInfo.Picture = userInfo.ExternalPath + userName + ".png"; string NextMatchPath = Path.Combine(userInfo.InternalPath, "Rival"); userInfo.NextMatch = Path.GetFileNameWithoutExtension(new FileInfo(Directory.GetFiles(NextMatchPath)[0]).Name); HttpContext.Current.Session[Consts.USER_INFO] = userInfo; lstRoles.Add("AppClient"); return string.Empty; //Usuario Logueado. } else { return "Usuario y/o Contraseña incorrectos"; } }