Пример #1
0
    //public string Referer;

    public LMEvent(string message, object eventSource, int eventCode, int eventDetailCode)
      : base(message, eventSource, WebEventCodes.WebExtendedBase + eventCode, eventDetailCode) {
      info = urlInfo.GetUrlInfo();
      cook = LMStatus.CookieLow;
      if (HttpContext.Current != null) {
        RequestUrl = HttpContext.Current.Request.Url.AbsolutePath;
        RequestUrl += ", agent = " + HttpContext.Current.Request.UserAgent;
        Uri rf = HttpContext.Current.Request.UrlReferrer;
        if (rf != null) RequestUrl += ", referer = " + rf.AbsoluteUri;
        //Referer = rf==null ? null : rf.AbsoluteUri;
      }
    }
Пример #2
0
 public static string createOtherTypeTicket(OtherType type, int otherId, string email, string firstName, string lastName) {
   LMCookie cook = new LMCookie() { id = otherTypeId(type, otherId), EMail = email, FirstName = firstName, LastName = lastName, CreateTick = DateTime.UtcNow.Ticks };
   return string.Format("ticket={0}", cook.ToString());
 }
Пример #3
0
    //public static void refreshMoodleProfile(ProfileData prof, Moodle.mdl_user user) {
    //  prof.Email = user.email == null ? user.id + "@fake.com" : user.email;
    //  prof.Site = Domains.org;
    //  prof.Address.FirstName = user.firstname;
    //  prof.Address.LastName = user.lastname;
    //  try {
    //    prof.Address.CompanyName = user.mdl_user_info_datas.First(dt => Convert.ToInt32(dt.fieldid) == mdl_CompanyFldNum).data;
    //    prof.Address.Web = user.mdl_user_info_datas.First(dt => Convert.ToInt32(dt.fieldid) == mdl_UrlFldNum).data;
    //  } catch { }
    //}

    //public static bool onMoodleLogin(HttpContext ctx, Moodle.mdl_user user) {
    //  OtherType type = OtherType.Moodle;
    //  ProfileData prof = LMComDataProvider.readOtherProfile(type, user.id.ToString());
    //  if (prof == null) { //profil neni zalozen v databazi - zaloz
    //    prof = LMComDataProvider.createProfileStart(Domains.org);
    //    prof.OtherType = type;
    //    prof.OtherId = user.id.ToString();
    //    prof.Roles = 0;
    //  }
    //  refreshMoodleProfile(prof, user);
    //  LMComDataProvider.WriteProfile(prof);
    //  LMComDataProvider.setProfileToCache(prof);
    //  LMCookie cook = new LMCookie();
    //  cook.EMail = prof.Email;
    //  cook.id = prof.Id;
    //  cook.Type = OtherType.Moodle;
    //  cook.TypeId = user.username;
    //  HttpContext.Current.Items[LowUtils.c_cookieName] = cook;
    //  LMComDataProvider.checkProfileInCache(ctx, cook.id);
    //  refreshLastRequest(ctx, cook);
    //  return false;
    //}

    public static string GetActStatus(HttpContext context, LMCookie cook) {
      urlInfo ui = urlInfo.GetUrlInfo(context);
      string res;
      if (cook == null || cook.EMail == null) {
        res = "{'isAuthenticated':false,'id':-1";
        if (context.Request["forceLogin"] == "true") res += ",'forceLogin':true";
      } else {
        res = "{'isAuthenticated':true,'id':" + cook.id.ToString() + ",'server':";
        res += "'" + cook.Type.ToString() + "'";
        res += ",'courseId':'" + cook.courseId + "'";
        res += ",'email':'" + cook.EMail + "'";
      }
      res += ",'site':'" + ui.Site + "'";
      res += ",'country':'" + cook.Country + "','lang':'" + ui.Lang + "'";
      return res + "}";
    }
