Пример #1
0
 public GraphQLController(
     ConscienceGraphQueryExecuter executer,
     IUsersIdentityService usersService)
 {
     _executer     = executer;
     _usersService = usersService;
 }
Пример #2
0
        private static async Task <ConscienceAccount> CreateOrUpdateAccount(IUsersIdentityService identityService, ConscienceContext context, string name, string password, string role)
        {
            var account = context.Accounts.FirstOrDefault(a => a.UserName.ToLower() == name.ToLower());

            if (account == null)
            {
                account = new ConscienceAccount
                {
                    UserName     = name,
                    PasswordHash = "AA+JyvawjlityY0fyaRSr1qZkCgaIvU+bqTe6uShANUqcoG0EH2F6BcXq7hwnN7N1Q=="
                };
                var roleName = Enum.GetNames(typeof(RoleTypes)).First(r => r.ToLowerInvariant() == role.ToLowerInvariant());
                account.Roles.Add(new Role
                {
                    Name = roleName
                });
                context.Accounts.Add(account);
                context.SaveChanges();
            }

            account.PictureUrl = "/Content/images/uploaded/" + account.Id + ".jpg?_ts=101";
            context.SaveChanges();

            await identityService.ChangePasswordAsync(account.Id, password);

            return(account);
        }
Пример #3
0
        public PlotQuery(PlotRepository plotRepo, IUsersIdentityService accountService)
        {
            Name = "PlotQuery";

            Field <ListGraphType <PlotGraphType> >("all",
                                                   arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                   resolve: context => plotRepo.GetAll()
                                                   .ApplyPaginationAndOrderBy(context)
                                                   .ToList().Where(p => !accountService.CurrentUser.UserName.Contains("-") || p.Characters.Any(c => c.Character.Hosts.Any(h => h.Host.Account.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First())))) //TODO: Remove this line, only to send both runs pre game
                                                   );

            Field <PlotGraphType>("byId",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "plot id"
            }
                                      ),
                                  resolve: context => plotRepo.GetById(context.GetArgument <int>("id")));
        }
Пример #4
0
        public EmployeeQuery(EmployeeRepository employeeRepo, IUsersIdentityService accountService)
        {
            Name = "EmployeeQuery";

            Field <ListGraphType <EmployeeGraphType> >("all",
                                                       arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                       resolve: context => employeeRepo.GetAllEmployees()
                                                       .ApplyPaginationAndOrderBy(context)
                                                       .AvoidLazyLoad(context, e => e.Account, e => e.Notifications)
                                                       .ToList().Where(e => !accountService.CurrentUser.UserName.Contains("-") || e.Account.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First())) //TODO: Remove this line, only to send both runs pre game
                                                       )
            .AddQAPermissions();

            Field <EmployeeGraphType>("byId",
                                      arguments: new QueryArguments(
                                          new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "host id"
            }
                                          ),
                                      resolve: context => employeeRepo.GetById(context.GetArgument <int>("id")))
            .AddBehaviourAndPlotPermissions();
        }
Пример #5
0
        public HostQuery(HostRepository hostRepo, IUsersIdentityService accountService)
        {
            Name = "HostQuery";

            Field <ListGraphType <HostGraphType> >("all",
                                                   arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                   resolve: context => hostRepo.GetAllHosts(accountService.CurrentUser)
                                                   .ApplyPaginationAndOrderBy(context)
                                                   .AvoidLazyLoad(context, h => h.Account, h => h.Notifications, h => h.Characters, h => h.CoreMemory1, h => h.CoreMemory2, h => h.CoreMemory3, h => h.Account, h => h.Account.Device)
                                                   .ToList().Where(h => !accountService.CurrentUser.UserName.Contains("-") || h.Account.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First())) //TODO: Remove this line, only to send both runs pre game
                                                   )
            .AddBehaviourAndPlotPermissions();

            Field <HostGraphType>("byId",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "host id"
            }
                                      ),
                                  resolve: context => hostRepo.GetById(accountService.CurrentUser, context.GetArgument <int>("id")))
            .AddBehaviourAndPlotPermissions();
        }
