public async Task <ActionResult <UserDadosDto> > GetByHumanCode(UserDadosDto dto) { try { var myUsername = User.Identity.Name; if (ZZApiMain.VerifyUserAuthorize(myUsername)) { if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn)) { var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.GetById, EntityId = dto.Id, Tela = Tela, Json = await SerializerAsync.SerializeJson(dto) }); var responseCommand = await myConn.Zz.GetApiWaitCommand(myId); if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk)) { return(await SerializerAsync.DeserializeJson <UserDadosDto>(responseCommand.Json)); } } } return(NotFound()); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <long> > SaveAddress(EnderecoDto dto) { try { var myUsername = User.Identity.Name; if (ZZApiMain.VerifyUserAuthorize(myUsername)) { if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn)) { var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.SaveAddress, Json = await SerializerAsync.SerializeJson(dto) }); var responseCommand = await myConn.Zz.GetApiWaitCommand(myId); if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk)) { return(responseCommand.EntityId); } } } return(-1); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <bool> > Delete(TipoSiglaDto dto) { try { var myUsername = User.Identity.Name; if (ZZApiMain.VerifyUserAuthorize(myUsername)) { if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn)) { var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Tela = Tela, Cmd = ServerCommands.Disable, EntityId = dto.Id, Json = await SerializerAsync.SerializeJson(dto) }); var responseCommand = await myConn.Zz.GetApiWaitCommand(myId); if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk)) { return(true); } } } return(false); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <IEnumerable <TipoSiglaDto> > > GetAll() { try { var myUsername = User.Identity.Name; if (ZZApiMain.VerifyUserAuthorize(myUsername)) { if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn)) { var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Tela = Tela, Cmd = ServerCommands.GetAll }); var responseCommand = await myConn.Zz.GetApiWaitCommand(myId); if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk)) { return(await SerializerAsync.DeserializeJsonList <TipoSiglaDto>(responseCommand.Json)); } } } return(NotFound()); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public void ReturnServer(Object[] server, Object[] local) { var dataJson = SerializerAsync.DeserializeJson <Command>(server[0].ToString()).Result; try { if (dataJson != null) { if (!dataJson.Cmd.Equals(ServerCommands.Exit)) { if (dataJson.Cmd.Equals(ServerCommands.LogResultOk)) { ConsoleEx.WriteLine("Uhulll, consegui logar"); _expirationTimer = ZZApiMain.SetTimer( (LoginResultDto.ExpirationDate - LoginResultDto.CreatedDate).TotalMilliseconds, ExpirationTokenTimer); } else if (dataJson.Cmd.Equals(ServerCommands.LogResultDeny)) { ConsoleEx.WriteLine("Algo deu errado"); ZZApiMain.RemoveUserConnection(LoginResultDto.Username); } } } } catch (Exception e) { Console.WriteLine(e); throw; } }
private void ExpirationTokenTimer(Object source, ElapsedEventArgs e) { Zz.WriteServer(new Command { Cmd = ServerCommands.Logout, Json = SerializerAsync.SerializeJson("Token expired").Result }); ZZApiMain.RemoveUserConnection(LoginResultDto.Username); }
public async Task <ActionResult <bool> > CreateScreenClaims(string roleName, string nomeTela) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { var success = await _roleManager.AddRoleClaim(roleName, nomeTela, ServerCommands.Create); success = success && await _roleManager.AddRoleClaim(roleName, nomeTela, ServerCommands.Read); success = success && await _roleManager.AddRoleClaim(roleName, nomeTela, ServerCommands.Update); success = success && await _roleManager.AddRoleClaim(roleName, nomeTela, ServerCommands.Delete); return(success); } return(false); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
static void Main(string[] args) { var timestamp = DateTime.Now.ToString("ddMMyyyyHHmmssfff"); ConsoleEx.WriteLine("===================================="); ConsoleEx.WriteLine("===================================="); ConsoleEx.WriteLine("|||||||||||Welcome to Adam||||||||||"); ConsoleEx.WriteLine("===================================="); ConsoleEx.WriteLine("===================================="); ConsoleEx.WriteLine("Time : " + timestamp); _dataThread = new Thread(ZZApkMain.Run); _dataThread.Start(); Thread.Sleep(250); ZZApiMain.CreateWebHostBuilder(args).Build(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); Console.ReadKey(); }
public async Task <ActionResult <bool> > Logout() { try { await ZZApiMain.RemoveUserConnection(this.User.Identity.Name); return(true); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public void Delete(string username) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { _manager.DeleteUser(username); } } catch (Exception e) { ConsoleEx.WriteError(e); } }
public async Task <ActionResult <LoginResultDto> > Login(LoginDto dto) { try { var resultDto = await _authentication.Authenticate(dto.Username, dto.Password); await ZZApiMain.AddUserConnection(resultDto); return(resultDto); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <MatrizRolePermission> > GetRoleClaims(string roleName) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { return(await _roleManager.GetRolePermissions(roleName)); } return(null); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <bool> > CreateClaim(string roleName, string nomeTela, string tipoPermissao) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { return(await _roleManager.AddRoleClaim(roleName, nomeTela, tipoPermissao)); } return(false); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <bool> > Create(string roleName) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { return(await _roleManager.CreateAsync(roleName)); } return(false); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public ActionResult <IEnumerable <string> > GetAll() { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { var users = _roleManager.ListAll(); var dtos = users.Select(u => u.Name); return(new ActionResult <IEnumerable <string> >(dtos)); } return(null); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public async Task <ActionResult <bool> > Create(UserDto dto) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { if (await _manager.CreateAsync(dto.Username, dto.Email, dto.Password, dto.Role)) { return(true); } } return(false); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public ActionResult <List <UserDto> > GetAll() { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { var users = _manager.ListAll(); var dtos = users.Select(u => new UserDto { Id = u.Id, Email = u.Email, Username = u.UserName }).ToList(); return(new List <UserDto>(dtos)); } return(null); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public ActionResult <IEnumerable <UserDto> > GetByEmail(string email) { try { if (ZZApiMain.VerifyUserAuthorize(User.Identity.Name)) { var users = _manager.GetUserByEmail(email); var dtos = users.Select(u => new UserDto { Id = u.Id, Email = u.Email, Username = u.UserName }); return(new ActionResult <IEnumerable <UserDto> >(dtos)); } return(null); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }