Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function logIn(){
- $request = \Slim\Slim::getInstance()->request();
- // Since the request is in JSON format, we need to decode it
- $user = json_decode($request->getBody());
- // the rest of the code is just PDO stuff
- $sql = "SELECT id, passkey FROM users WHERE username=:username AND password=:password";
- try{
- $db = getConnection();
- $stmt=$db->prepare($sql);
- $stmt->bindParam(":username", $user->username);
- $stmt->bindParam(":password", md5sum($user->password + "salt"));
- $stmt->execute();
- $db = null;
- $row=$stmt->fetchAll(PDO::FETCH_OBJ);
- // here we check if there are rows
- if($row){
- echo '{"user":'.json_encode($row).'}';
- //echo json_encode($row);
- }
- else{
- $errArray = array('passkey'=>'false');
- echo '{"user":'.json_encode($errArray).'}';
- //echo json_encode($errArray);
- }
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement