Explore all
Check out all of the posts from our 25+ communities.
6 posts
2 years ago
How to make Angular reactive forms?

I am having a problem setting up reactive angular forms i keep getting errors in my html and ts file. I have tried to import formgroup and form control into my component but it seems they are not there. What further steps do i need to take to get this working. Angular documents have me confused.


Html:

<div class="container">
  <form action="">
    <form formGroup="form" (ngSubmit)="onSubmit()">


      <label for="first-name">First Name: </label>
      <input id="first-name" type="text" formControlName="firstName">


      <label for="last-name">Last Name: </label>
      <input id="last-name" type="text" formControlName="lastName">


      <label for="last-name">Email: </label>
      <input id="last-name" type="email" formControlName="email">


      <button type="submit">Submit</button>
    </form>
  </form>
</div>

Ts:

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';


@Component({
  selector: 'app-hoem',
  templateUrl: './hoem.component.html',
  styleUrls: ['./hoem.component.css']
})
export class HoemComponent implements OnInit {


  constructor() { }
  form:any;
  ngOnInit(): void {
    this.form = new FormGroup({
      firstName: new FormControl(''),
      lastName: new FormControl(''),
      email: new FormControl('')
    })


    onSubmit(){
      console.log(this.form.value)
    }
}

App Module:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HoemComponent } from './hoem/hoem.component';


@NgModule({
  declarations: [
    AppComponent,
    HoemComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }


Does anyone know what the problem is here ? any feedback would be much appreciated and I thank you in advance!

2 years ago
When trying to write a user to the database I am getting errors in my console?

When trying to write a new user to the mongo db i am getting an error when trying to save them to the database i have logged the incoming requests to the console and they all are working properly. If someone could take a look at my code and see what the problem is that would be awesome! Thanks in advance!


app.js

const express = require("express");
const cors = require ("cors");
const passport = require("passport");
const bodyParser = require("body-parser");
const  mongoose  = require("mongoose");
const User = require('./models/user');






var app = express();
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cors());
app.use(passport.initialize());
mongoose.connect(process.env.MONGO_URI, (err,res)=>{
    if(err){
        console.log("not connected to mongo")
    }else{
        console.log("connection successful")
    }
})


app.post("/user/signup", (res,res)=>{
    let newUser = new User({
        firstName: req.body.firstName,
        lastName: req.body.lastName,
        email: req.body.email
    })
    newUser.save()
})






app.listen( 8080, () =>{
    console.log(`Server is listening on port: 8080`)
})


mongoose model:

const mongoose = require('mongoose');


new userSchema = new mongoose.Schema({
    firstName: string,
    lastName: string,
    email: string
})


module.exports = (userSchema)

console.log when starting server:

2 years ago
WebElement not found when Selenium script executes

I have been experimenting with some simple Automation scripts using Java and Selenium, but with this login script I am running into an issue where the web elements are not being found by my automation script. The code below is my current login automation script, and for obvious reasons the website, username, and password are removed from the code...

Note: I am not too familiar with using Selenium and Java so any advice would go a long way...

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Login {

  public static void main(String[] args) throws InterruptedException {
  
    // TODO Auto-generated method stub
  
    Login obj = new Login(); 
    obj.LoginScriptTest();
  
  }
  
  public void LoginScriptTest() throws InterruptedException {
    
    String curDir = System.getProperty("user.dir");
    System.setProperty("webdriver.chrome.driver", curDir+"\\drivers\\chromedriverexe.exe");
    ChromeOptions options = new ChromeOptions(); 
    options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); 
    WebDriver driver = new ChromeDriver(options); 
    driver.get("https://********.com");
    driver.findElement(By.xpath("//span[@class='myTestSpan']")).click(); 
    driver.findElement(By.xpath("//div[@class='myTestDiv']")).click(); 
    
      WebDriverWait wait3 = new WebDriverWait(driver, 4); 
      wait3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//form[@method='post']"))); 
      WebElement userName = driver.findElement(By.id("username"));
      WebElement password = driver.findElement(By.id("password"));
  
      String username = "********@yahoo.com";  
      String pwd = "*******"; 
    
      for (int i = 0; i < username.length(); i++) {
    
        char c = username.charAt(i); 
        String s = new StringBuilder().append(c).toString();
        userName.sendKeys(s);
    
      }
    
     
      for (int i = 0; i < pwd.length(); i++) {
    
        char c = pwd.charAt(i); 
        String s = new StringBuilder().append(c).toString();
        password.sendKeys(s);
    
      }
    
         WebElement ele = driver.findElement(By.id("login")); 
         ele.sendKeys(Keys.ENTER);
    
    }
  
}
2 years ago
What framework should I build my client side application with?

I'm going to be starting a new project pretty soon and I know that I am going to need to work with some sort of front end framework as I anticipate this project becoming overwhelmingly large. Having never worked with any sort of front end frameworks before, I am afraid of starting to work with one and realizing that I hate it or it may not work for my given application. Additionally, how do you guys handle projects that you know are going to become large and complex? Are there any sort of steps you take before hand to help prepare you for the work ahead?

2 years ago
Cors blocking access from my client application

I currently have both my client side and API being served on Heroku, but Cors is blocking access to my API. This is only happening in my production environment, as my local environments work as expected. I've tried multiple combinations of Cors policies in my API, and from each request that is sent from my client side, I am sending { withCredentials: true }. Below is the current code that I have in my app.js.


const express = require('express');
const cors = require('cors');

var app = express(); 

const options = {
  origin: 'https://myclientapp.com',
  credentials: 'true'
};

app.use(cors(options)); 

app.listen(process.env.PORT || 3000, () => {
  console.log(`Sever is listening on port: ${process.env.PORT}`);
});

Any help would be great

2 years ago
Looking for more information on Insecure Direct Object Reference

Hi -

Does anyone have references or info on Insecure Direct Object Reference (IDOR) - and how to fix it?

Thanks,

Walt