Beispiel #1
0
		public ActionResult List(string namePrefix = null, string role = null)
		{
			IQueryable<ApplicationUser> applicationUsers = new ULearnDb().Users;
			if (!string.IsNullOrEmpty(namePrefix)) applicationUsers = applicationUsers.Where(u => u.UserName.StartsWith(namePrefix));
			if (!string.IsNullOrEmpty(role)) applicationUsers = applicationUsers.Where(u => u.Roles.Any(r => r.Role.Name == role));
			return View(applicationUsers.OrderBy(u => u.UserName).Take(50).ToList());
		}
Beispiel #2
0
		public AccountController()
			: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ULearnDb())))
		{
			db = new ULearnDb();
			courseManager = WebCourseManager.Instance;
			UserManager.UserValidator =
				new UserValidator<ApplicationUser>(UserManager)
				{
					AllowOnlyAlphanumericUserNames = false
				};
		}
Beispiel #3
0
		public AccountController()
			: this(new ULearnUserManager())
		{
			db = new ULearnDb();
			courseManager = WebCourseManager.Instance;
			usersRepo = new UsersRepo(db);
			userRolesRepo = new UserRolesRepo(db);
			groupsRepo = new GroupsRepo(db);
			certificatesRepo = new CertificatesRepo(db);
			visitsRepo = new VisitsRepo(db);
		}
		public static IAppBuilder UseLtiAuthentication(this IAppBuilder app)
		{
			app.UseLtiAuthentication(new LtiAuthenticationOptions
			{
				Provider = new LtiAuthenticationProvider
				{
					// Look up the secret for the consumer
					OnAuthenticate = async context =>
					{
						// Make sure the request is not being replayed
						var timeout = TimeSpan.FromMinutes(5);
						var oauthTimestampAbsolute = OAuthConstants.Epoch.AddSeconds(context.LtiRequest.Timestamp);
						if (DateTime.UtcNow - oauthTimestampAbsolute > timeout)
						{
							throw new LtiException("Expired " + OAuthConstants.TimestampParameter);
						}

						var db = new ULearnDb();
						var consumer = await db.Consumers.SingleOrDefaultAsync(c => c.Key == context.LtiRequest.ConsumerKey);
						if (consumer == null)
						{
							throw new LtiException("Invalid " + OAuthConstants.ConsumerKeyParameter + " " + context.LtiRequest.ConsumerKey);
						}

						/* Substitute http(s) scheme with real scheme from header */
						var uriBuilder = new UriBuilder(context.LtiRequest.Url)
						{
							Scheme = context.OwinContext.Request.GetRealRequestScheme(),
                            Port = context.OwinContext.Request.GetRealRequestPort()
						};
						context.LtiRequest.Url = uriBuilder.Uri;


						var signature = context.LtiRequest.GenerateSignature(consumer.Secret);
						if (!signature.Equals(context.LtiRequest.Signature))
						{
							throw new LtiException("Invalid " + OAuthConstants.SignatureParameter);
						}

						// If we made it this far the request is valid
					},

					// Sign in using application authentication. This handler will create a new application
					// user if no matching application user is found.
					OnAuthenticated = context => SecurityHandler.OnAuthenticated(context),

					// Generate a username using the LisPersonEmailPrimary from the LTI request
					OnGenerateUserName = context => SecurityHandler.OnGenerateUserName(context)
				},
				SignInAsAuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
			});

			return app;
		}
Beispiel #5
0
		public TextsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #6
0
		public SlideRateRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #7
0
 public AntiPlagiarismController(ULearnDb db, UserSolutionsRepo userSolutionsRepo, GroupsRepo groupsRepo)
 {
     this.db = db;
     this.userSolutionsRepo = userSolutionsRepo;
     this.groupsRepo        = groupsRepo;
 }
Beispiel #8
0
		public UnitsRepo(ULearnDb db, CourseManager courseManager)
		{
			this.db = db;
			this.courseManager = courseManager;
		}
//		private static IEnumerable<Tuple<string, string, string>> GetErrors(string compilationError)
//		{
//			var lines = compilationError.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
//			var regex = new Regex(@"\((\d+),\d+\):\s+(warning|error)\s+CS(\d{4})");
//			foreach (var line in lines)
//			{
//				var m = regex.Match(line);
//				if (!m.Success)
//					continue;
//				var lineNumber = m.Groups[1].Value;
//				var type = m.Groups[2].Value;
//				var code = m.Groups[3].Value;
//				yield return Tuple.Create(lineNumber, type, code);
//			}
//		}
//
//		private static string RemoveFileName(string str)
//		{
//			var pos = str.IndexOf('(');
//			return pos == -1 ? "" : str.Substring(pos);
//		}
//
//		private static int SecondIndexOf(string str, char pattern)
//		{
//			var pos = str.IndexOf(pattern);
//			if (pos == -1)
//				return 0;
//			pos = str.IndexOf(pattern, pos + 1);
//			return pos == -1 ? 0 : pos;
//		}

		private static IEnumerable<Solution> GetSources()
		{
			var slides = WebCourseManager.Instance
				.GetCourses()
				.SelectMany(course => course.Slides)
				.Where(slide => slide is ExerciseSlide)
				.Cast<ExerciseSlide>()
				.ToDictionary(slide => slide.Id);

			var db = new ULearnDb();
			var solutions = db.UserSolutions.ToList();
			return solutions.Select(solution => new Solution(slides[solution.SlideId], solution));
		}
Beispiel #10
0
		public CertificatesRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #11
0
		public RestoreRequestRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #12
0
		public UnitController()
		{
			db = new ULearnDb();
			courseManager = WebCourseManager.Instance;
			usersRepo = new UsersRepo(db);
		}
Beispiel #13
0
		public UnitController()
		{
			db = new ULearnDb();
			courseManager = WebCourseManager.Instance;
		}
Beispiel #14
0
		public CoursesRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #15
0
		public VisitsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #16
0
		public GroupsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #17
0
		public ConsumersRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #18
0
		public SlideHintRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #19
0
		public UserCourseModel(Course course, ApplicationUser user, ULearnDb db)
		{
			Course = course;
			User = user;

			var visits = db.Visits.Where(v => v.UserId == user.Id && v.CourseId == course.Id).GroupBy(v => v.SlideId).ToDictionary(g => g.Key, g => g.FirstOrDefault());
			var unitResults = new Dictionary<string, UserCourseUnitModel>();
			foreach (var slide in Course.Slides)
			{
				var unit = slide.Info.UnitName;
				if (!unitResults.ContainsKey(unit))
					unitResults.Add(unit, new UserCourseUnitModel
					{
						UnitName = unit,
						SlideVisits = new ProgressModel(),
						Exercises = new ProgressModel(),
						Quizes = new ProgressModel(),
						Total = new ProgressModel()
					});

				var res = unitResults[unit];
				var isVisited = visits.ContainsKey(slide.Id);
				var isPassed = isVisited && visits[slide.Id].IsPassed;
				var score = isPassed ? visits[slide.Id].Score : 0;

				res.SlideVisits.Total++;
				res.Total.Total += slide.MaxScore;
				res.Total.Earned += score;

				if (isVisited)
					res.SlideVisits.Earned++;

				if (slide is ExerciseSlide)
				{
					res.Exercises.Total += slide.MaxScore;
					res.Exercises.Earned += score;
				}

				if (slide is QuizSlide)
				{
					res.Quizes.Total += slide.MaxScore;
					res.Quizes.Earned += score;
				}
			}

			Units = course.GetUnits().Select(unitName => unitResults[unitName]).ToArray();
			Total = new UserCourseUnitModel
			{
				Total = new ProgressModel(),
				Exercises = new ProgressModel(),
				SlideVisits = new ProgressModel(),
				Quizes = new ProgressModel()
			};
			foreach (var result in Units)
			{
				Total.Total.Add(result.Total);
				Total.Exercises.Add(result.Exercises);
				Total.SlideVisits.Add(result.SlideVisits);
				Total.Quizes.Add(result.Quizes);
			}
		}
Beispiel #20
0
		public LtiRequestsRepo()
		{
			db = new ULearnDb();
			serializer = new JsonSerializer();
		}
Beispiel #21
0
 public AntiPlagiarismController(ULearnDb db, CourseManager courseManager)
     : this(db, new UserSolutionsRepo(db, courseManager), new GroupsRepo(db, courseManager))
 {
     this.courseManager = courseManager;
 }
Beispiel #22
0
		public UserSolutionsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #23
0
		public VisitsRepo(ULearnDb db)
		{
			this.db = db;
			this.slideCheckingsRepo = new SlideCheckingsRepo(db);
		}
Beispiel #24
0
		public UserQuizzesRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #25
0
		public UserQuestionsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #26
0
		public UserRolesRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #27
0
 public override void PreRemove(ULearnDb db)
 {
     db.Set <ExerciseCodeReview>().RemoveRange(Reviews);
 }
Beispiel #28
0
		public UsersRepo(ULearnDb db)
		{
			this.db = db;
			userRolesRepo = new UserRolesRepo(db);
		}
Beispiel #29
0
 public virtual void PreRemove(ULearnDb db)
 {
 }
Beispiel #30
0
		public CommentsRepo(ULearnDb db)
		{
			this.db = db;
		}
Beispiel #31
0
        public UserCourseModel(Course course, ApplicationUser user, ULearnDb db)
        {
            Course = course;
            User   = user;

            var visits      = db.Visits.Where(v => v.UserId == user.Id && v.CourseId == course.Id).GroupBy(v => v.SlideId).ToDictionary(g => g.Key, g => g.FirstOrDefault());
            var unitResults = new Dictionary <string, UserCourseUnitModel>();

            foreach (var slide in Course.Slides)
            {
                var unit = slide.Info.UnitName;
                if (!unitResults.ContainsKey(unit))
                {
                    unitResults.Add(unit, new UserCourseUnitModel
                    {
                        UnitName    = unit,
                        SlideVisits = new ProgressModel(),
                        Exercises   = new ProgressModel(),
                        Quizes      = new ProgressModel(),
                        Total       = new ProgressModel()
                    });
                }

                var res       = unitResults[unit];
                var isVisited = visits.ContainsKey(slide.Id);
                var isPassed  = isVisited && visits[slide.Id].IsPassed;
                var score     = isPassed ? visits[slide.Id].Score : 0;

                res.SlideVisits.Total++;
                res.Total.Total  += slide.MaxScore;
                res.Total.Earned += score;

                if (isVisited)
                {
                    res.SlideVisits.Earned++;
                }

                if (slide is ExerciseSlide)
                {
                    res.Exercises.Total  += slide.MaxScore;
                    res.Exercises.Earned += score;
                }

                if (slide is QuizSlide)
                {
                    res.Quizes.Total  += slide.MaxScore;
                    res.Quizes.Earned += score;
                }
            }

            Units = course.GetUnits().Select(unitName => unitResults[unitName]).ToArray();
            Total = new UserCourseUnitModel
            {
                Total       = new ProgressModel(),
                Exercises   = new ProgressModel(),
                SlideVisits = new ProgressModel(),
                Quizes      = new ProgressModel()
            };
            foreach (var result in Units)
            {
                Total.Total.Add(result.Total);
                Total.Exercises.Add(result.Exercises);
                Total.SlideVisits.Add(result.SlideVisits);
                Total.Quizes.Add(result.Quizes);
            }
        }