-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation
To call services in this file with AJAX, you need to specify url to this file and userService's name. Here is a sample AJAX call:
/*Sample to call isDuplicate in userActionHandler.php*/
$.ajax({
type: "POST",
url: "../php/userActionHandler.php" ,
data: {'userService': 'isDuplicate' , 'servicePara': 'username'},
success: function (serverResponse) {
/* serverResponse contains info sent from server
Handle server response with proper functions*/
},
error : function(ajaxError) {
/*If the communication failed, explore ajaxError*/
}
});-
Calling Service
-
isDuplicate- function : find out if the given userName existed in the database.
-
post data :
{'userService' : 'isDuplicate ', 'userName': 'userName'} -
server response :
{'status' : status_code, 'msg': TRUE/FALSE}
-
signUp- function: store the user's registration info into the database.
-
post data :
{'userService' : 'signUp', 'userName':'user name', 'userPass':'user passwork', 'userRole':'user role', 'userPhone': 'user phone', 'userEmail': 'user email'} -
server response :
{'status' : status_code, 'msg': SUCCESS} when signUp success
-
logIn- function: check if the userName and userPassword users input are correct by comparing with records from database.
-
post data :
{'userService' : 'logIn', 'userName':'user name', 'userPassword':'user password'} -
server response :
{'status' : status_code, 'msg': true} when logIn success or {'status' : status_code, 'msg': false} when logIn fail
-
-
Server Response
- Service Success
{'status' : 200, 'msg': database response}
- Service Failed
{'status' : 400, 'msg': 'No Service Selected'}{'status' : 404, 'msg': 'Service Not Found'}{'status' : 406, 'msg': 'No enough data'}{'status' : 600, 'msg': 'Databae Connection Failed'}{'status' : 601, 'msg': 'Unknown error in database'}
- Service Success
To call services in this file with AJAX, you need to specify url to this file and userService's name. Here is a sample AJAX call:
/*Sample to call uploadHouseInfo in houseActionHandler.php*/
$.ajax({
type: "POST",
url: "../php/houseInfoHandler.php" ,
data: {'houseService': 'uploadHouseInfo' , 'servicePara': },
success: function (serverResponse) {
/* serverResponse contains info sent from server
Handle server response with proper functions*/
},
error : function(ajaxError) {
/*If the communication failed, explore ajaxError*/
}
});-
Calling Service
-
uploadHouseInfo- function : insert the houseInfo to the database.
-
post data :
{'userService' : 'uploadHouseInfo', (*)'userName', (*)'address', (*)'city',(*)'state',(*)'bath',(*)'bed' ,(*)'price', (*)'imageUrl', (*)'livingSpace', (*)'zipCode' ,'buildTime', 'lotSpace' ,'description'} -
server response :
{'status' : status_code, 'msg': SUCESS}OR{'status' : status_code, 'msg': Unknown error in database}(*) means the tag is required.
-
-
Syntax of each filed in SignUp form
- userName (required): shouldn't be duplicate with any userName in Database
- passWord (required)
- repassWord (required): passWord should be the same with repassWord.
- email (optional): xx@xxx.com
- phone (optional): xxx-xxx-xxxx
-
Check Validate of input
- Check if all field in the form is filled.
- If not, should prompt a notice to user
- Check if the passWord marched with repassWord
- Check if the userName is duplicated
- Check if all field in the form is filled.
-
Ajax POST() and GET()
- Get the userName information from Server.
- get Status from server about whether userName isDuplicate or not
- Post all the information in 1. to Server
- get status back from server about if the Post succeeded or not
- Get the userName information from Server.
-
calling service
-
generateitem(obj)- function: Create new HTML nodes for Item (show house infomation)
- param obj: an JSON that contains house infomation
obj= { "address":"address string", "price":"price" , "bed": "bedNUmber", "bath": "bathNumebr", "lotSpace":"spaceNUmber", "buildTime":"buildYearNUmber", "imgUrl":"house img url", "description":"Descrition about hour house" } - return: a DOM object (essential to list a single house info)
-
isDuplicated.sql checks a username is already existed in the table User_infoand return the result message.
To use these queries you need to specify [user name](requirement)
-- isDuplicated
SELECT CASE ( SELECT COUNT(`User_name`) FROM User_info WHERE `User_name` = [user name])
WHEN 0 THEN CONCAT ('{"status":' , 0, ',' '"msg":', '"user name is available!"}')
ELSE CONCAT ('{"status":' , -1 , ',' '"msg":', '"user name is duplicated!"}')
END;To use these queries you need to specify [user name](requirement), [password](requirement),[user role](requirement),[email] and [phone]
-- signUp
INSERT INTO User_info (User_name, Password, User_role, Email, Phone)
VALUES ([user name],
AES_ENCRYPT([password], UNHEX(SHA2(`My secret key`,512))), [user role], [email], [phone]);
SELECT CASE ( SELECT COUNT(`User_name`) FROM `User_info` WHERE `User_name` = [user name])
WHEN 0 THEN CONCAT ('{"status":' , -1 , ',' '"msg":', '"Sign up Failed!"}')
ELSE CONCAT ('{"status":' , 0 , ',' '"msg":', '"Sign up succeed!"}')
END;To use these queries you need to specify [user name](requirement), [password](requirement)
-- logIn
SELECT COUNT(`User_name`) AS dbResult
FROM `User_info`
WHERE `User_name` = [user name] AND AES_DECRYPT (`Password`,UNHEX(SHA2('My secret passphrase',512))) = [password] ;
upLoad.sql upload a seller Houses info and image url in the database tables 'Houses', 'Houses_image' and return status of upload.
To use these queries you need to specify [user name](requirement), [Zipcode](requirement),[Address](requirement),[City](requirement),[State](requirement),[Price](requirement),[Beds](requirement),[Baths](requirement),[Built](requirement),[living_space](requirement),[Lot_space](requirement),[description](requirement),[Image_url](requirement)
-- upLoad house info
INSERT INTO `Houses2` (`User_id`, `Zipcode`, `Address`, `City`, `State`,`Price`,`Beds`, `Baths`, `Built`,`description`,`Space`,`Lot_space`)
VALUES(
(SELECT `User_id` FROM `User_info` WHERE `User_name` = [user name]),[Zipcode],
[Address],[City], [State], [Price], [Beds],[Baths],[Built],[description],[living_space],[Lot_space])
-- upLoad image
INSERT INTO `Houses_images` (`House_id`,`User_id`, `Url`)
VALUES(
(SELECT `House_id` FROM `Houses2` ORDER BY `House_id` DESC LIMIT 1),(SELECT `User_id` FROM `Houses2` ORDER BY `House_id` DESC LIMIT 1),
[Image_url])
-
isDuplicate
- function : find out if the given userName existed in the database.
- input parameter: [user name]
-
signUp
- function : store the user's registration info into the database and return status of registration.
- input parameter: [user name], [password], [user role], [email], [phone].
-
logIn
- function : check the user's username and password in the database table 'User_info' and return status of log in.
- input parameter: [user name], [password].
-
upLoad
- function : upload a seller Houses info and image url in the database tables 'Houses', 'Houses_image' and return status of upload.
- input parameter: [user name], [Zipcode],[Address],[City],[State],[Price],[Beds],[Baths],[Built],[living_space],[Lot_space],[description],[Image_url].