public async Task <bool> Handle(LoginRequest message, IOutputPort <LoginResponce> outputPort) { if (!string.IsNullOrEmpty(message.UserName) || !string.IsNullOrEmpty(message.Password)) { var user = await _userReposytory.FindByName(message.UserName); if (user != null) { if (await _userReposytory.CheckPassword(user, message.Password)) { var jwtToken = await _jwtFactory.GenerateEncodedToken(user.IdentityId, message.UserName); var refreshToken = _tokenFactory.GenerateToken(); user.AddRefreshToken(refreshToken, user.Id, message.RemoteIpAddress); await _userReposytory.Update(user); outputPort.Handle(new LoginResponce(jwtToken, refreshToken, true)); return(true); } } } outputPort.Handle(new LoginResponce(new[] { new Error("login_failure", "Wrong Username of Password") })); return(false); }
public async Task <bool> Handle(PublickKeyRequest message, IOutputPort <PublickKeyResponce> outputPort) { var userId = _userReposytory.FindByName(message.UserName).Id; bool result = await _publickKeyReposytory.Create(userId, message.KeyValue); if (result) { outputPort.Handle(new PublickKeyResponce(true, "Publick key added succesfuly")); return(true); } outputPort.Handle(new PublickKeyResponce(false, "Error whilr adding publick key")); return(false); }