Esempio n. 1
0
        private static async Task CreateEmails(LLDbContext context)
        {
            if (!await context.EmailTemplates.AnyAsync(c => c.Key == "ResendVerification"))
            {
                await context.EmailTemplates.AddAsync(new EmailTemplate
                {
                    Key         = "ResendVerification",
                    Description = "Re-send verification email",
                    Created     = DateTime.Now,
                    Subject     = "Confirm email",
                    Body        = "Click this <a href=\"http://localhost:52812/api/register/confirmemail?userId={0}&code={1}\">link</a> mofo."
                });
            }
            if (!await context.EmailTemplates.AnyAsync(c => c.Key == "Register"))
            {
                await context.EmailTemplates.AddAsync(new EmailTemplate
                {
                    Key         = "Register",
                    Description = "Registration confirmation",
                    Created     = DateTime.Now,
                    Subject     = "Confirm email",
                    Body        = "Click this <a href=\"http://localhost:52812/api/register/confirmemail?userId={0}&code={1}\">link</a> mofo."
                });
            }

            await context.SaveChangesAsync();
        }
 public TokenProviderMiddleware(RequestDelegate next, IOptions <TokenProviderOptions> options, LLDbContext dataContext, ApplicationUserManager userManager)
 {
     _next        = next;
     _dataContext = dataContext;
     _userManager = userManager;
     _options     = options.Value;
 }
Esempio n. 3
0
        private static async Task CreateAgencies(LLDbContext context)
        {
            if (!await context.Agencies.AnyAsync(c => c.Name == "Entwhistle Green"))
            {
                var agency = new Agency
                {
                    Created = DateTime.Now,
                    Name    = "Entwhistle Green"
                };

                await context.Agencies.AddAsync(agency);

                await context.SaveChangesAsync();

                var user1 = await context.Users.FirstAsync(c => c.UserName == "*****@*****.**");

                var user2 = await context.Users.FirstAsync(c => c.UserName == "*****@*****.**");

                user1.AgencyId = agency.Id;
                user2.AgencyId = agency.Id;

                await context.SaveChangesAsync();

                var landlord1 = await context.Users.FirstAsync(c => c.UserName == "*****@*****.**");

                var portfolios = context.ApplicationUserPortfolios.Where(c => c.UserId == landlord1.Id);

                await portfolios.ForEachAsync(c => c.AgencyId = agency.Id);

                await context.SaveChangesAsync();

                var agencyPortfolio = new Portfolio
                {
                    Created     = DateTime.Now,
                    DisplayName = "Agency Portfolio",
                    Name        = "Agency-BBB445"
                };
                await context.Portfolios.AddAsync(agencyPortfolio);

                await context.SaveChangesAsync();

                var link = new ApplicationUserPortfolio
                {
                    Created     = DateTime.Now,
                    PortfolioId = agencyPortfolio.Id,
                    AgencyId    = agency.Id,
                    UserId      = user1.Id
                };
                await context.ApplicationUserPortfolios.AddAsync(link);

                await context.SaveChangesAsync();
            }
        }
Esempio n. 4
0
        //CONTENT ADMIN PAGES

        public ActionResult ContentIndex()
        {
            //Get a list of content to populate a drop down list.
            ApplicationDbContext memberContext = new ApplicationDbContext();
            LLDbContext          context       = new LLDbContext();
            ContentRepository    repo          = new ContentRepository();
            ContentViewModel     contentList   = new ContentViewModel()
            {
                ContentList = repo.Content.ToList <Content>()
            };

            return(View(contentList));
        }
Esempio n. 5
0
        public static void Seed(this LLDbContext context, IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetService <ApplicationRoleManager>();
            var userManager = serviceProvider.GetService <ApplicationUserManager>();

            CreatePermissions(context);
            AsyncHelpers.RunSync(() => CreateEmails(context));
            AsyncHelpers.RunSync(() => CreateRoles(context, roleManager));
            AsyncHelpers.RunSync(() => CreateTenants(context, userManager));
            AsyncHelpers.RunSync(() => CreateUsers(context, userManager));
            AsyncHelpers.RunSync(() => CreateAgencies(context));
            AsyncHelpers.RunSync(() => CreateChecklists(context, userManager));
        }
Esempio n. 6
0
        public ViewResult ProductInfo(Product formProduct)
        {
            ProductRepository repo = new ProductRepository();

            //After we get the information back from the form...
            if (ModelState.IsValid)
            {
                //...update the database with it.
                LLDbContext productDB       = new LLDbContext();
                Product     productToUpdate = productDB.Products.Find(formProduct.ProductID);
                if (productToUpdate != null)
                {
                    productToUpdate.Description = formProduct.Description;
                    productToUpdate.Category    = formProduct.Category;
                    productToUpdate.InStock     = formProduct.InStock;
                    productToUpdate.Price       = formProduct.Price;
                    productToUpdate.ProductName = formProduct.ProductName;
                    //productToUpdate.Shipping = formProduct.Shipping;
                    productDB.SaveChanges();

                    //This means that the user was editing the product, not creating a new one.
                    //In this case, we should try to retrieve the product with the same ID as the one passed in as a parameter.

                    return(View((from p in repo.Products
                                 where p.ProductID == formProduct.ProductID
                                 select p).FirstOrDefault <Product>()));
                }
                else
                {
                    Product newProduct = new Product();
                    newProduct.Description = formProduct.Description;
                    newProduct.Category    = formProduct.Category;
                    newProduct.InStock     = formProduct.InStock;
                    newProduct.Price       = formProduct.Price;
                    newProduct.ProductName = formProduct.ProductName;
                    productDB.Products.Add(newProduct);
                    productDB.SaveChanges();

                    //This means that the user is trying to create a new product.
                    //Because its ID will be auto-generated by the database, we should instead just pass
                    //the newProduct object to the view for now.

                    return(View(newProduct));
                }
            }

            else
            {
                return(View("ProductIndex"));
            }
        }
Esempio n. 7
0
 private static async Task CreateRoles(LLDbContext context, ApplicationRoleManager roleManager)
 {
     if (!await context.Roles.AnyAsync())
     {
         foreach (var role in ApplicationRoles.AllRoles)
         {
             await roleManager.CreateAsync(new ApplicationRole(role));
         }
     }
     if (!await context.Roles.AnyAsync(c => c.Name == ApplicationRoles.Tenant))
     {
         await roleManager.CreateAsync(new ApplicationRole(ApplicationRoles.Tenant));
     }
 }
Esempio n. 8
0
        private static void CreatePermissions(LLDbContext context)
        {
            typeof(PermissionAttribute).GetTypeInfo().Assembly
            .GetTypes()
            .SelectMany(c => c.GetMethods(BindingFlags.Instance | BindingFlags.Public))
            .Where(c => c.CustomAttributes.Any(d => d.AttributeType == typeof(PermissionAttribute)))
            .Select(c => c.GetCustomAttribute <PermissionAttribute>())
            .ToList()
            .ForEach(permissionAttribute =>
            {
                if (!context.Permissions.Any(c => c.Id == permissionAttribute.PermissionId))
                {
                    context.Permissions.Add(new Permission
                    {
                        Id          = permissionAttribute.PermissionId,
                        Description = permissionAttribute.Description,
                        RouteId     = permissionAttribute.RouteId
                    });
                }
            });

            context.SaveChanges();
        }
 public ChecklistInstanceDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
Esempio n. 10
0
 public BaseDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context)
 {
     HostingEnvironment = hostingEnvironment;
     Context            = context;
 }
Esempio n. 11
0
 public LandlordDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
Esempio n. 12
0
 public RegisterController(IUserRepository userRepository, IEmailSender emailSender, LLDbContext context)
 {
     _userRepository = userRepository;
     _emailSender    = emailSender;
     _context        = context;
 }
Esempio n. 13
0
 public MaintenanceRequestsDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
 public TransactionsDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
 public ConversationDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
 public NotificationsDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
 public PermissionsDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
Esempio n. 18
0
        private static async Task CreateTenants(LLDbContext context, ApplicationUserManager userManager)
        {
            if (!await context.Users.AnyAsync(c => c.Email == "*****@*****.**"))
            {
                var user = new ApplicationUser
                {
                    UserName             = "******",
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    FirstName            = "John",
                    MiddleName           = "Paul",
                    LastName             = "Tenant",
                    PhoneNumber          = "07955567790",
                    SecondaryPhoneNumber = "01925555555",
                    Title                = "Mr"
                };

                await userManager.CreateAsync(user, "Password123");

                await userManager.AddToRoleAsync(user, ApplicationRoles.Tenant);

                await userManager.SetUserPermissionsAsync(user.Id, DefaultPermissions.Tenant.Select(c => Guid.Parse(c)).ToArray());

                var tenant = new Tenant
                {
                    DateOfBirth             = DateTime.Parse("1987-07-27 00:00:00"),
                    Created                 = DateTime.Now,
                    AdditionalInformation   = "Additional",
                    DrivingLicenseReference = "Driving",
                    EmploymentType          = EmploymentTypes.SelfEmployed,
                    HasPets                 = true,
                    IsAdult                 = true,
                    IsLeadTenant            = true,
                    IsSmoker                = true,
                    Occupation              = "Web Developer",
                    PassportReference       = "Passport",
                    CompanyName             = "Jon Preece Development Ltd",
                    WorkAddress             = "Work address",
                    WorkContactNumber       = "Work Contact",
                    ApplicationUserId       = user.Id
                };

                tenant.Addresses = new List <TenantAddress>
                {
                    new TenantAddress
                    {
                        Tenant          = tenant,
                        Created         = DateTime.Now,
                        Country         = Countries.UnitedKingdom,
                        CountyOrRegion  = Counties.Cheshire,
                        MonthsAtAddress = 6,
                        Postcode        = "WA53SL",
                        Street          = "Bridgeport Mews",
                        TownOrCity      = "Warrington",
                        YearsAtAddress  = 3
                    }
                };

                tenant.Contacts = new List <TenantContact>
                {
                    new TenantContact
                    {
                        Name                   = "Contact",
                        Tenant                 = tenant,
                        Comments               = "Comments",
                        Created                = DateTime.Now,
                        MainContactNumber      = "07955555555",
                        Relationship           = "Manager",
                        SecondaryContactNumber = "09111111"
                    }
                };

                await context.Tenants.AddAsync(tenant);

                await context.SaveChangesAsync();
            }
        }
