Advertisement
Guest User

Untitled

a guest
Sep 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. Object { _body: "<!DOCTYPE html> <html> <head> …", status: 500, ok: false, statusText: "Internal Server Error", headers: Object, type: 2, url: "http://ec2-52-92-174-9.us-west-2.co…" }
  2.  
  3. // Find user in database, if exists, and log them in
  4. find(email:any, password:any){
  5. //let body:User = {email:email, password:password};
  6. let headers = new Headers({ 'Content-Type': 'application/json' });
  7. this.http.post('/api/User/find', {email:email, password:password} ,{headers:headers})
  8. .map(response => response.json())
  9. .subscribe(
  10. data => this.login(data),
  11. error => this.userError(error)
  12. );
  13. }
  14.  
  15. public IActionResult find([FromBody] User user){
  16. User result = new User();
  17. using(SqliteConnection con = new SqliteConnection(cs)){
  18. con.Open();
  19. string stm = $"SELECT * FROM USERS WHERE EMAIL='{user.email}' AND PASSWORD='{user.password}' LIMIT 1";
  20. using (SqliteCommand cmd = new SqliteCommand(stm, con)){
  21. using (SqliteDataReader rdr = cmd.ExecuteReader()){
  22. while (rdr.Read()) {
  23. result = new User {
  24. id = rdr.GetInt32(0),
  25. email = rdr.GetString(1)
  26. };
  27. }
  28. }
  29. }
  30. con.Close();
  31. }
  32. if(result.Equals(user))
  33. return Json(result);
  34. return BadRequest("User not found"); // Not my current error, this is a different status 400 and message
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement