public TokenVO ValidateCredentials(ClientVO userCredentials) { var user = _repository.ValidateCredentials(userCredentials); if (user == null) { return(null); } var claims = new List <Claim> { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")), new Claim(JwtRegisteredClaimNames.UniqueName, user.SecretClient) }; var accessToken = _tokenService.GenerateAccessToken(claims); var refreshToken = _tokenService.GenerateRefreshToken(); user.RefreshToken = refreshToken; user.RefreshTokenExpiryTime = DateTime.Now.AddDays(_configuration.DaysToExpiry); _repository.RefreshUserInfo(user); DateTime createDate = DateTime.Now; DateTime expirationDate = createDate.AddMinutes(_configuration.Minutes); return(new TokenVO( true, createDate.ToString(DATE_FORMAT), expirationDate.ToString(DATE_FORMAT), accessToken, refreshToken )); }
public object FindByLogin(ClientVO client) { bool credentialsIsValid = false; if (client != null && !string.IsNullOrWhiteSpace(client.UserName)) { var baseUser = _service.ValidateCredentials(client.UserName); credentialsIsValid = (baseUser != null && client.UserName == baseUser.SecretClient && client.Password == baseUser.SecretKey); } if (credentialsIsValid) { ClaimsIdentity identity = new ClaimsIdentity( new GenericIdentity(client.UserName, "Login"), new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")), new Claim(JwtRegisteredClaimNames.UniqueName, client.UserName) } ); DateTime createDate = DateTime.Now; DateTime expirationDate = createDate + TimeSpan.FromMinutes(_tokenConfigurations.Minutes); var handler = new JwtSecurityTokenHandler(); string token = CreateToken(identity, createDate, expirationDate, handler); return(SuccessObject(createDate, expirationDate, token)); } else { return(ExceptionObject()); } }
public ClientVO Update(ClientVO client) { var clientEntity = _converter.Parse(client); clientEntity = _repository.Update(clientEntity); return(_converter.Parse(clientEntity)); }
public ClientVO UpdateClient(ClientVO clientVO) { Client client = convert.Convert(clientVO); client = _repository.Update(client); clientVO = convert.Convert(client); return(clientVO); }
public ClientVO Created(ClientVO clientVO) { Client client = convert.Convert(clientVO); client = _repository.Created(client); clientVO = convert.Convert(client); return(clientVO); }
public IActionResult Put([FromBody] ClientVO client) { if (client == null) { return(BadRequest()); } return(Ok(_clientBusiness.Update(client))); }
public ClientVO GetClient(long id) { Client client = _repository.GetClient(id); ClientVO clientVO = convert.Convert(client); List <DeviceVO> devices = _deviceBusiness.GetDevicesClient(id); clientVO.NumberOfDevices = devices.Count; return(clientVO); }
public FormAdmin() { InitializeComponent(); _clientDAO = new ClientDAO(); _bankAccDAO = new BankAccountDAO(); _tranzDAO = new TranzactionsDAO(); _clientVO = new ClientVO(); _accountVO = new BankAccountsVO(); _listTranzVO = new List <TranzactionsVO>(); _listBankAccVO = new List <BankAccountsVO>(); _bankBUS = new BankAccountsBUS(); _tranzBUS = new TranzactionsBUS(); }
public ClientVO getClientById(int _id) { ClientVO clientVO = new ClientVO(); DataTable dataTable = new DataTable(); dataTable = _clientDAO.searchByID(_id); foreach (DataRow dr in dataTable.Rows) { clientVO.name = dr["Name"].ToString(); clientVO.address = dr["Address"].ToString(); clientVO.cnp = dr["Cnp"].ToString(); clientVO.email = dr["Email"].ToString(); clientVO.phone = dr["Phone"].ToString(); clientVO.pNumCode = dr["PersNumCode"].ToString(); } return(clientVO); }
//Insert public bool insertClient(ClientVO _clientVO) { string _query = "insert into dbo.clients(Name,Cnp,PersNumCode,Address,Phone,Email) values(@name,@cnp,@persnumcode,@address,@phone,@email)"; SqlParameter[] sqlParameters = new SqlParameter[6]; sqlParameters[0] = new SqlParameter("@name", SqlDbType.VarChar); sqlParameters[0].Value = Convert.ToString(_clientVO.name); sqlParameters[1] = new SqlParameter("@cnp", SqlDbType.VarChar); sqlParameters[1].Value = Convert.ToString(_clientVO.cnp); sqlParameters[2] = new SqlParameter("@persnumcode", SqlDbType.VarChar); sqlParameters[2].Value = Convert.ToString(_clientVO.pNumCode); sqlParameters[3] = new SqlParameter("@address", SqlDbType.VarChar); sqlParameters[3].Value = Convert.ToString(_clientVO.address); sqlParameters[4] = new SqlParameter("@phone", SqlDbType.VarChar); sqlParameters[4].Value = Convert.ToString(_clientVO.phone); sqlParameters[5] = new SqlParameter("@email", SqlDbType.VarChar); sqlParameters[5].Value = Convert.ToString(_clientVO.email); return(conn.executeInsertQuery(_query, sqlParameters)); }
public IActionResult Signin([FromBody] ClientVO client) { if (client == null) { return(BadRequest("Invalid client request")); } if (!string.IsNullOrWhiteSpace(client.UserName) && !string.IsNullOrWhiteSpace(client.Password)) { var token = _loginBusiness.ValidateCredentials(client); if (token == null) { return(Unauthorized("Unauthorized client request")); } return(Ok(token)); } else { return(BadRequest("Invalid client request")); } }
//Update By Id public bool updateByIdClient(ClientVO _clientVO) { string _query = "update dbo.clients set name = @name, cnp=@cnp, persnumcode = @persnumcode, address = @address,phone = @phone,email = @email where idClient=@idClient"; SqlParameter[] sqlParameters = new SqlParameter[7]; sqlParameters[0] = new SqlParameter("@idClient", SqlDbType.Int); sqlParameters[0].Value = Convert.ToInt32(_clientVO.idClient); sqlParameters[1] = new SqlParameter("@name", SqlDbType.VarChar); sqlParameters[1].Value = Convert.ToString(_clientVO.name); sqlParameters[2] = new SqlParameter("@cnp", SqlDbType.VarChar); sqlParameters[2].Value = Convert.ToString(_clientVO.cnp); sqlParameters[3] = new SqlParameter("@persnumcode", SqlDbType.VarChar); sqlParameters[3].Value = Convert.ToString(_clientVO.pNumCode); sqlParameters[4] = new SqlParameter("@address", SqlDbType.VarChar); sqlParameters[4].Value = Convert.ToString(_clientVO.address); sqlParameters[5] = new SqlParameter("@phone", SqlDbType.VarChar); sqlParameters[5].Value = Convert.ToString(_clientVO.phone); sqlParameters[6] = new SqlParameter("@email", SqlDbType.VarChar); sqlParameters[6].Value = Convert.ToString(_clientVO.email); return(conn.executeUpdateQuery(_query, sqlParameters)); }
public IActionResult UpdateClient([FromBody] ClientVO client) { return(Ok(_bussines.UpdateClient(client))); }
public IActionResult CreatedClient([FromBody] ClientVO client) { return(Ok(_bussines.Created(client))); }
public Client ValidateCredentials(ClientVO client) { var pass = ComputeHash(client.Password, new SHA256CryptoServiceProvider()); return(_mySQLContext.Clients.FirstOrDefault(c => ((c.SecretClient == client.UserName) && (c.SecretKey == pass)))); }
public ClientDAO() { conn = new Connection(); _clientVO = new ClientVO(); }