private UserContext DemoUserLogin(User user, UnitOfWork uow, int?schoolYearId = null) { if (user == null) { return(null); } if (!user.District.IsDemoDistrict) { throw new ChalkableException("This login is allowed to demo district only"); } Guid?developerId = null; var developer = new DeveloperDataAccess(uow).GetDeveloper(user.District.Id); if (developer != null) { developerId = developer.Id; } var schoolUser = user.SchoolUsers.First(); var schoolYear = DemoSchoolYearService.GetDemoSchoolYear(); int roleId; var personId = DemoPersonService.GetPersonDataForLogin(schoolUser.User, out roleId); var res = new UserContext(user, CoreRoles.GetById(roleId), user.District, schoolUser.School, developerId, personId, null, schoolYear) { Claims = ClaimInfo.Create(DemoUserService.GetDemoClaims()) }; return(res); }
private UserContext SisUserLogin(User user, UnitOfWork uow, ConnectorLocator iNowConnector = null , StiConnector.Connectors.Model.User iNowUser = null, int?schoolYearId = null, string sisRedirectUrl = null) { if (user == null) { return(null); } if (user.SisUserId.HasValue) { try { SaveSisToken(user, uow, ref iNowConnector); } catch (HttpException) { return(null); } Trace.Assert(user.DistrictRef.HasValue); var schoolL = ServiceLocator.SchoolServiceLocator(user.DistrictRef.Value, null); Data.School.Model.SchoolYear schoolYear; SchoolUser schoolUser; var userAcadSessionsIds = iNowConnector.UsersConnector.GetUserAcadSessionsIds(); if (userAcadSessionsIds.Length == 0) { throw new ChalkableException("Current user does not have access to any of school acadSessions"); } if (!schoolYearId.HasValue && userAcadSessionsIds.Length == 1) { schoolYearId = userAcadSessionsIds[0]; } PrepareSchoolData(schoolL, user, schoolYearId, userAcadSessionsIds, out schoolYear, out schoolUser); if (!schoolUser.School.IsChalkableEnabled) { return(null); } if (iNowUser == null) { iNowUser = iNowConnector.UsersConnector.GetMe(); } int roleId; int personId = PersonDataAccess.GetPersonDataForLogin(user.District.ServerUrl, user.DistrictRef.Value, user.SisUserId.Value, out roleId); var claimInfos = ClaimInfo.Create(iNowUser.Claims); if (roleId == CoreRoles.TEACHER_ROLE.Id) { EnsureTeacherChalkableAccess(claimInfos); } #if DEBUG var loginTimeOut = (int?)null; #else var loginTimeOut = schoolL.AppSettingService.GetLoginTimeOut(); #endif var res = new UserContext(user, CoreRoles.GetById(roleId), user.District, schoolUser.School, null, personId, loginTimeOut, schoolYear, sisRedirectUrl) { Claims = ClaimInfo.Create(iNowUser.Claims), SisApiVersion = iNowConnector.ApiVersion }; return(res); } throw new UnknownRoleException(); }