Esempio n. 19
0
        private static async Task CreateChecklists(LLDbContext context, ApplicationUserManager userManager)
        {
            var admin = await context.Users.FirstAsync(c => c.UserName == "*****@*****.**");

            if (!await context.Checklists.AnyAsync(c => c.Name == "New tenant move in"))
            {
                var moveInChecklist = new Checklist
                {
                    Created               = DateTime.Now,
                    Name                  = "New tenant move in",
                    Image                 = "checklist.png",
                    Description           = "For when a new tenant is moving into the property",
                    IsAvailableDownstream = true,
                    IsPropertyMandatory   = true,
                    UserId                = admin.Id
                };

                await context.Checklists.AddAsync(moveInChecklist);

                await context.SaveChangesAsync();

                var checklistItems = new List <ChecklistItem>
                {
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Determine rental amount",
                        IsExpanded  = true,
                        Key         = "NL001",
                        Order       = 1,
                        Template    = ChecklistTemplates.CommentsOnly
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Take photos (or get a professional to do it)",
                        Key         = "NL002",
                        Order       = 2,
                        Template    = ChecklistTemplates.DocumentUpload
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Advertise the property",
                        Key         = "NL003",
                        Order       = 3,
                        Template    = ChecklistTemplates.CommentsOnly
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Conduct viewings",
                        Key         = "NL004",
                        Order       = 4,
                        Template    = ChecklistTemplates.CommentsOnly
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Negotiate & accept offer",
                        Key         = "NL005",
                        Order       = 5,
                        Template    = ChecklistTemplates.CommentsOnly
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Take fees",
                        Key         = "NL006",
                        Order       = 6,
                        Template    = ChecklistTemplates.CommentsOnly
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Get proof of Id",
                        Key         = "NL007",
                        Order       = 7,
                        Template    = ChecklistTemplates.DocumentUpload
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Establish right to rent",
                        Key         = "NL008",
                        Order       = 8,
                        Template    = ChecklistTemplates.CommentsAndDateOfAction
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Conduct reference checks",
                        Key         = "NL009",
                        Order       = 9,
                        Template    = ChecklistTemplates.DateOfAction
                    },

                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveInChecklist.Id,
                        DisplayText = "Ask for a guarantor if necessary",
                        Key         = "NL010",
                        Order       = 10,
                        Template    = ChecklistTemplates.CommentsOnly
                    }
                };

                await context.ChecklistItems.AddRangeAsync(checklistItems);

                await context.SaveChangesAsync();
            }

            if (!await context.Checklists.AnyAsync(c => c.Name == "Move the tenants out"))
            {
                var moveOutChecklist = new Checklist
                {
                    Created               = DateTime.Now,
                    Name                  = "Move the tenants out",
                    Image                 = "checklist.png",
                    Description           = "For when a new tenant is moving out of the property",
                    IsAvailableDownstream = true,
                    IsPropertyMandatory   = false,
                    UserId                = admin.Id
                };

                await context.Checklists.AddAsync(moveOutChecklist);

                await context.SaveChangesAsync();

                var checklistItems = new List <ChecklistItem>
                {
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Before move out, make sure the tenants are clear on their responsibilities and what is expected in order for them to get their deposit back in full",
                        IsExpanded  = false,
                        Key         = "MO001",
                        Order       = 1,
                        Template    = ChecklistTemplates.CommentsOnly
                    },
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Conduct a checkout inspection",
                        IsExpanded  = false,
                        Key         = "MO002",
                        Order       = 2,
                        Template    = ChecklistTemplates.DateOfAction
                    },
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Take meter readings",
                        IsExpanded  = false,
                        Key         = "MO003",
                        Order       = 3,
                        Template    = ChecklistTemplates.CommentsAndDateOfAction
                    },
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Contact the utility companies with the meter readings, the tenant's forwarding address, and the details of the new occupant",
                        IsExpanded  = false,
                        Key         = "MO004",
                        Order       = 4,
                        Template    = ChecklistTemplates.CommentsAndDateOfAction
                    },
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Agree on how much (if any) of the deposit should be deducted",
                        IsExpanded  = false,
                        Key         = "MO005",
                        Order       = 5,
                        Template    = ChecklistTemplates.CommentsOnly
                    },
                    new ChecklistItem
                    {
                        Created     = DateTime.Now,
                        ChecklistId = moveOutChecklist.Id,
                        DisplayText = "Arrange the return of the deposit with the deposit protection scheme you've used",
                        IsExpanded  = false,
                        Key         = "MO006",
                        Order       = 6,
                        Template    = ChecklistTemplates.CommentsAndDateOfAction
                    }
                };

                await context.ChecklistItems.AddRangeAsync(checklistItems);

                await context.SaveChangesAsync();
            }

            if (!await context.Checklists.AnyAsync(c => c.Name == "Blank"))
            {
                var blankChecklist = new Checklist
                {
                    Created               = DateTime.Now,
                    Name                  = "Blank",
                    Image                 = "checklist.png",
                    Description           = "Blank checklist template",
                    IsAvailableDownstream = true,
                    IsPropertyMandatory   = false,
                    UserId                = admin.Id
                };

                await context.Checklists.AddAsync(blankChecklist);

                await context.SaveChangesAsync();
            }
        }
Esempio n. 20
0
 public PropertyImageDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
 public TenanciesDataProvider(ITenantsDataProvider tenantsDataProvider, IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
     _tenantsDataProvider = tenantsDataProvider;
 }
Esempio n. 22
0
 public UsersService(LLDbContext _llDbContext)
 {
     llDbContext = _llDbContext;
 }
Esempio n. 23
0
 public PropertyDataProvider(INotificationsDataProvider notificationsDataProvider, IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
     _notificationsDataProvider = notificationsDataProvider;
 }
 public SuppliersDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
Esempio n. 25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            #region 初始化配置
            //初始化配置
            services.Configure <LLSetting>(Configuration.GetSection("LLSetting"));
            services.Configure <JWTSetting>(Configuration.GetSection("JWTSetting"));
            services.Configure <ImagePathSetting>(Configuration.GetSection("ImagePathSetting"));
            #endregion


            #region ConfigureServices中读取配置
            string Issuer       = Configuration.GetSection("JWTSetting").GetSection("Issuer").Value;
            string CookieScheme = Configuration.GetSection("CookieSetting").GetSection("CookieScheme").Value;

            string Audience  = Configuration.GetSection("JWTSetting:Audience").Value;
            string SecretKey = Configuration.GetSection("JWTSetting:SecretKey").Value;
            #endregion

            #region Authentication cookie,JwtBearer 认证配置

            var jwtAuthorizationRequirement = new JwtAuthorizationRequirement();

            //添加认证Cookie信息
            services.AddAuthentication(CookieScheme) // Sets the default  to cookies
            .AddCookie(CookieScheme, options =>
            {
                options.AccessDeniedPath = "/Account/Denied";                                  //禁止访问路径:当用户试图访问资源时,但未通过该资源的任何授权策略,请求将被重定向到这个相对路径(没有权限跳转)。
                options.LoginPath        = System.Web.HttpUtility.UrlEncode("/Account/Index"); // 登录路径:这是当用户试图访问资源但未经过身份验证时,程序将会将请求重定向到这个相对路径。
                //options.SlidingExpiration = true;  //Cookie可以分为永久性的和临时性的。 临时性的是指只在当前浏览器进程里有效,浏览器一旦关闭就失效(被浏览器删除)。 永久性的是指Cookie指定了一个过期时间,在这个时间到达之前,此cookie一直有效(浏览器一直记录着此cookie的存在)。 slidingExpriation的作用是,指示浏览器把cookie作为永久性cookie存储,但是会自动更改过期时间,以使用户不会在登录后并一直活动,但是一段时间后却自动注销。也就是说,你10点登录了,服务器端设置的TimeOut为30分钟,如果slidingExpriation为false,那么10:30以后,你就必须重新登录。如果为true的话,你10:16分时打开了一个新页面,服务器就会通知浏览器,把过期时间修改为10:46。 更详细的说明还是参考MSDN的文档。
                options.Events = new CookieAuthenticationEvents()
                {
                    //覆写跳转到登陆页事件
                    OnRedirectToLogin = context =>
                    {
                        /*
                         * 由于  LoginPath 前台页面url 会被编码
                         * ps:覆写事件 对url进行转码
                         *
                         */
                        context.Response.Redirect(System.Uri.UnescapeDataString(context.RedirectUri));
                        return(System.Threading.Tasks.Task.FromResult(0));
                    }
                };
            });
            #region jwt


            #region Jwt默认
            //.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, jwtoptions =>
            //{
            //    jwtoptions.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            //    {

            //        //Token颁发机构
            //        ValidIssuer = "https://localhost:44303/",
            //        //颁发给谁
            //        ValidAudience = "https://localhost:44303/",
            //        //这里的key要进行加密,需要引用Microsoft.IdentityModel.Tokens
            //        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("LL_2AWopCMMgEIWt6KkzxEJD0EA4xreXLINaQIDAQABAoGAcUQIoKWyldZa8xnPDJTMKIV8GpeuzebKWvwp5dIu+miTdzmZX4weeHADRNb")),
            //        //验证token 有效期
            //        ValidateLifetime = true,
            //        //ValidateIssuer = true,
            //        //ValidateAudience = true,
            //        //ValidateIssuerSigningKey=true
            //        ///允许的服务器时间偏移量
            //        //ClockSkew = TimeSpan.Zero

            //    };
            //});
            #endregion

            #region Jwt自定义策略

            /*
             * 1.添加授权自定义策略 policy
             * 2.设置认证方式(cookie、bearer、openid)
             * 3.添加JWT认证机制
             */

            //1.添加授权自定义策略
            services.AddAuthorization(option =>
            {
                option.AddPolicy("LL_Jwt", policy =>
                {
                    //参数约束
                    policy.AddRequirements(jwtAuthorizationRequirement);
                });

                //2.设置认证方式(cookie、bearer、openid)
            }).AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(o =>
            {
                o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    //Token颁发机构
                    ValidIssuer = Issuer,
                    //颁发给谁
                    ValidAudience = Audience,
                    //这里的key要进行加密,需要引用Microsoft.IdentityModel.Tokens
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SecretKey)),
                    //验证token 有效期
                    ValidateLifetime = true,
                    //ValidateIssuer = true,
                    //ValidateAudience = true,
                    ValidateIssuerSigningKey = true
                                               ///允许的服务器时间偏移量
                                               //ClockSkew = TimeSpan.Zero
                };
            });


            #endregion

            #endregion


            #endregion

            #region  UEditor文本编辑器
            services.AddUEditorService(configFileRelativePath: "ueditor_config.json",
                                       isCacheConfig: false,
                                       basePath: "");
            #endregion

            #region 依赖注入 服务

            //注册EF上下文
            services.AddDbContext <LLDbContext>(options =>
            {
                options.UseSqlServer(
                    //数据是sql server 2008  开启 UseRowNumberForPaging
                    Configuration.GetConnectionString("LLDbContext"), b => b.UseRowNumberForPaging());
            });

            // Transient: 每一次GetService都会创建一个新的实例
            // Scoped:  在同一个Scope内只初始化一个实例 ,可以理解为( 每一个request级别只创建一个实例,同一个http request会在一个 scope内)
            // Singleton :整个应用程序生命周期以内只创建一个实例
            services.AddTransient <IUsersService, UsersService>();

            //jwt 自定义验证AuthorizationHandler时间
            services.AddSingleton <IAuthorizationHandler, JwtAuthorizationHandler>();
            #endregion

            #region 初始化数据
            //获取注册的服务
            ServiceProvider serviceProvider = services.BuildServiceProvider();
            LLDbContext     dbcontext       = serviceProvider.GetService <LLDbContext>();
            DataInitialize.DataInit(dbcontext);
            #endregion

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);



            #region 数据保护组件
            //.NETCore 数据保护组件
            services.AddDataProtection();
            #endregion
        }
