Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="environment"></param>
 /// <param name="formOptions"></param>
 public ArtifactController(APIDatabaseContext context, IHostingEnvironment environment, IOptions <FormOptions> formOptions)
 {
     _defaultFormOptions = formOptions.Value;
     _context            = context;
     _environment        = environment;
     _storagePath        = Path.Combine(_environment.ContentRootPath, "storage", "artifacts");
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_context"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static LoginToken GetLoginToken(this APIDatabaseContext _context, string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(default(LoginToken));
            }

            return(_context.GetFullTable <LoginToken>().SingleOrDefault(t => t.Token == token));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="authenticationService"></param>
        public AccountController(APIDatabaseContext context, IAuthenticationService authenticationService)
        {
            _context = context;
            _authenticationService = authenticationService;
#if DEMO
            _tokenLifespanInMinutes = 1440;
#else
            _tokenLifespanInMinutes = 30;
#endif
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_context"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static bool IsTokenValid(this APIDatabaseContext _context, string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(false);
            }

            var loginToken = _context.Tokens.SingleOrDefault(t => t.Token == token);

            return(loginToken != null && loginToken.Valid > DateTime.Now);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="_context"></param>
        /// <returns></returns>
        public static IQueryable <T> GetFullTable <T>(this APIDatabaseContext _context)
        {
            Type genericTableType = typeof(T);

            switch (genericTableType.Name)
            {
            case "Lecture":
                return((IQueryable <T>)_context.Lectures
                       .Include(l => l.Contents)
                       .ThenInclude(p => p.Dependencies)
                       .Include(l => l.StorageItems)
                       .ThenInclude(lsi => lsi.LectureRef)
                       .Include(l => l.UserLectures)
                       .ThenInclude(ul => ul.User));

            case "Package":
                return((IQueryable <T>)_context.Packages.Include(p => p.Dependencies));

            case "Artifact":
                return((IQueryable <T>)_context.Artifacts
                       .Include(a => a.StorageItems)
                       .ThenInclude(asi => asi.ArtifactRef)
                       .Include(a => a.Backups)
                       .ThenInclude(ab => ab.StorageItems)
                       .ThenInclude(absi => absi.ArtifactBackupRef)
                       .ThenInclude(ab => ab.ArtifactRef));

            case "ApplicationUser":
                return((IQueryable <T>)_context.Users
                       .Include(u => u.UserLectures)
                       .ThenInclude(ul => ul.Lecture));

            case "LoginToken":
                return((IQueryable <T>)_context.Tokens
                       .Include(lt => lt.User)
                       .ThenInclude(user => user.UserLectures)
                       .ThenInclude(ul => ul.Lecture));

            default:
                return(default(IQueryable <T>));
            }
        }
Beispiel #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public PackageController(APIDatabaseContext context)
 {
     _context = context;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="environment"></param>
 public LectureController(APIDatabaseContext context, IHostingEnvironment environment)
 {
     _context     = context;
     _environment = environment;
     _storagePath = Path.Combine(_environment.ContentRootPath, "storage", "lectures");
 }
Beispiel #8
0
        /// <summary>
        /// Service-Configuration called by .NetCore Runtime
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAntiforgery(options =>
            {
                options.Cookie.Name         = "_af";
                options.Cookie.HttpOnly     = true;
                options.Cookie.SecurePolicy = Microsoft.AspNetCore.Http.CookieSecurePolicy.Always;
                options.HeaderName          = "X-XSRF-TOKEN";
            });

            services.AddMvc();
            services.Configure <FormOptions>(config =>
            {
                config.ValueLengthLimit             = int.MaxValue;
                config.MultipartBodyLengthLimit     = uint.MaxValue;
                config.MultipartBoundaryLengthLimit = int.MaxValue;
            });

            services.Configure <LdapConfig>(Configuration.GetSection("ldap_auth"));

            var context = new APIDatabaseContext();

            /*if (Environment.IsDevelopment())
             *  context.Database.EnsureDeleted();*/

            context.Database.EnsureCreated();
            context.SaveChanges();

            services.AddCors(options => options.AddPolicy("Automatic", builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
            services.AddSingleton(Environment);

#if !DEMO
            LdapConfig conf = new LdapConfig();
            Configuration.Bind("ldap_auth", conf);

            services.AddScoped <IAuthenticationService>((service) => new LdapAuthenticationService(conf));
#else
            services.AddScoped <IAuthenticationService>((a) => new SimpleAuthenticationService());
#endif

            var signatureSection = Configuration.GetSection("SignatureService");
            var certFile         = "";
            var certFilePassword = "";
            var signatureEnabled = false;

            if (signatureSection != null)
            {
                signatureEnabled = signatureSection.GetValue("Enabled", false);
                certFile         = signatureSection.GetValue("Certificate", string.Empty);
                certFilePassword = signatureSection.GetValue("Password", string.Empty);

                services.AddSingleton <ISignatureService>((service) =>
                {
                    var rsaSignatureService = new RSASignatureService(signatureEnabled);
                    rsaSignatureService.LoadCertificate(certFile, certFilePassword);
                    return(rsaSignatureService);
                });
            }

            services.AddRouting(/*options => options.LowercaseUrls = true*/);
            services.AddDbContext <APIDatabaseContext>(ServiceLifetime.Scoped);

            /*
             * services.AddSwaggerGen(config =>
             * {
             *  config.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Project API", Version = "v1" });
             *  config.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "ProjectAPI.xml"));
             * });*/
        }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public RecipeController(APIDatabaseContext context)
 {
     _context = context;
 }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="_context"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static T GetSingleOrDefault <T>(this APIDatabaseContext _context, Func <T, bool> predicate)
        {
            var queryable = _context.GetFullTable <T>();

            return(queryable != default(IQueryable <T>) ? queryable.SingleOrDefault(predicate) : default(T));
        }