Пример #4
0
 public static void fakeSetCookie(HttpContext ctx, string email) {
   LMCookie cook = new LMCookie();
   cook.EMail = email;
   cook.id = 123454321;
   cook.Type = OtherType.no;
   cook.TypeId = "123454321";
   HttpContext.Current.Items[LowUtils.c_cookieName] = cook;
   LMStatus.saveCookie(ctx);
 }
Пример #5
0
    /*public static bool onGoogleFacebookLogin(HttpContext ctx, bool isFacebook, string id, string firstName, string lastName, string sex, string courseId, getOtherData otherDataEvent, object eventData) {
      LMCookie cook = LMStatus.Cookie;
      if (cook != null && cook.facebookId != 0 && isFacebook && cook.facebookId.ToString() == id && courseId == cook.courseId) return true;
      if (cook != null && cook.googleId != null && !isFacebook && cook.googleId == id && courseId == cook.courseId) return true;
      OtherType type = isFacebook ? OtherType.Facebook : OtherType.Google;
      return onGoogleFacebookLogin(ctx, type, id, id + "@" + type.ToString() + ".fake", firstName, lastName, sex, courseId, otherDataEvent, eventData);
    }*/

    public static bool onGoogleFacebookLogin(HttpContext ctx, OtherType type, string id, string email, string firstName, string lastName, string sex, string courseId, getOtherData otherDataEvent, object eventData) {
      if (string.IsNullOrEmpty(email)) return false;
      email = email.ToLower();
      //hotovo:
      string dataStr = otherDataEvent != null ? otherDataEvent(eventData) : null;
      ProfileData prof = LMComDataProvider.readOtherProfile(type, id, email);
      if (string.IsNullOrEmpty(email)) {
        if (prof != null) email = prof.Email;
        if (string.IsNullOrEmpty(email)) email = "fake@" + type.ToString() + ".www";
      }
      if (prof == null) { //profil neni zalozen v databazi - zaloz
        prof = LMComDataProvider.createProfileStart(Domains.com);
        prof.OtherType = type;
        prof.OtherId = id;
        prof.Roles = 0;
        prof.Email = email;
        prof.Address.FirstName = firstName;
        prof.Address.LastName = lastName;
        prof.Male = sex == null ? true : sex.ToLower() == "male";
        prof.Site = Domains.com;
        prof.OtherData = dataStr;
        LMComDataProvider.WriteProfile(prof);
      } else {
        prof.Site = Domains.com;
        prof.OtherData = dataStr;
        prof.OtherType = type;
        prof.OtherId = id;
        prof.Email = email;
        prof.Address.FirstName = firstName;
        prof.Address.LastName = lastName;
      }
      //vymaz ostatni profily s tim samym emailem
      LMComDataProvider.removeDuplicetedEMails(email, prof.Id);
      //
      LMComDataProvider.setProfileToCache(prof);
      LMCookie cook = new LMCookie();
      cook.EMail = prof.Email;
      cook.id = prof.Id;
      cook.Type = type;
      cook.TypeId = id;
      cook.FirstName = firstName;
      cook.LastName = lastName;
      HttpContext.Current.Items[LowUtils.c_cookieName] = cook;
      LMComDataProvider.checkProfileInCache(ctx, cook.id);
      //refreshLastRequest(ctx, cook);
      return false;
    }
Пример #6
0
 static LMCookie getCookie() {
   LMCookie cook = CookieLow;
   if (cook != null) return cook; //cookie j*z vytvoren a ulozen v HttpContext.Current.Items
   urlInfo ui = urlInfo.GetUrlInfo();
   HttpContext ctx = HttpContext.Current;
   //**** Fake cookie pro ladeni autorizace Seznamu
   /*string sezLog = ConfigurationManager.AppSettings["debug.logToSeznam"];
   if (!string.IsNullOrEmpty(sezLog)) {
     Int64 userId;
     if (Int64.TryParse(sezLog, out userId)) {
       cook = new LMCookie(); cook.id = userId; cook.EMail = "*****@*****.**"; cook.seznamId = 1;
       ctx.Items[LowUtils.c_cookieName] = cook;
       checkCookie(ctx, cook);
       if (ui != null && ui.EACourse != CourseIds.no) cook.courseId = ui.EACourse.ToString();
       refreshLastRequest(ctx, cook);
       return cook;
     }
   }*/
   //**** LM Cookie
   cook = LMCookie.DeserializeCookie();
   //**** Seznam cookie? Hledá se specializovaný Seznam cookie
   LMCookie seznamCook = null; // LMComLib.Seznam.Utils.getSeznamCookie(ctx, cook, ui);
   if (seznamCook != null)
     cook = seznamCook;
   //**** LM anonymous cookie
   if (cook == null) {
     cook = new LMCookie();
     cook.id = -LMComDataProvider.getUniqueId(LMComDataProvider.uiUserId);
   }
   ctx.Items[LowUtils.c_cookieName] = cook;
   LMComDataProvider.checkProfileInCache(ctx, cook.id);
   checkCookie(ctx, cook);
   if (ui != null && ui.EACourse != CourseIds.no) cook.courseId = ui.EACourse.ToString();
   //refreshLastRequest(ctx, cook);
   return cook;
 }
Пример #7
0
 static void checkCookie(HttpContext ctx, LMCookie cook) {
   if (!string.IsNullOrEmpty(cook.EMail)) { // && Machines.isCrawlerEx(ctx)) {
     Emailer em = new Emailer(null, "*****@*****.**", "Invalid crawler: ", ctx.Request.UserAgent);
     //em.From = "*****@*****.**";
     em.AddTo("*****@*****.**");
     em.AddTo("*****@*****.**");
     //em.Subject = "Invalid crawler: " + ctx.Request.UserAgent;
     em.SendMail();
   }
 }
Пример #8
0
    public static void loginProfile(ProfileData prof) {
      if (prof == null) return;

      //10.7.2009, nektere profily v DB maji Site=0, pro jistotu...
      urlInfo ui = urlInfo.GetUrlInfo();
      if (ui != null) prof.Site = ui.SiteId;

      LMComDataProvider.setProfileToCache(prof);

      //PZ 12.7.08: cookie se pro noveho uzivatele musi vytvorit kompletne znova
      LMCookie cook = new LMCookie(); HttpContext.Current.Items[LowUtils.c_cookieName] = cook;

      cook.id = prof.Id;
      cook.EMail = prof.Anonymous ? null : prof.Email;
      cook.FirstName = prof.Address.FirstName;
      cook.LastName = prof.Address.LastName;
      cook.Login = prof.Login;
      cook.LoginEMail = prof.LoginEMail;
      cook.roles = prof.Roles == null ? 0 : (Int64)prof.Roles;
      cook.TypeId = prof.OtherId;
      cook.Type = prof.OtherType;
      LMStatus.saveCookie(HttpContext.Current);

      LMStatus.autenticate(cook);

    }
Пример #9
0
 public static void trace(LMCookie cook, string msg, params object[] pars) {
   Logging.Trace(TraceLevel.Verbose, TraceCategory.Security, cook == null ? string.Format(msg, pars) : string.Format(cook.id + ": " + msg, pars));
 }
Пример #10
0
 public static void trace(LMCookie cook, string msg) {
   Logging.Trace(TraceLevel.Verbose, TraceCategory.Security, cook == null ? msg : cook.id + ": " + msg);
 }
Пример #11
0
 /// <summary>
 /// autentifikace na zacatku kazdeho requestu (nebo pri login x logout)
 /// </summary>
 public static void autenticate(LMCookie cook) {
   if (cook == null) cook = Cookie;
   HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(cook.EMail == null ? "" : cook.EMail), null/*PZ NEW cook.roleStrings()*/);
 }