public async Task <AuthKeyResult> GenKey(AuthKeyOptions options, HandshakeMethod method) { var ret = await _typeHandlers[options.Type][options.Format].GenerateKey(method); ret.Public.Value = ret.Public.Value.Replace("\r", ""); if (string.IsNullOrWhiteSpace(ret.Public.FingerPrint)) { ret.Public.FingerPrint = ComputeFingerPrint(ret.Public, FingerPrintType.MD5); } await _db.PublicKeys.AddAsync(ret.Public); await _db.SaveChangesAsync(); ret.Private.PublicKeyId = ret.Public.Id; throw new Exception(); //await _db.PrivateKeys.AddAsync(ret.Private); await _db.SaveChangesAsync(); return(new AuthKeyResult() { Keys = ret, Error = AuthKeyError.None, }); }
public async Task <IActionResult> GenAuthKey(AuthKeyOptions AuthKey) { ViewData["Controller"] = "Account"; ViewData["Action"] = nameof(GenAuthKey); var user = await GetCurrentLocalUserAsync(); var result = await _auth.GenKey(AuthKey, HandshakeMethod.Default); switch (result.Error) { case AuthKeyError.None: { result = await _auth.TryAddUserKey(result.Keys.Public, user); switch (result.Error) { case AuthKeyError.None: return(RedirectToAction(nameof(AuthKeys))); case AuthKeyError.InvalidFormat: ModelState.AddModelError("PublicKey", "Invalid format"); break; } } break; case AuthKeyError.InvalidFormat: ModelState.AddModelError("PublicKey", "Invalid format"); break; } return(View(nameof(AuthKeys), new AuthKeysViewModel() { MyProfile = await _publicProfiles.Transform(user, 0, user.Id), NewKey = new AddKeyViewModel() { AuthKey = AuthKey }, })); }