Пример #6
0
        public AccountQuery(AccountRepository accountRepo, IUsersIdentityService accountService)
        {
            Name = "AccountQuery";

            Field <ListGraphType <AccountGraphType> >("all",
                                                      arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                      resolve: context => accountRepo.GetAll()
                                                      .ApplyPaginationAndOrderBy(context)
                                                      .AvoidLazyLoad(context, a => a.Host, a => a.Employee, a => a.Device)
                                                      .ToList().Where(a => !accountService.CurrentUser.UserName.Contains("-") || a.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First())) //TODO: Remove this line, only to send both runs pre game
                                                      );

            Field <AccountGraphType>("current",
                                     arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                     resolve: context => accountService.CurrentUser).CurrentUserQuery();

            Field <AccountGraphType>("byId",
                                     arguments: new QueryArguments(
                                         new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "account id"
            }
                                         ),
                                     resolve: context => accountRepo.GetById(context.GetArgument <int>("id")));
        }
Пример #7
0
 public ErrorsController(
     IUsersIdentityService usersService)
 {
     _usersService = usersService;
 }
Пример #8
0
 public NotificationsController(
     IUsersIdentityService usersService, AccountRepository accountsRepo)
 {
     _usersService = usersService;
     _accountsRepo = accountsRepo;
 }
Пример #9
0
 public PictureUploadController(IUsersIdentityService usersService, AccountRepository accountsRepo)
 {
     _usersService = usersService;
     _accountsRepo = accountsRepo;
 }
Пример #10
0
        public AccountMutation(IUsersIdentityService accountService, AccountRepository accountRepo)
        {
            Name = "AccountMutation";

            Field <AccountGraphType>("addAccount",
                                     arguments: new QueryArguments(
                                         new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userName", Description = "user name"
            },
                                         new QueryArgument <StringGraphType> {
                Name = "email", Description = "email"
            },
                                         new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password", Description = "password"
            }
                                         ),
                                     resolve: context => accountService.RegisterAsync(context.GetArgument <string>("userName"), context.GetArgument <string>("email"), context.GetArgument <string>("password")))
            .AddPermission(RoleTypes.Admin).RequiresMembership();

            Field <AccountGraphType>("addRole",
                                     arguments: new QueryArguments(
                                         new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "accountId", Description = "account id"
            },
                                         new QueryArgument <NonNullGraphType <RoleEnumeration> > {
                Name = "role", Description = "role"
            }
                                         ),
                                     resolve: context => accountRepo.AddRole(context.GetArgument <int>("accountId"), context.GetArgument <RoleTypes>("role")))
            .AddPermission(RoleTypes.Admin).RequiresMembership();

            Field <AccountGraphType>("changePassword",
                                     arguments: new QueryArguments(
                                         new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "accountId", Description = "account id"
            },
                                         new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password", Description = "password"
            }
                                         ),
                                     resolve: context =>
            {
                accountService.ChangePasswordAsync(context.GetArgument <int>("accountId"), context.GetArgument <string>("password")).Wait();
                return(accountRepo.GetById(context.GetArgument <int>("accountId")));
            })
            .AddPermission(RoleTypes.Admin).RequiresMembership();

            Field <AccountGraphType>("login",
                                     arguments: new QueryArguments(
                                         new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userName", Description = "user name"
            },
                                         new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password", Description = "password"
            }
                                         ),
                                     resolve: context => accountService.LoginAsync(context.GetArgument <string>("userName"), context.GetArgument <string>("password"))).CurrentUserQuery();

            Field <AccountGraphType>("logout",
                                     resolve: context => { accountService.LogoffAsync(); return(null); }).RequiresMembership();
        }