예제 #1
0
        protected void Application_AuthenticateRequest(object sender, EventArgs args)
        {
            var chalkableUser = ChalkableAuthentication.GetUser();

            if (chalkableUser != null)
            {
                HttpContext.Current.User = chalkableUser;
            }
        }
예제 #2
0
        private static void ProcessNormalRequestError(ExceptionContext filterContext)
        {
            if (filterContext.Exception is HttpException &&
                ((HttpException)filterContext.Exception).GetHttpCode() == 401)
            {
                filterContext.ExceptionHandled = true;
                filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                filterContext.Result =
                    new RedirectToRouteResult(HtmlExtensions.ParseExpression <HomeController>(c => c.Index()));

                ChalkableAuthentication.SignOut();
            }
        }
예제 #3
0
        protected UserContext LogOn(bool remember, IUserService userService, Func <IUserService, UserContext> logOnAction)
        {
            var context = logOnAction(userService);

            if (context != null)
            {
                ChalkableAuthentication.SignIn(context, false);
                if (context.DeveloperId.HasValue && !DemoUserService.IsDemoUser(context))
                {
                    DeveloperAuthentication.SignIn(context, remember);
                }
            }
            return(context);
        }
예제 #4
0
        public ActionResult GetAccessToken(string applicationUrl, Guid?applicationId)
        {
            var app = !string.IsNullOrWhiteSpace(applicationUrl)
                    ? MasterLocator.ApplicationService.GetApplicationByUrl(applicationUrl) :
                      applicationId.HasValue
                    ? MasterLocator.ApplicationService.GetApplicationById(applicationId.Value) : null;

            if (app == null)
            {
                throw new ChalkableException("Application not found");
            }

            var token = MasterLocator.ApplicationService.GetAccessToken(app.Id, ChalkableAuthentication.GetSessionKey());

            return(Json(new
            {
                Token = token,
                ApplicationInfo = BaseApplicationViewData.Create(app)
            }));
        }
예제 #5
0
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            var         chalkablePrincipal = User as ChalkablePrincipal;
            UserContext context            = null;

            AuthorizationUserInfo authAppInfo;
            Application           app;

            if (ApplicationAuthentification.AuthenticateByToken(requestContext, ServiceLocatorFactory.CreateMasterSysAdmin().ApplicationService,
                                                                out authAppInfo, out app))
            {
                var user = ChalkableAuthentication.GetUser(authAppInfo.SessionKey);
                InitServiceLocators(user.Context);

                SchoolLocator.Context.IsOAuthUser      = true;
                SchoolLocator.Context.IsInternalApp    = app.IsInternal;
                SchoolLocator.Context.IsTrustedApp     = app.IsTrustedApp;
                SchoolLocator.Context.OAuthApplication = app.Url;
                SchoolLocator.Context.AppPermissions   = MasterLocator.ApplicationService.GetPermisions(app.Url);

                //if(SchoolLocator.Context.LoginTimeOut.HasValue)
                //    GlobalCache.UpdateExpiryUserInfo(authAppInfo.SessionKey, new TimeSpan(0, 0, SchoolLocator.Context.LoginTimeOut.Value));

                return;
            }

            if (chalkablePrincipal != null && chalkablePrincipal.Identity.IsAuthenticated &&
                !string.IsNullOrEmpty(chalkablePrincipal.Identity.Name))
            {
                if (chalkablePrincipal.Context.SisTokenExpires.HasValue && chalkablePrincipal.Context.SisTokenExpires < DateTime.Now)
                {
                    ChalkableAuthentication.SignOut();
                    return;
                }
                context = chalkablePrincipal.Context;
            }

            InitServiceLocators(context);
        }
예제 #6
0
        public ActionResult LogOnIntoDemo(string rolename, string prefix)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                Json(new ChalkableException(ChlkResources.ERR_DEMO_SCHOOL_INVALID_PREFIX));
            }
            if (rolename.ToLower() == CoreRoles.DEVELOPER_ROLE.LoweredName)
            {
                var devContext = DeveloperAuthentication.GetUser();
                if (devContext != null)
                {
                    ChalkableAuthentication.SignIn(devContext, true);
                    return(Redirect <HomeController>(c => c.Developer(null, null)));
                }
                throw new UnassignedUserException();
            }

            var context = LogOn(false, userService => userService.DemoLogin(rolename, prefix));

            if (context == null)
            {
                return(Json(new ChalkableException(string.Format(ChlkResources.USER_NOT_FOUND_IN_DEMO_SCHOOL, rolename, prefix))));
            }
            if (rolename.ToLower() == CoreRoles.DISTRICT_ADMIN_ROLE.LoweredName)
            {
                return(Redirect <HomeController>(c => c.DistrictAdmin()));
            }
            if (rolename.ToLower() == CoreRoles.TEACHER_ROLE.LoweredName)
            {
                return(Redirect <HomeController>(c => c.Teacher()));
            }
            if (rolename.ToLower() == CoreRoles.STUDENT_ROLE.LoweredName)
            {
                return(Redirect <HomeController>(c => c.Student()));
            }

            throw new ChalkableSecurityException(ChlkResources.ERR_DEMO_SCHOOL_INCORRECT_ROLE);
        }
예제 #7
0
        public ActionResult MiniQuizInfo(int standardId)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            var standard    = SchoolLocator.StandardService.GetStandardById(standardId);
            var miniQuizApp = MasterLocator.ApplicationService.GetMiniQuizAppication();

            var allApps = MasterLocator.ApplicationService.GetApplications(live: true)
                          .Select(BaseApplicationViewData.Create).ToList();

            IList <Application> suggestedApps = new List <Application>();

            if (standard.AcademicBenchmarkId.HasValue)
            {
                suggestedApps = MasterLocator.ApplicationService.GetSuggestedApplications(
                    new List <Guid> {
                    standard.AcademicBenchmarkId.Value
                }, 0, int.MaxValue);
            }

            //filter banned suggestedApps
            if (!BaseSecurity.IsSysAdminOrDeveloper(Context))
            {
                suggestedApps = suggestedApps?.Where(x => allApps.Any(y => x.Id == y.Id)).ToList();
            }

            var hasMyAppDic = suggestedApps.ToDictionary(x => x.Id, x => MasterLocator.ApplicationService.HasMyApps(x));
            var userInfo    = OAuthUserIdentityInfo.Create(Context.Login, Context.Role, Context.SchoolYearId, ChalkableAuthentication.GetSessionKey());
            var token       = MasterLocator.ApplicationService.GetAccessToken(miniQuizApp.Id, ChalkableAuthentication.GetSessionKey());

            return(Json(MiniQuizAppInfoViewData.Create(miniQuizApp, suggestedApps.Select(BaseApplicationViewData.Create).ToList(), allApps,
                                                       hasMyAppDic, Context.PersonId, token)));
        }
예제 #8
0
        private void SwitchToRole(CoreRole role)
        {
            var context = MasterLocator.UserService.SwitchToRole(role);

            ChalkableAuthentication.SignIn(context, false);
        }
예제 #9
0
 public ActionResult LogOutWithRedirect()
 {
     ChalkableAuthentication.SignOut();
     DeveloperAuthentication.SignOut();
     return(Redirect <HomeController>(x => x.Index()));
 }
예제 #10
0
 public ActionResult LogOut()
 {
     ChalkableAuthentication.SignOut();
     DeveloperAuthentication.SignOut();
     return(Json(new { success = true, data = new { success = true } }, JsonRequestBehavior.AllowGet));
 }
