Browse Source

Login works. retj now allows for state overrides.

Nathaniel van Diepen 11 years ago
parent
commit
b497415e32
4 changed files with 18 additions and 4 deletions
  1. 1 0
      api.php
  2. 15 2
      php/functions.php
  3. 0 1
      php/security.php
  4. 2 1
      php/user.php

+ 1 - 0
api.php

@@ -40,6 +40,7 @@
 								}else{
 									$ret['error'] = "Please provide a valid username and password.";
 								}
+								$ret['state'] = Array('data'=>Array('type'=>'template','id'=>'login'));
 								retj($ret,$id);
 							break;
 							case 'register':

+ 15 - 2
php/functions.php

@@ -4,8 +4,21 @@
 	function retj($json,$title){
 		$type=$_GET['type'];
 		$id=$_GET['id'];
-		$json['state'] = Array();
-		$json['state']['data'] = $_GET;
+		if(!isset($json['state'])){
+			$json['state'] = Array();
+		}
+		if(!isset($json['state']['data'])){
+			$json['state']['data'] = $_GET;
+		}else{
+			foreach($_GET as $key => $val){
+				if(!isset($json['state']['data'][$key])){
+					$json['state']['data'][$key] = $val;
+				}
+			}
+		}
+		if(isset($json['key'])){
+			$json['state']['key'] = $json['key'];
+		}
 		$json['state']['title'] = $title;
 		switch($type){
 			case 'user':$url='~'.$id;break;

+ 0 - 1
php/security.php

@@ -10,7 +10,6 @@
 		return $hash;
 	}
 	function compareSaltedHash($pass,$salt,$hash){
-		die(saltedHash($pass,$salt)."\n".$hash);
 		return $hash == saltedHash($pass,$salt);
 	}
 	function securityKey($username,$salt){

+ 2 - 1
php/user.php

@@ -18,7 +18,8 @@
 				$row = $res->fetch_assoc();
 				if(compareSaltedHash($password,$row['salt'],$row['password'])){
 					return securityKey($username,salt());
-				}			}
+				}			
+			}
 		}
 		return false;
 	}