Skip to content

HouPoc/Dream-House

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guideline for using backend APIs

userActionHandler.php contains all services related to users' actions.

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*/  
                }
            });

Specifications:

  1. 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
  2. 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'}

houseActionHandler.php contains all services related to houses' actions.

Guideline for using Front End Javascript

signUp.js contains all event controls related to sign up page.

Specifications:

  1. 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
  2. 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
  3. 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

Guideline for using database sql query

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;

signUp.sql add a new user to table User_info and return the result of sign up.

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;

logIn.sql check user's username and password in table User_info and return the result of log in.

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] ;

Specifications:

  1. isDuplicate

    • function : find out if the given userName existed in the database.
    • input parameter: [user name]
  2. 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].
  3. 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].

Releases

No releases published

Packages

No packages published

Languages

  • PHP 44.6%
  • CSS 36.7%
  • JavaScript 12.1%
  • HTML 6.6%