Advertisement
ArranUbels

Untitled

Mar 30th, 2013
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. public static function logIn(){
  2.         $request = \Slim\Slim::getInstance()->request();
  3.         // Since the request is in JSON format, we need to decode it
  4.         $user = json_decode($request->getBody());
  5.         // the rest of the code is just PDO stuff
  6.         $sql = "SELECT id, passkey FROM users WHERE username=:username AND password=:password";
  7.         try{
  8.             $db = getConnection();
  9.             $stmt=$db->prepare($sql);
  10.             $stmt->bindParam(":username", $user->username);
  11.             $stmt->bindParam(":password", md5sum($user->password));
  12.             $stmt->execute();
  13.             $db = null;
  14.             $row=$stmt->fetchAll(PDO::FETCH_OBJ);
  15.             // here we check if there are rows
  16.             if($row){
  17.                 echo '{"user":'.json_encode($row).'}';
  18.                 //echo json_encode($row);
  19.             }
  20.             else{
  21.                 $errArray = array('passkey'=>'false');
  22.                 echo '{"user":'.json_encode($errArray).'}';
  23.                 //echo json_encode($errArray);
  24.             }
  25.         }
  26.         catch(PDOException $e){
  27.             echo $e->getMessage();
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement