Esempio n. 1
0
} else {
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // check to make sure form is filled out correctly
        if (empty($_POST["username"])) {
            apologize("You must provide your username.");
        } else {
            if (empty($_POST["password"])) {
                apologize("You must provide your password.");
            } else {
                if ($_POST["password"] != $_POST["confirmation"]) {
                    apologize("Two passwords do not match!");
                }
            }
        }
        // check to make sure random uniqueID is actually unique
        do {
            $identifier = generateRandomID();
            $checkuniqueID = CS50::query("SELECT * FROM users WHERE uniqueID = ?", $identifier);
        } while (!empty($checkuniqueID));
        // check to see username was unique
        $test = CS50::query("INSERT IGNORE INTO users (username, hash, uniqueID, email) VALUES(?, ?, ?, ?)", $_POST["username"], password_hash($_POST["password"], PASSWORD_DEFAULT), $identifier, $_POST["email"]);
        if ($test == 0) {
            apologize("This username is taken!");
        } else {
            $rows = CS50::query("SELECT LAST_INSERT_ID() AS id");
            $id = $rows[0]["id"];
            $_SESSION = $id;
            redirect("/");
        }
    }
}
Esempio n. 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // validate the info, create rules for the inputs
     $rules = array('user_firstname' => 'required', 'user_gender' => 'required', 'user_joined_date' => 'required|date_format:"' . DATE_FORMAT_2, 'user_left_date' => 'date_format:"' . DATE_FORMAT_2, 'user_email' => 'required|email|unique:user,user_email,' . $id . ',user_key,deleted_at,NULL', 'country_key1' => 'required', 'user_contact_phone_number1' => 'required', 'user_status' => 'required');
     // run the validation rules on the inputs from the form
     $validator = Validator::make(Input::all(), $rules);
     // if the validator fails, redirect back to the form
     if ($validator->fails()) {
         // redirect to list page
         Session::flash('danger', UNABLE_TO_SAVE);
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         // where condition
         $user = User::userKey($id)->first();
         // check if the record can be updated
         if (empty($user->id)) {
             // redirect to list page
             Session::flash('danger', SOMETHING_WENT_WRONG);
             return Redirect::to(strtolower(USER_TITLE));
         }
         // fields to be updated
         $user->user_firstname = $this->getInput('user_firstname', '');
         $user->user_middlename = $this->getInput('user_middlename', '');
         $user->user_lastname = $this->getInput('user_lastname', '');
         $user->user_alias = $this->getInput('user_alias', '');
         $user->user_gender = $this->getInput('user_gender', '');
         $user->user_civil_status = $this->getInput('user_civil_status', '');
         $user->user_birth_date = \Carbon\Carbon::createFromFormat(DATE_FORMAT_1, $this->getInput('user_birth_date', DEFAULT_DATE))->format(DB_DATE_FORMAT);
         $user->user_joined_date = $this->getInput('user_joined_date', '');
         $user->user_left_date = $this->getInput('user_left_date', '');
         $user->user_email = $this->getInput('user_email', '');
         $user->user_hometown_address = $this->getInput('user_hometown_address', '');
         $user->user_overseas_address = $this->getInput('user_overseas_address', '');
         if (Session::has('user_photo')) {
             $user->user_photo = Session::get('user_photo');
             Session::forget('user_photo');
         }
         $user->user_status = $this->getInput('user_status', '');
         $user->updated_by = Auth::user()->id;
         // update record
         $user->save();
         for ($cnt = 1; $cnt <= $this->getInput('hdn_increment', ''); $cnt++) {
             if ($this->getInput('hdn_index' . $cnt, '') == YES && $this->getInput('country_key' . $cnt, '') != EMPTY_STRING && $this->getInput('user_contact_phone_number' . $cnt, '') != EMPTY_STRING) {
                 if ($this->getInput('user_contact_key' . $cnt, '') == EMPTY_STRING) {
                     $data = array();
                     $data['user_contact_key'] = generateRandomID();
                     $data['user_id'] = $user->id;
                     $data['country_id'] = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id');
                     $data['user_contact_phone_number'] = $this->getInput('user_contact_phone_number' . $cnt, '');
                     $data['created_by'] = Auth::user()->id;
                     // create record
                     UserContact::create($data);
                 } else {
                     // where condition
                     $user_contact = UserContact::UserContactKey($this->getInput('user_contact_key' . $cnt, ''))->first();
                     // check if the record can be updated
                     if (isset($user_contact->id)) {
                         $user_contact->country_id = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id');
                         $user_contact->user_contact_phone_number = $this->getInput('user_contact_phone_number' . $cnt, '');
                         $user_contact->updated_by = Auth::user()->id;
                         // update record
                         $user_contact->save();
                     }
                 }
             }
         }
         // where condition
         $user_emergency = UserEmergency::userId($user->id)->first();
         // check if the record can be updated
         if (!empty($user_emergency->id)) {
             // fields to be updated
             $user_emergency->user_emergency_name = $this->getInput('user_emergency_name', '');
             $user_emergency->user_emergency_relation = $this->getInput('user_emergency_relation', '');
             $user_emergency->user_emergency_address = $this->getInput('user_emergency_address', '');
             $user_emergency->country_id = Country::countryKey($this->getInput('emergency_country_key', ''))->pluck('id');
             $user_emergency->user_emergency_phone = $this->getInput('user_emergency_phone', '');
             $user_emergency->updated_by = Auth::user()->id;
             // update record
             $user_emergency->save();
         }
         // flag all approver template records
         AccessUser::userId($user->id)->update(array('access_user_flag' => YES));
         // create access record
         if (is_array($this->getInput('access_user', array()))) {
             foreach ($this->getInput('access_user', array()) as $access_id) {
                 $access_user = AccessUser::accessId($access_id)->userId($user->id)->first();
                 if (isset($access_user->id) && !empty($access_user->id)) {
                     // update record
                     $access_user->user_id = $user->id;
                     $access_user->access_id = $access_id;
                     $access_user->access_user_flag = NO;
                     $access_user->updated_by = Auth::user()->id;
                     $access_user->save();
                 } else {
                     // create record
                     $data = array();
                     $data['user_id'] = $user->id;
                     $data['access_id'] = $access_id;
                     $data['access_user_flag'] = NO;
                     $data['created_by'] = Auth::user()->id;
                     AccessUser::create($data);
                 }
             }
             // delete records set to yes
             AccessUser::AccessUserFlag(YES)->UserId($user->id)->delete();
         }
         // redirect to list page
         Session::flash('success', SUCCESS_UPDATE);
         return Redirect::to($this->getPreviousListURL());
     }
 }
Esempio n. 3
0
// Lock the myInfoTab table.
$query = "LOCK TABLES {$myInfoTab} WRITE";
if (!@mysql_query($query, $connection)) {
    die("Couldn't lock.");
}
// We're updating.
// Get the referal id.
$query = "select referal_id from {$myInfoTab} where reg_id = '{$reg_id}'";
// Run the query.
$result = @mysql_query($query, $connection);
// Translate the output to an array.
$row = @mysql_fetch_array($result);
// Keep track of the referal id -- it gets printed out at the end.
$parameters['referal_id'] = $row['referal_id'];
if ($parameters['referal_id'] == "NULL" || $parameters['referal_id'] == "") {
    $parameters['referal_id'] = generateRandomID($myHost, $myUser, $myPW, $myDB, $myReferTab, "referal_id");
    if ($parameters['referal_id'] != null && $parameters['referal_id'] != "false") {
        // Add the registrant's reg_id to the referal table.
        // Lock the refer table.
        //        $query = "LOCK TABLES $myReferTab WRITE";
        //        if( !(@ mysql_query( $query, $connection) ) )
        //           die( "Couldn't lock." );
        // Make the query to add the registrant's id to the referer table.
        $query = "update {$myReferTab} set reg_id = '{$reg_id}' " . "where referal_id = '{$parameters['referal_id']}'";
    } else {
        // Unlock the table.
        $query = "UNLOCK TABLES";
        if (!@mysql_query($query, $connection)) {
            die("Couldn't unlock.");
        }
        print "fail";
Esempio n. 4
0
   // Run the query.
   $result = @ mysql_query( $query, $connection );

   // Translate the output to an array.
   $row =  @ mysql_fetch_array( $result );

   // If the row array is null, then we know the username hasn't been used
   // yet.
   $isValidUsername =  ($row == null);

//   if( !$isValidUsername )
//      print "username already in use: " . $username . "<br>";

} while( !$isValidUsername );
*/
$username = generateRandomID($myHost, $myUser, $myPW, $myDB, $myInfoTab, "reg_id");
$referal_id = generateRandomID($myHost, $myUser, $myPW, $myDB, $myReferTab, "referal_id");
// Insert the name into the database.
$query = "update {$myInfoTab} set  first_reg_date = '" . date("r") . "', referal_id = '{$referal_id}' where reg_id = '{$username}'";
if (!@mysql_query($query, $connection)) {
    print "Error inserting into table.";
}
print "id:" . $username;
//print "In middle.<br>" ;
// Unlock the table.
$query = "UNLOCK TABLES";
if (!@mysql_query($query, $connection)) {
    die("Couldn't unlock.");
}
//print "At end.<br>" ;