예제 #11
0
        public ActionResult SubmitAnnouncement(ClassAnnouncementInfo classAnnouncementInfo, IList <AssignedAttributeInputModel> attributes)
        {
            SchoolLocator.AnnouncementAssignedAttributeService.Edit(AnnouncementTypeEnum.Class, classAnnouncementInfo.AnnouncementId, attributes);
            var annDetails = SchoolLocator.ClassAnnouncementService.Edit(classAnnouncementInfo);

            SchoolLocator.ClassAnnouncementService.Submit(annDetails.Id);
            SchoolLocator.ClassAnnouncementService.DeleteAnnouncements(classAnnouncementInfo.ClassId, annDetails.ClassAnnouncementData.ClassAnnouncementTypeRef, AnnouncementState.Draft);
            var includeDiscussion = annDetails.DiscussionEnabled;

            ApplicationLogic.NotifyApplications(MasterLocator, annDetails.AnnouncementApplications, (int)AnnouncementTypeEnum.Class, ChalkableAuthentication.GetSessionKey(), NotifyAppType.Attach);
            TrackNewItemCreate(annDetails, (s, appsCount, doscCount) => s.CreatedNewItem(Context.Login, annDetails.ClassAnnouncementData.ClassAnnouncementTypeName, annDetails.ClassAnnouncementData.ClassName, appsCount, doscCount, includeDiscussion));
            return(Json(true, 5));
        }
        public ActionResult Submit(int supplementalAnnouncementPlanId, int classId, string title, string content, int?classAnnouncementTypeId,
                                   DateTime?expiresDate, bool hideFromStudents, IList <AssignedAttributeInputModel> attributes, IList <int> recipientsIds,
                                   bool discussionEnabled, bool previewCommentsEnabled, bool requireCommentsEnabled)
        {
            SchoolLocator.AnnouncementAssignedAttributeService.Edit(AnnouncementTypeEnum.Supplemental, supplementalAnnouncementPlanId, attributes);
            var ann = SchoolLocator.SupplementalAnnouncementService.Edit(supplementalAnnouncementPlanId, classId, classAnnouncementTypeId, title, content, expiresDate, !hideFromStudents, recipientsIds, discussionEnabled, previewCommentsEnabled, requireCommentsEnabled);

            SchoolLocator.SupplementalAnnouncementService.Submit(supplementalAnnouncementPlanId);
            var supplementalAnnouncement = SchoolLocator.SupplementalAnnouncementService.GetSupplementalAnnouncementById(supplementalAnnouncementPlanId);
            //TODO delete old drafts
            var studentsCount     = supplementalAnnouncement.Recipients.Count;
            var includeDiscussion = supplementalAnnouncement.DiscussionEnabled;

            ApplicationLogic.NotifyApplications(MasterLocator, ann.AnnouncementApplications, (int)AnnouncementTypeEnum.Supplemental, ChalkableAuthentication.GetSessionKey(), NotifyAppType.Attach);

            TrackNewItemCreate(ann, (s, appsCount, doscCount) => s.CreateNewSupplemental(Context.Login, supplementalAnnouncement.ClassName, studentsCount, appsCount, doscCount, includeDiscussion));
            return(Json(true, 5));
        }
예제 #13
0
        public ActionResult Submit(int adminAnnouncementId, string title, string content, DateTime?expiresDate, IList <AssignedAttributeInputModel> attributes)
        {
            Trace.Assert(Context.PersonId.HasValue);
            if (string.IsNullOrEmpty(title))
            {
                throw new ChalkableException(string.Format(ChlkResources.ERR_PARAM_IS_MISSING_TMP, "Announcement Title "));
            }

            SchoolLocator.AnnouncementAssignedAttributeService.Edit(AnnouncementTypeEnum.Admin, adminAnnouncementId, attributes);
            var ann = SchoolLocator.AdminAnnouncementService.Edit(adminAnnouncementId, title, content, expiresDate);

            SchoolLocator.AdminAnnouncementService.Submit(adminAnnouncementId);
            SchoolLocator.AdminAnnouncementService.DeleteDrafts(Context.PersonId.Value);
            ApplicationLogic.NotifyApplications(MasterLocator, ann.AnnouncementApplications, (int)AnnouncementTypeEnum.Admin, ChalkableAuthentication.GetSessionKey(), NotifyAppType.Attach);
            TrackNewItemCreate(ann, (s, appsCount, doscCount) => s.CreateNewAdminItem(Context.Login, ann.AdminAnnouncementData.AdminName, appsCount, doscCount));
            return(Json(true, 5));
        }
