public async Task <IActionResult> Add(AddJanitraBotViewModel bot) { if (ModelState.IsValid) { string accessKey = SecureRandomStringGenerator.Generate(); var janitraBot = new JanitraBot { AccessKey = CryptoHelper.Crypto.HashPassword(accessKey), AddedByUser = _currentUser.User, HardwareDetails = bot.HardwareDetails, Name = bot.Name, Os = bot.Os, RunsHwTests = User.IsInRole("Developer") ? bot.RunsHwTests : false }; await _context.JanitraBots.AddAsync(janitraBot); await _context.SaveChangesAsync(); return(View("AccessKey", new JanitraBotAccessKeyViewModel { JanitraBotId = janitraBot.JanitraBotId, AccessKey = accessKey })); } return(View(bot)); }
/// <summary> /// Begin an OAuth authentication with github /// </summary> public async Task <IActionResult> Github() { var state = SecureRandomStringGenerator.Generate(); await _cache.SetAsync("github:state:" + state, new byte[0], new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5) }); return(Redirect("https://github.com/login/oauth/authorize?client_id=" + _options.Value.GithubClientId + "&state=" + state)); }
public async Task <IActionResult> ResetAccessKey(ResetAccessKeyViewModel reset) { var bot = await _context.JanitraBots.SingleOrDefaultAsync(b => b.JanitraBotId == reset.JanitraBotId && b.AddedByUserId == _currentUser.User.UserId); //User doesn't own this bot, or bot doesn't exist if (bot == null) { return(Forbid()); } string accessKey = SecureRandomStringGenerator.Generate(); bot.AccessKey = CryptoHelper.Crypto.HashPassword(accessKey); await _context.SaveChangesAsync(); return(View("AccessKey", new JanitraBotAccessKeyViewModel { JanitraBotId = reset.JanitraBotId, AccessKey = accessKey })); }