Esempio n. 26
0
        private static async Task CreateUsers(LLDbContext context, ApplicationUserManager userManager)
        {
            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var administrator = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Admin",
                    LastName       = "Admin"
                };

                await userManager.CreateAsync(administrator, "Password123");

                await userManager.AddToRoleAsync(administrator, ApplicationRoles.SiteAdministrator);

                await userManager.SetUserPermissionsAsync(administrator.Id, DefaultPermissions.Administrator.Select(c => Guid.Parse(c)).ToArray());
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var landlord = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Jon",
                    LastName       = "Preece"
                };

                await userManager.CreateAsync(landlord, "Password123");

                await userManager.AddToRoleAsync(landlord, ApplicationRoles.Landlord);

                await userManager.SetUserPermissionsAsync(landlord.Id, DefaultPermissions.Landlord.Select(c => Guid.Parse(c)).ToArray());

                var portfolio = new Portfolio
                {
                    Created     = DateTime.Now,
                    DisplayName = "Jons Portfolio",
                    Name        = "JonPreece-ABC123"
                };
                await context.Portfolios.AddAsync(portfolio);

                await context.SaveChangesAsync();

                var link = new ApplicationUserPortfolio
                {
                    Created     = DateTime.Now,
                    PortfolioId = portfolio.Id,
                    UserId      = landlord.Id
                };
                await context.ApplicationUserPortfolios.AddAsync(link);

                await context.SaveChangesAsync();
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var landlord = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Land",
                    LastName       = "Lord"
                };

                await userManager.CreateAsync(landlord, "Password123");

                await userManager.AddToRoleAsync(landlord, ApplicationRoles.Landlord);

                await userManager.SetUserPermissionsAsync(landlord.Id, DefaultPermissions.Landlord.Select(c => Guid.Parse(c)).ToArray());

                var portfolio = new Portfolio
                {
                    Created     = DateTime.Now,
                    DisplayName = "Landlord Portfolio",
                    Name        = "LandLord-ASD432"
                };
                await context.Portfolios.AddAsync(portfolio);

                await context.SaveChangesAsync();

                var link = new ApplicationUserPortfolio
                {
                    Created     = DateTime.Now,
                    PortfolioId = portfolio.Id,
                    UserId      = landlord.Id
                };
                await context.ApplicationUserPortfolios.AddAsync(link);

                await context.SaveChangesAsync();
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var accountant = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Account",
                    LastName       = "Ant"
                };

                await userManager.CreateAsync(accountant, "Password123");

                await userManager.AddToRoleAsync(accountant, ApplicationRoles.Accountant);

                await userManager.SetUserPermissionsAsync(accountant.Id, DefaultPermissions.Accountant.Select(c => Guid.Parse(c)).ToArray());

                var portfolio = await context.Portfolios.FirstAsync(c => c.Name == "JonPreece-ABC123");

                var link = new ApplicationUserPortfolio
                {
                    Created     = DateTime.Now,
                    PortfolioId = portfolio.Id,
                    UserId      = accountant.Id
                };

                await context.ApplicationUserPortfolios.AddAsync(link);

                await context.SaveChangesAsync();
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var accountant = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Other",
                    LastName       = "User"
                };

                await userManager.CreateAsync(accountant, "Password123");

                await userManager.AddToRoleAsync(accountant, ApplicationRoles.OtherUser);

                await userManager.SetUserPermissionsAsync(accountant.Id, DefaultPermissions.OtherUser.Select(c => Guid.Parse(c)).ToArray());

                var portfolio = await context.Portfolios.FirstAsync(c => c.Name == "JonPreece-ABC123");

                var link = new ApplicationUserPortfolio
                {
                    Created     = DateTime.Now,
                    PortfolioId = portfolio.Id,
                    UserId      = accountant.Id
                };

                await context.ApplicationUserPortfolios.AddAsync(link);

                await context.SaveChangesAsync();
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var administrator = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Agency",
                    LastName       = "Administrator"
                };

                await userManager.CreateAsync(administrator, "Password123");

                await userManager.AddToRoleAsync(administrator, ApplicationRoles.AgencyAdministrator);

                await userManager.SetUserPermissionsAsync(administrator.Id, DefaultPermissions.AgencyAdministrator.Select(c => Guid.Parse(c)).ToArray());
            }

            if (!await userManager.Users.AnyAsync(c => c.UserName == "*****@*****.**"))
            {
                var accountant = new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Agency",
                    LastName       = "User"
                };

                await userManager.CreateAsync(accountant, "Password123");

                await userManager.AddToRoleAsync(accountant, ApplicationRoles.AgencyAdministrator);

                await userManager.SetUserPermissionsAsync(accountant.Id, DefaultPermissions.AgencyAdministrator.Select(c => Guid.Parse(c)).ToArray());
            }
        }
Esempio n. 27
0
 public FinancesDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }
Esempio n. 28
0
 public ShortlistedPropertiesDataProvider(IHostingEnvironment hostingEnvironment, LLDbContext context) : base(hostingEnvironment, context)
 {
 }