예제 #14
0
        public ActionResult Submit(int lessonPlanId, int?classId, string title, string content, int?lpGalleryCategoryId,
                                   DateTime?startDate, DateTime?endDate, bool hideFromStudents, bool inGallery, IList <AssignedAttributeInputModel> attributes
                                   , bool discussionEnabled, bool previewCommentsEnabled, bool requireCommentsEnabled)
        {
            if (Context.Role == CoreRoles.TEACHER_ROLE)
            {
                SchoolLocator.AnnouncementAssignedAttributeService.Edit(AnnouncementTypeEnum.LessonPlan, lessonPlanId, attributes);
                var ann = SchoolLocator.LessonPlanService.Edit(lessonPlanId, classId, lpGalleryCategoryId, title, content, startDate, endDate, !hideFromStudents, false, discussionEnabled, previewCommentsEnabled, requireCommentsEnabled);
                SchoolLocator.LessonPlanService.Submit(lessonPlanId);
                var lessonPlan = SchoolLocator.LessonPlanService.GetLessonPlanById(lessonPlanId);
                //TODO delete old drafts

                var includeDiscussion = lessonPlan.DiscussionEnabled;
                ApplicationLogic.NotifyApplications(MasterLocator, ann.AnnouncementApplications, (int)AnnouncementTypeEnum.LessonPlan, ChalkableAuthentication.GetSessionKey(), NotifyAppType.Attach);

                TrackNewItemCreate(ann, (s, appsCount, doscCount) => s.CreateNewLessonPlan(Context.Login, lessonPlan.ClassName, appsCount, doscCount, includeDiscussion));
            }

            if (inGallery)
            {
                var lpGalleryId = Context.Role == CoreRoles.DISTRICT_ADMIN_ROLE ? lessonPlanId : SchoolLocator.LessonPlanService.Create(null, startDate, endDate).LessonPlanData.Id;

                SchoolLocator.AnnouncementAssignedAttributeService.Edit(AnnouncementTypeEnum.LessonPlan, lpGalleryId, attributes);
                SchoolLocator.LessonPlanService.Edit(lpGalleryId, null, lpGalleryCategoryId, title + " Template", content, startDate, endDate, !hideFromStudents, true, discussionEnabled, previewCommentsEnabled, requireCommentsEnabled);
                SchoolLocator.LessonPlanService.Submit(lpGalleryId);

                if (Context.Role == CoreRoles.TEACHER_ROLE)
                {
                    SchoolLocator.LessonPlanService.CopyToGallery(lessonPlanId, lpGalleryId);
                    MasterLocator.UserTrackingService.SavedLessonPlanToGallery(Context.Login, title);
                }
            }


            return(Json(true, 5));
        }
예제 #15
0
        public ActionResult Attach(int announcementApplicationId, int announcementType)
        {
            SchoolLocator.ApplicationSchoolService.AttachAppToAnnouncement(announcementApplicationId, (AnnouncementTypeEnum)announcementType);
            var aa  = SchoolLocator.ApplicationSchoolService.GetAnnouncementApplication(announcementApplicationId);
            var res = PrepareFullAnnouncementViewData(aa.AnnouncementRef, (AnnouncementTypeEnum)announcementType);

            if (res.State == (int)AnnouncementState.Created)
            {
                ApplicationLogic.NotifyApplication(MasterLocator, aa.ApplicationRef, aa.Id, announcementType, ChalkableAuthentication.GetSessionKey(), NotifyAppType.Attach);
            }
            return(Json(res));
        }
예제 #16
0
        public static IList <BaseApplicationViewData> GetApplicationsWithContent(IServiceLocatorSchool schoolLocator, IServiceLocatorMaster masterLocator)
        {
            IList <Application> applications = masterLocator.ApplicationService.GetApplications(live: true);

            applications = applications.Where(x => x.ProvidesRecommendedContent).ToList();

            var res = BaseApplicationViewData.Create(applications);

            foreach (var app in res)
            {
                app.EncodedSecretKey = HashHelper.HexOfCumputedHash(applications.First(x => x.Id == app.Id).SecretKey);
                app.AccessToken      = masterLocator.ApplicationService.GetAccessToken(app.Id, ChalkableAuthentication.GetSessionKey());
            }

            return(res);
        }