예제 #1
0
        public static void CreateUser(WebmailContext context, User user)
        {
            var entity = new Database.POCO.User()
            {
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Role      = user.Role
            };

            context.Users.Add(entity);
            context.SaveChanges();
        }
예제 #2
0
        public static Group CreateGroup(WebmailContext context, string name, Database.POCO.User admin,
                                        List <Database.POCO.User> members = null)
        {
            var group = new Database.POCO.Group()
            {
                Name  = name,
                Admin = admin,
                Users = members ?? new List <Database.POCO.User>()
            };

            context.Groups.Add(group);
            context.SaveChanges();
            return(CreateGroup(group));
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebmailContext webmailContext)
        {
            webmailContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.Use(async(context, next) =>
            {
                context.Request.EnableBuffering();
                await next();
            });

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseAuditMiddleware(_ => _
                                   .WithEventType("{verb}:{url}")
                                   .IncludeHeaders()
                                   .IncludeResponseHeaders()
                                   .IncludeRequestBody()
                                   .IncludeResponseBody());

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Webmail");
            });
        }
예제 #4
0
        public static Database.POCO.User CreateUser(WebmailContext context, string email, Role role = Role.USER,
                                                    string firstName = "Mariusz", string lastName = "Tester")
        {
            var entity = new Database.POCO.User()
            {
                Email     = email,
                FirstName = firstName,
                LastName  = lastName,
                Role      = role
            };

            context.Users.Add(entity);
            context.SaveChanges();
            return(entity);
        }
예제 #5
0
        public static Database.POCO.User CreateTestUser(WebmailContext context, Role role = Role.USER,
                                                        string email = "*****@*****.**")
        {
            var user = new Database.POCO.User()
            {
                Email     = email,
                FirstName = "Mariusz",
                LastName  = "Tester",
                Role      = role
            };

            context.Users.Add(user);
            context.SaveChanges();
            return(user);
        }
예제 #6
0
        public static void CreateNotification(WebmailContext context, Notification notification, NotificationType type)
        {
            var notificationEntity = new Database.POCO.Notification()
            {
                Content         = notification.Content,
                ContentType     = notification.ContentType,
                CreationTime    = DateTime.Now,
                RecipientsList  = context.Users.Where(u => notification.RecipientsList.Contains(u.Email)).ToList(),
                Type            = type,
                WithAttachments = notification.WithAttachments
            };

            context.Notifications.Add(notificationEntity);
            context.SaveChanges();
        }
예제 #7
0
        public static void CreateNotification(WebmailContext context, Notification notification,
                                              DateTime?creationTime = null, NotificationType type = NotificationType.API)
        {
            var time = creationTime ?? DateTime.Now;

            var entity = new Database.POCO.Notification()
            {
                Content         = notification.Content,
                ContentType     = notification.ContentType,
                WithAttachments = notification.WithAttachments,
                Type            = type,
                CreationTime    = time
            };

            context.Notifications.Add(entity);
            context.SaveChanges();
        }
예제 #8
0
        public static Database.POCO.Message CreateMessage(WebmailContext context, string subject, string content,
                                                          Database.POCO.User sender, List <Database.POCO.User> receivers, List <Database.POCO.User> cc,
                                                          List <Database.POCO.User> bcc, DateTime?receivedTime = null)
        {
            var message = new Database.POCO.Message()
            {
                Sender       = sender,
                Subject      = subject,
                MessageBody  = content,
                Attachments  = new List <Database.POCO.Attachment>(),
                ReceivedTime = receivedTime ?? DateTime.Now
            };

            message.MessagesReceivers = receivers.Select(mr => new MessagesReceivers()
            {
                User    = mr,
                Message = message,
                IsRead  = false
            }).ToList();

            message.MessagesCCs = cc.Select(mc => new MessagesCCs()
            {
                User    = mc,
                Message = message,
                IsRead  = false
            }).ToList();

            message.MessagesBCCs = bcc.Select(mb => new MessagesBCCs()
            {
                User    = mb,
                Message = message,
                IsRead  = false
            }).ToList();

            message = context.Messages.Add(message).Entity;
            context.SaveChanges();
            return(message);
        }
 public HomeController(WebmailContext _context)
 {
     this.Context = _context;
 }
예제 #10
0
        public static Database.POCO.User AuthorizeControllerUser(ControllerBase controller, WebmailContext context,
                                                                 Role role = Role.USER)
        {
            var testUser = CreateTestUser(context, role);
            var claims   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("emails", testUser.Email),
            }, "mock"));

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = claims
                }
            };

            return(testUser);
        }
예제 #11
0
 public SqlGroupService(WebmailContext context)
 {
     this.context = context;
 }
예제 #12
0
 public SqlUserService(WebmailContext context, IMessageService messageService)
 {
     this.context        = context;
     this.messageService = messageService;
 }
예제 #13
0
 public SqlMessageService(WebmailContext context)
 {
     this.context = context;
 }
예제 #14
0
 public SqlNotificationService(WebmailContext context)
 {
     this.context = context;
 }
예제 #15
0
 public SqlAttachmentService(WebmailContext context)
 {
     this.context = context;
 }