public static List <AppsContainer> GetOneComputerData(string hostname) { var appsContainers = new List <AppsContainer>(); using (var db = new ApplicationContext()) { var computerId = GetComputerId(hostname); if (computerId == 0) { return(appsContainers); } var computer = db.Computers.Where(cc => cc.Id == computerId).ToList().FirstOrDefault(); var appsContainer = new AppsContainer { hostname = computer.Name, date = long.Parse(computer.UpdTime) }; var programs = db.Programs.Where(p => p.IdC == computer.Id).ToList(); foreach (var pr in programs) { var app = new App(pr.Name, pr.Version); appsContainer.apps.Add(app); } appsContainers.Add(appsContainer); } return(appsContainers); }
public async Task <CreateChannelViewModel> Init() { var token = AppsContainer.AccessToken(); var channel = await ChannelService.CreateChannelAsync(await token(), ""); return(channel); }
public AuthController( ServiceLocation serviceLocation, IConfiguration configuration, IHostingEnvironment env, AuthService <KahlaUser> authService, OAuthService oauthService, UserManager <KahlaUser> userManager, SignInManager <KahlaUser> signInManager, UserService userService, AppsContainer appsContainer, KahlaPushService pusher, ChannelService channelService, VersionChecker version, KahlaDbContext dbContext, IMemoryCache cache) { _serviceLocation = serviceLocation; _configuration = configuration; _env = env; _authService = authService; _oauthService = oauthService; _userManager = userManager; _signInManager = signInManager; _userService = userService; _appsContainer = appsContainer; _pusher = pusher; _channelService = channelService; _version = version; _dbContext = dbContext; _cache = cache; }
public ApiController( UserManager <KahlaUser> userManager, SignInManager <KahlaUser> signInManager, KahlaDbContext dbContext, PushKahlaMessageService pushService, IConfiguration configuration, AuthService <KahlaUser> authService, ServiceLocation serviceLocation, OAuthService oauthService, ChannelService channelService, StorageService storageService, AppsContainer appsContainer, UserService userService) { _userManager = userManager; _signInManager = signInManager; _dbContext = dbContext; _pusher = pushService; _configuration = configuration; _authService = authService; _serviceLocation = serviceLocation; _oauthService = oauthService; _channelService = channelService; _storageService = storageService; _appsContainer = appsContainer; _userService = userService; }
public AiurUploader( AppsContainer appsContainer, TokenService tokenService) { _appsContainer = appsContainer; _tokenService = tokenService; }
public async Task <IActionResult> DeleteApp(DeleteAppViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.Recover(cuser, 1); return(View(model)); } var target = await _dbContext.Apps.FindAsync(model.AppId); if (target == null) { return(NotFound()); } else if (target.CreaterId != cuser.Id) { return(new UnauthorizedResult()); } await ApiService.DeleteAppAsync(await AppsContainer.AccessToken(target.AppId, target.AppSecret)(), target.AppId); _dbContext.Apps.Remove(target); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(AllApps))); }
private static List <App> GetDifference(List <App> apps) { var result = new List <App>(); if (!File.Exists(_config.CacheFileName)) { return(apps); } var cachedApps = AppsContainer.FromBytes(File.ReadAllBytes(_config.CacheFileName)).apps; foreach (var app in apps) { var cachedApp = cachedApps.Find(a => a.name == app.name); if (cachedApp != null) { cachedApps.Remove(cachedApp); if (app.version == cachedApp.version) { continue; } app.status = AppStatus.Updated; } result.Add(app); } cachedApps.ForEach(app => app.status = AppStatus.Deleted); result.AddRange(cachedApps); return(result); }
public AuthController( ServiceLocation serviceLocation, IConfiguration configuration, IHostingEnvironment env, AuthService <ApplicationUser> authService, OAuthService oauthService, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, UserService userService, AppsContainer appsContainer, ChatPushService pusher, ChannelService channelService, VersionChecker version, ApplicationDbContext dbContext, ThirdPartyPushService thirdPartyPushService) { _serviceLocation = serviceLocation; _configuration = configuration; _env = env; _authService = authService; _oauthService = oauthService; _userManager = userManager; _signInManager = signInManager; _userService = userService; _appsContainer = appsContainer; _pusher = pusher; _channelService = channelService; _version = version; _dbContext = dbContext; _thirdPartyPushService = thirdPartyPushService; }
private static void SaveToCache(AppsContainer container) { var formatter = new BinaryFormatter(); using (var fs = new FileStream(_config.CacheFileName, FileMode.OpenOrCreate)) formatter.Serialize(fs, container); }
public AuthController( ServiceLocation serviceLocation, IWebHostEnvironment env, AuthService <KahlaUser> authService, UserManager <KahlaUser> userManager, SignInManager <KahlaUser> signInManager, UserService userService, AppsContainer appsContainer, KahlaPushService pusher, ChannelService channelService, VersionChecker version, KahlaDbContext dbContext, IOptions <List <DomainSettings> > optionsAccessor, AiurCache cache) { _serviceLocation = serviceLocation; _env = env; _authService = authService; _userManager = userManager; _signInManager = signInManager; _userService = userService; _appsContainer = appsContainer; _pusher = pusher; _channelService = channelService; _version = version; _dbContext = dbContext; _cache = cache; _appDomains = optionsAccessor.Value; }
public AuthController( StargateLocator serviceLocation, AuthService <KahlaUser> authService, UserManager <KahlaUser> userManager, SignInManager <KahlaUser> signInManager, UserService userService, AppsContainer appsContainer, KahlaPushService pusher, ChannelService channelService, KahlaDbContext dbContext, IOptions <List <DomainSettings> > optionsAccessor, EventService eventService, OnlineJudger onlineJudger, StargatePushService stargatePushService) { _stargateLocator = serviceLocation; _authService = authService; _userManager = userManager; _signInManager = signInManager; _userService = userService; _appsContainer = appsContainer; _pusher = pusher; _channelService = channelService; _dbContext = dbContext; _eventService = eventService; _onlineJudger = onlineJudger; _stargatePushService = stargatePushService; _appDomains = optionsAccessor.Value; }
public WebSocketPusher( AppsContainer appsContainer, EventService eventService) { _appsContainer = appsContainer; _eventService = eventService; }
public async Task <IActionResult> CreateBucket([FromForm] CreateBucketViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(this, cuser); return(View(model)); } var app = await _dbContext.Apps.FindAsync(model.AppId); if (app == null) { return(NotFound()); } try { var token = AppsContainer.AccessToken(app.AppId, app.AppSecret); var result = await ApiService.CreateBucketAsync(await token(), model.NewBucketName, model.OpenToRead, model.OpenToUpload); return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true })); } catch (AiurUnexceptedResponse e) { ModelState.AddModelError(string.Empty, e.Response.message); model.ModelStateValid = false; model.Recover(this, cuser); return(View(model)); } }
public async Task <IActionResult> EditBucket(EditBucketViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(cuser, 1); return(View(model)); } try { var app = await _dbContext.Apps.FindAsync(model.AppId); var token = AppsContainer.AccessToken(app.AppId, app.AppSecret); var bucket = await ApiService.ViewBucketDetailAsync(model.BucketId); if (bucket.BelongingAppId != app.AppId || app.CreaterId != cuser.Id) { return(Unauthorized()); } await ApiService.EditBucketAsync(await token(), model.BucketId, model.NewBucketName, model.OpenToRead, model.OpenToUpload); return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = model.AppId, JustHaveUpdated = true })); } catch (AiurUnexceptedResponse e) { ModelState.AddModelError(string.Empty, e.Response.message); model.ModelStateValid = false; model.Recover(cuser, 1); return(View(model)); } }
public async Task <IActionResult> DeleteFile(DeleteFileViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.Recover(cuser, 3); return(View(model)); } var fileinfo = await ApiService.ViewOneFileAsync(model.FileId); var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId); var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId); if (fileinfo == null || bucketInfo.BelongingAppId != app.AppId || fileinfo.File.BucketId != bucketInfo.BucketId) { return(Unauthorized()); } await ApiService.DeleteFileAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), model.FileId, bucketInfo.BucketId); return(RedirectToAction(nameof(ViewFiles), new { id = bucketInfo.BucketId })); }
public DebugApiController( UserManager <KahlaUser> userManager, SignInManager <KahlaUser> signInManager, KahlaDbContext dbContext, PushKahlaMessageService pushService, IConfiguration configuration, AuthService <KahlaUser> authService, ServiceLocation serviceLocation, OAuthService oauthService, ChannelService channelService, StorageService storageService, AppsContainer appsContainer, UserService userService) : base( userManager, signInManager, dbContext, pushService, configuration, authService, serviceLocation, oauthService, channelService, storageService, appsContainer, userService) { }
public AppsController( UserManager <DeveloperUser> userManager, SignInManager <DeveloperUser> signInManager, ILoggerFactory loggerFactory, DeveloperDbContext dbContext, ServiceLocation serviceLocation, StorageService storageService, OSSApiService ossApiService, AppsContainer appsContainer, CoreApiService coreApiService, IConfiguration configuration, SitesService siteService) { _userManager = userManager; _signInManager = signInManager; _logger = loggerFactory.CreateLogger <AppsController>(); _dbContext = dbContext; _serviceLocation = serviceLocation; _storageService = storageService; _ossApiService = ossApiService; _appsContainer = appsContainer; _coreApiService = coreApiService; _configuration = configuration; _siteService = siteService; }
public async Task Recover( DeveloperUser user, DeveloperApp appInDb, CoreApiService coreApiService, AppsContainer appsContainer, SitesService sitesService, EventService eventService, ChannelService channelService, RecordsService recordsService, int pageNumber) { RootRecover(user); var token = await appsContainer.AccessToken(appInDb.AppId, appInDb.AppSecret); Grants = await coreApiService.AllUserGrantedAsync(token, pageNumber, 15); var sites = await sitesService.ViewMySitesAsync(token); Sites = sites.Sites; var errorLogs = await eventService.ViewAsync(token); ErrorLogs = errorLogs.Logs; var channels = await channelService.ViewMyChannelsAsync(token); Channels = channels.Channels; var records = await recordsService.ViewMyRecordsAsync(token, Array.Empty <string>()); Records = records.Records; Trusted = appInDb.TrustedApp; }
public async Task <IActionResult> GenerateLink(int id) { var cuser = await GetCurrentUserAsync(); var fileinfo = await ApiService.ViewOneFileAsync(id); if (fileinfo.File == null) { return(NotFound()); } var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId); var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId); if (bucketInfo.BelongingAppId != app.AppId) { return(Unauthorized()); } var secret = await SecretService.GenerateAsync(id, await AppsContainer.AccessToken(app.AppId, app.AppSecret)()); var model = new GenerateLinkViewModel(cuser) { Address = secret.Value, BucketId = bucketInfo.BucketId }; return(View(model)); }
public async Task <IActionResult> ViewFiles(int id)//Bucket Id { var cuser = await GetCurrentUserAsync(); var bucketInfo = await ApiService.ViewBucketDetailAsync(id); if (bucketInfo.BelongingAppId == null) { return(NotFound()); } var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId); var files = await ApiService.ViewAllFilesAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), id); var model = new ViewFilesViewModel(cuser) { BucketId = files.BucketId, AllFiles = files.AllFiles, AppId = app.AppId, OpenToRead = bucketInfo.OpenToRead, BucketName = bucketInfo.BucketName }; return(View(model)); }
public async Task <IActionResult> EnterCode(EnterCodeViewModel model) { var user = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.Recover(user); model.ModelStateValid = ModelState.IsValid; return(View(model)); } var correctToken = await _userManager.VerifyChangePhoneNumberTokenAsync(user, model.Code, model.NewPhoneNumber); if (correctToken) { var result = await UserService.SetPhoneNumberAsync(user.Id, await AppsContainer.AccessToken()(), model.NewPhoneNumber); if (result.Code == ErrorType.Success) { user.PhoneNumber = model.NewPhoneNumber; await _userManager.UpdateAsync(user); return(RedirectToAction(nameof(Phone), new { JustHaveUpdated = true })); } throw new InvalidOperationException(); } else { model.ModelStateValid = false; model.Recover(user); ModelState.AddModelError("", "Your token is invalid!"); return(View(model)); } }
public async Task Recover( DeveloperUser user, App thisApp, CoreApiService coreApiService, AppsContainer appsContainer, SitesService sitesService, EventService eventService, ChannelService channelService, int pageNumber) { RootRecover(user); var token = await appsContainer.AccessToken(thisApp.AppId, thisApp.AppSecret); Grants = await coreApiService.AllUserGrantedAsync(token, pageNumber, 15); var sites = await sitesService.ViewMySitesAsync(token); Sites = sites.Sites; var errorLogs = await eventService.ViewAsync(token); ErrorLogs = errorLogs.Logs; var channels = await channelService.ViewMyChannelsAsync(token); Channels = channels.Channels; }
public BucketController( DeveloperDbContext dbContext, AppsContainer appsContainer, OSSApiService ossApiService) { _dbContext = dbContext; _appsContainer = appsContainer; _ossApiService = ossApiService; }
public KahlaPushService( AppsContainer appsContainer, ChannelService channelService, CannonService cannonService) { _appsContainer = appsContainer; _channelService = channelService; _cannonService = cannonService; }
public EmailNotifier( ILogger <EmailNotifier> logger, IServiceScopeFactory scopeFactory, AppsContainer appsContainer) { _logger = logger; _scopeFactory = scopeFactory; _appsContainer = appsContainer; }
public DashboardController( AppsContainer appsContainer, RecordsService recordsService, UserManager <WrapUser> userManager) { _appsContainer = appsContainer; _recordsService = recordsService; _userManager = userManager; }
public RecordsController( DeveloperDbContext dbContext, AppsContainer appsContainer, RecordsService recordsService) { _dbContext = dbContext; _appsContainer = appsContainer; _recordsService = recordsService; }
public KahlaPushService( AppsContainer appsContainer, CannonService cannonService, EventService eventService) { _appsContainer = appsContainer; _cannonService = cannonService; _eventService = eventService; }
public APIFriendlyServerExceptionMiddleware( RequestDelegate next, ILogger <APIFriendlyServerExceptionMiddleware> logger, AppsContainer appsContainer, EventService eventService) { _next = next; _logger = logger; _appsContainer = appsContainer; _eventService = eventService; }
public FilesCleaner( ILogger <FilesCleaner> logger, IServiceScopeFactory scopeFactory, AppsContainer appsContainer, IConfiguration configuration) { _logger = logger; _scopeFactory = scopeFactory; _appsContainer = appsContainer; _configuration = configuration; }