示例#1
0
 /// <summary>
 /// provides an entry point for custom authorization checks.
 /// </summary>
 /// <param name="httpContext">HTTP context</param>
 /// <returns>true if the user is authorized; otherwise, false.</returns>
 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     if (base.AuthorizeCore(httpContext))
     {
         if (httpContext.Request.QueryString["mod"] != null)
         {
             int modulId = 0;
             int.TryParse(httpContext.Request.QueryString["mod"], out modulId);
             int          userId = (httpContext.User as CustomPrincipal).UserId;
             List <Modul> moduls = CustomMemberShipProvider.GetModuls(userId, new SqlSession(), httpContext);
             return(moduls.Exists(t => t.ModulId == modulId));
         }
         else if (httpContext.Request.RequestContext.RouteData.Values.ContainsKey("controller"))
         {
             string       controller = httpContext.Request.RequestContext.RouteData.GetRequiredString("controller");
             int          userId     = (httpContext.User as CustomPrincipal).UserId;
             List <Modul> moduls     = CustomMemberShipProvider.GetModuls(userId, new SqlSession(), httpContext);
             return(moduls.Exists(t => t.Controller == controller));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
示例#2
0
        /// <summary>
        /// validates whether a user exists
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="twitterId">twitter id</param>
        /// <returns>returns a <c>AuthencReturn</c></returns>
        public AuthencReturn ValidateUserTwitter(HttpContextBase context, string twitterId)
        {
            try
            {
                this.Userrepository.Entity.TwitterId = twitterId;
                this.Userrepository.Load();

                if (this.Userrepository.Entity.UserId != null && this.Userrepository.Entity.Active == true)
                {
                    LanguageRepository languagerepo = new LanguageRepository(this.session);
                    languagerepo.Entity.LanguageId = this.Userrepository.Entity.LanguageId;
                    languagerepo.LoadByKey();

                    if (context.Session["lang"] == null)
                    {
                        context.Session.Add("lang", languagerepo.Entity);
                    }
                    else
                    {
                        context.Session["lang"] = languagerepo.Entity;
                    }

                    RolUserRepository objus = new RolUserRepository(this.session);
                    objus.Entity.UserId = this.Userrepository.Entity.UserId;
                    IList <RolUser> coll = objus.GetAllReadOnly();
                    List <Domain.Entities.Modul> moduls = CustomMemberShipProvider.GetModuls(this.Userrepository.Entity.UserId.Value, this.session, context);
                    string isFrontEndAdmin = "false";
                    if (moduls.Exists(t => t.ModulId == 57))
                    {
                        isFrontEndAdmin = "true";
                    }

                    StringBuilder strbRoles = new StringBuilder();

                    foreach (RolUser item in coll)
                    {
                        strbRoles.Append(item.RolId.ToString() + "-");
                    }

                    Utils.SetUserRewardAction(this.Userrepository.Entity.UserId.Value, RewardAction.UserActionType.Login, 2, 1, this.session, context, true, languagerepo.Entity);
                    this.Userrepository.Load();

                    this.Createticket(
                        strbRoles,
                        this.Userrepository.Entity.Names,
                        this.Userrepository.Entity.UserId.Value,
                        this.Userrepository.Entity.Email,
                        this.Userrepository.Entity.Image,
                        this.Userrepository.Entity.Medallos,
                        isFrontEndAdmin);

                    return(AuthencReturn.USER_OK);
                }
                else if (this.Userrepository.Entity.UserId != null && this.Userrepository.Entity.Active == false)
                {
                    return(AuthencReturn.USER_BLOCKED);
                }
                else
                {
                    return(AuthencReturn.NOT_FOUND);
                }
            }
            catch (Exception ex)
            {
                Utils.InsertLog(
                    this.session,
                    "Error Validando Usuario",
                    ex.Message + " " + ex.StackTrace);
                return(AuthencReturn.ERROR);
            }
        }