I'm using script program with a Create Account Page. It asks for User Name, Password, Email Address etc. I want the User Name to be the Users Email Address, is there a way to combine these, so that the User Name is the email address? Or is it possible to somehow require that the user enter an email address as a User Name? And then store the user name where the email address would be stored? Thank you. Here is the code: <?php global $account; ?> <form method="POST" action="index.php"> <table align="center" cellpadding="1" width="70%" height="100%"> <tr><td> </td></tr> <tr><td> </td></tr> <input class='field' type='hidden' name='command' value='account'> <input class='field' type='hidden' name='param' value='signup'> <tr><td colspan='2' class='pageTitle'><div class='hLine'>Create new account</div></td></tr> <tr><td> </td></tr> <tr> <td class='fieldLabel' width="30%">Membership type</td> <td align="center">[account_type_panel]</td></tr> <tr><td> </td></tr> <tr> <td class='fieldLabel' width="30%">User Name</td> <td><input class='field' type='text' size='30' maxlength="30" name='user_name' value='<?=$account->user_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('user_name') ?></span></td> </tr> <tr> <td class='fieldLabel'>Password</td> <td><input class='field' type='password' size='30' maxlength="30" name='password' value='<?=$account->password ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('password') ?></span></td> </tr> <tr> <td class='fieldLabel'>Re-enter Password</td> <td><input class='field' type='password' size='30' maxlength="30" name='reenter_password' value='<?=$account->reenter_password ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('reenter_password') ?></span></td> </tr> <tr> <td class='fieldLabel'>Name </td> <td ><input class='field' type='text' size='40' maxlength="50" name='first_name' value='<?=$account->first_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('first_name') ?></span></td> </tr> <tr> <td class='fieldLabel'>business / company name</td> <td><input class='field' type='text' size='40' maxlength="50" name='last_name' value='<?=$account->last_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('last_name') ?></span></td> </tr> <tr><td> </td></tr> <tr> <td class='fieldLabel'>Email address</td> <td><input class='field' type='text' size='40' maxlength="50" name='email' value='<?=$account->email ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('email') ?></span></td> </tr> <tr> <td class='fieldLabel'>Address</td> <td><input class='field' type='text' size='40' maxlength="70" name='address' value='<?=$account->address ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('address') ?></span></td> </tr> <tr> <td class='fieldLabel'>Address 2</td> <td><input class='field' type='text' size='40' maxlength="70" name='address_second' value='<?=$account->address_second ?>'></td> </tr> <tr> <td class='fieldLabel'>City</td> <td><input class='field' type='text' size='40' maxlength="50" name='city' value='<?=$account->city ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('city') ?></span></td> </tr> <tr> <td class='fieldLabel'>Zip/Postal code</td> <td><input class='field' type='text' size='35' maxlength="35" name='zip_postal_code' value='<?=$account->zip_code ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('zip_code') ?></span></td> </tr> <tr> <td class='fieldLabel'>Phone Number</td> <td><input class='field' type='text' size='35' maxlength="35" name='phone' value='<?=$account->phone ?>'></td> </tr> <tr> <td class='fieldLabel'>Mobile Phone Number</td> <td><input class='field' type='text' size='35' maxlength="35" name='mobile_phone_number' value='<?=$account->mobile_phone_number ?>'></td> </tr> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td colspan="2" class='hLine' align="right"> <span class='requiredField'> *</span> Required field</td></tr> <tr><td colspan='2' align="right"><input class='button' type='submit' value='create'></td></tr> <tr><td colspan="2"> </td></tr> </table> </form> Code (markup):
Yea, you can remove the 'username' column from the DB. Change the login and authentication code so that it uses the email column instead of username. And you can remove the username box and label from the registration page.
Thank you for your replies. How/where can I remove the 'username' column from the DB. I'm not too familiar with mySQL. How would I "change the login and authentication code so that it uses the email column instead of username."? And you how would I "remove the username box and label from the registration page"? Here is the index.php content, as requested: <?php /** * @file: index.php * @description: main page */ session_start(); include_once "db_config.php"; include_once "classes/system.php"; include_once "classes/main_menu.php"; include_once "classes/tools.php"; $command = tools::get_field_value("command"); $param = tools::get_field_value("param"); $main_menu = new main_menu($system); $content = $main_menu->parse_command($command,$param); echo $content; ?> Code (markup):
Well, removing the username box is as simple as removing the code <tr> <td class='fieldLabel' width="30%">User Name</td> <td><input class='field' type='text' size='30' maxlength="30" name='user_name' value='<?=$account->user_name ?>'> <span class='requiredField'> * </span><span class='errorMessage'><?=$account->get_error('user_name') ?></span></td> </tr> from the form. But that wont do it all. From what you have posted, it seems it is using a custom authentication class to do the registration and login and so on. So any modifications will have to go in there. I dont know where the authentication is taking place. It seems the main_menu class takes the command and param ( 'account' and 'signup' in this case ) and finds out what to do. So you will have to look in classes/main_menu.php to find where the account signup code is. I dont know why you say there is no DB, since I see include_once "db_config.php"; in the file you posted. This is usually used to store info about the database. Or maybe it uses a text file to store the data? Its actually difficult to say without seeing the whole code. The index.php file does nothing. It only calls some other files, which does the job.
Thanks again for your reply. If you wouldn't mind helping me find "where the account signup code is" in classes/main_menu.php, here is the code: <?php /** * file: main_menu.php * class: main_menu * description: main menu * * include_once "system.php"; include_once "tools.php"; include_once "account.php"; include_once "account_type.php"; include_once "content_pages.php"; class main_menu { var $system; var $terms_error; /** * constructor * * @param system $system */ function main_menu(&$system) { if ($system != null) { $this->system = $system; } else { die("Error account reference is null"); } } /** * parse menu commands and return template content * * @param string $command * @param string $param * @return html template content */ function parse_command($command,$param) { $content = ""; global $account,$account_type, $login_text,$member_menu,$account_type_id, $account_type_title; $account = new account($this->system); $account_type = new account_type($this->system); $activation_code = tools::get_field_value("param"); if ($account->check_login() == true) { $login_text = " user: <b>" . $account->get_user_name() . "</b>"; $member_menu = $account->get_account_menu(); } else { $login_text = ""; } switch($command) { // forgotten password page case "send_pass": { $main_content = $this->system->template->compile_template("forgotten_password_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // display subscribtion thanks page case "thanks": { $transaction_id = tools::get_field_value("tx"); $amount = tools::get_field_value("amt"); $account_id = tools::get_field_value("account"); $account_type_id = $account->get_account_type_id($account_id); $account_type_title = $account_type->get_account_type_title($account_type_id); $main_content = $this->system->template->compile_template("subscribe_thanks_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // reset password command case "reset_password": { $email = tools::get_field_value("email",true,false); $result = $account->check_account_email($email); if ($result == false) { $error_message = " email address is not valid ! "; $main_content = $this->system->template->compile_template("forgotten_password_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); } else { $result = $account->reset_password($email); if ($result == true) { $content = $this->show_message_page(" forgotten password "," You password send to: <b>$email</b> "); } else { $content = $this->show_message_page(" error "," Error send password "); } } break; } // activate account case "activate": { $result = $account->activate_account($activation_code); if ($result == true) { $content = $this->system->template->compile_template("account_activation_page.htm",get_defined_vars()); } else { $content = $this->show_message_page("Error Account activation","Error activate your account "); } break; } case "account": { $content = $this->parse_account_commands($param); break; } // member signup case "signup_page": { $account_type_panel = $account_type->get_account_type_panel($account_type_id); $content = $this->system->template->compile_template("account_create_page.htm",get_defined_vars()); break; } // show login page case "login_page": { $content = $this->system->template->compile_template("account_login_page.htm",get_defined_vars()); break; } default : { // default open home page if ($account->check_login() == true) { $account_type_id = $account->get_account_type_id(); $price = $account_type->get_account_type_price($account_type_id); $account_type_title = $account_type->get_account_type_title($account_type_id); if ($price > 0) { // show paid protcted page $main_content = $this->system->template->compile_template("account_paid_home_page.php",get_defined_vars()); } else { // show free account protected page $main_content = $this->system->template->compile_template("account_free_home_page.php",get_defined_vars()); } } else { // site home page when user is nto loged in $main_content = $this->system->template->compile_template("home_page.htm",get_defined_vars()); } $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } } $header = $this->system->template->compile_template("header.htm",get_defined_vars()); $footer = $this->system->template->compile_template("footer.htm",get_defined_vars()); $page = $header . $content . $footer; return $page; } function parse_account_commands($param) { global $account,$account_type, $account_type_id,$account_type_title, $login_text,$member_menu; $account = new account($this->system); $account_type = new account_type($this->system); if ($account->check_login() == false && $param != "login" && $param != "logout" && $param != "signup" ) { $content = @$this->show_message_page(" erorr "," login to your account "); return $content; } switch ($param) { // do login case "login": { $user_name = tools::get_field_value("user_name"); $password = tools::get_field_value("password"); $result = @$account->user_name_login($user_name,$password); if ($result != 0) { // display if ($result == -8 ) { // not activated accocunt $login_message = "Error login"; $content = $this->show_message_page(" Erorr login "," Your account is not acctivated or closed "); } else { $login_message = "Error login"; $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); } } else { $login_text = " user: <b>" . $account->get_user_name() . "</b>"; $member_menu = @$account->get_account_menu(); $content = @$this->system->template->compile_template("main_page.htm",get_defined_vars()); } break; } // show protected content page case "content": { $account_type_id = $account->get_account_type_id(); $price = $account_type->get_account_type_price($account_type_id); $account_type_title = $account_type->get_account_type_title($account_type_id); if ($price > 0) { // show paid protcted page $content = $this->system->template->compile_template("account_paid_home_page.php",get_defined_vars()); } else { // show free account protected page $content = $this->system->template->compile_template("account_free_home_page.php",get_defined_vars()); } break; } // upgrade account / subscribe / case "subscribe": { break; } // upgrade account / show subscribe page / case "upgrade": { break; } // edit account details case "edit": { $account->read(); $account_type_title = $account_type->get_account_type_title($account->account_type_id); $main_content = $this->system->template->compile_template("account_change_details_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // update account details case "update": { $account->read_form_data(true,false); $result = $account->update_profile(); if ($result == true) { $content =$this->show_message_page(" Account details "," Account details changed successful "); } else { $content =$this->show_message_page(" Error "," Error save details "); } break; } // show protected page case "show_page": { $main_content = ""; $account_type_id = $account->get_account_type_id(); $page_id = tools::get_field_value("page_id"); $content = new content_pages($this->system); $page_account_type_id= $content->get_account_type($page_id); $page_status = $content->get_status($page_id); if ($page_account_type_id == 0 || $page_account_type_id == $account_type_id) { $main_content = $content->get_page_content($page_id); } else { $main_content = " Access denied! "; } if ($page_status == 0) { $main_content = " Page content disabled "; } $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // logout case "logout": { $account->logout(); $member_menu = ""; $login_text = ""; $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // do account change password case "change_password_confirm": { global $error_messages; $result = $account->read_change_password_form(); if ($result == 0) { $change_result = $account->update_password($account->get_account_email(),$account->new_password); if ($change_result == true) { $content = $this->show_message_page(" Ok ","Password changed successful"); return $content; } } $error_message = $error_messages[$result]; $main_content = $this->system->template->compile_template("account_change_password_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // change account password case "change_password": { $main_content = $this->system->template->compile_template("account_change_password_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); break; } // creat account case "signup": { @$account->logout(); @$account->read_form_data(false,false); $price = $account_type->get_account_type_price($account->account_type_id); if (@$account->get_errors_count() == 0) { // subscribtion page if ($price > 0) { // paid accounts $account_id = $account->add(false); if ($account_id > 0) { @$account->change_status($account_id,0); // set top temp status $site_url = tools::get_script_path(); @$period = $account_type->get_account_type_period($account->account_type_id); @$paypal_account_id = $this->system->config->read_config_variable("paypal_account_id"); $payment_code = $content = $this->system->template->compile_template("paypal_code.htm",get_defined_vars()); $account_type_title = @$account_type->get_account_type_title($account->account_type_id); $price = @$account_type->get_account_type_price($account->account_type_id); $period = @$account_type->get_account_type_period($account->account_type_id); $content = $this->system->template->compile_template("account_subscribe_page.htm",get_defined_vars()); } else { // display message $content = $this->show_message_page("Error","Error creation account"); } } else { // free accounts $result = @$account->add(true); // send with activation email fro free account type only if ($result > 0) { $content = $this->system->template->compile_template("account_creation_message.htm",get_defined_vars()); } else { $content = $this->show_message_page("Error","Error creation account"); } } } else { // validation erorrs $account_type_panel = $account_type->get_account_type_panel($account->account_type_id); $content = $this->system->template->compile_template("account_create_page.htm",get_defined_vars()); } break; } default: break; } return $content; } function show_message_page($title,$message_text) { $message_title = $title; $message = $message_text; $main_content = $this->system->template->compile_template("message_page.htm",get_defined_vars()); $content = $this->system->template->compile_template("main_page.htm",get_defined_vars()); return $content; } } // end class ?> Code (markup): Thank you
Thanks SO much again for your help. I'm assuming you mean classes/account.php. Here is half of it. When I posted the whole thing I got this from DigitalPoint:: "The text that you have entered is too long (38406 characters). Please shorten it to 20000 characters long". So I've split it to pst the other half. <?php /** * * file: account.php * class: account * description: account functions */ // // account_status constants // define('ACCOUNT_STATUS_PENDING',1); define('ACCOUNT_STATUS_ACTIVE',2); define('ACCOUNT_STATUS_LIMITED',3); define('ACCOUNT_STATUS_SUSPENED',4); define('ACCOUNT_STATUS_END_SUBSCRIBTION',5); define('ACCOUNT_STATUS_CANCEL_SUBSCRIBTION',6); define('ENCRYPT_PASSWORD',false); define('LOGIN_WITH_EMAIL',false); define("ERROR_PASSWORD_INCORRECT",-1); define("ERROR_REENTER_PASSWORD",-2); // account erros define("TURING_NUMBER_WRONG_ERROR",-6); define("EMAIL_ADDRESS_WRONG_ERROR",-7); define("ACCOUNT_STATUS_ERROR",-8); global $error_messages; $error_messages[ERROR_PASSWORD_INCORRECT] = " Incorrect password"; $error_messages[ERROR_REENTER_PASSWORD] = " Re entered password not correct"; $error_messages[TURING_NUMBER_WRONG_ERROR] = " Wrong turing number "; $error_messages[EMAIL_ADDRESS_WRONG_ERROR] = " Invalid email address"; $error_messages[ACCOUNT_STATUS_ERROR] = " Your accout not activated "; include_once "tools.php"; include_once "content_pages.php"; class account { // account data var $account_id; var $account_status_id; var $account_status_title; var $user_name; var $account_type_id; var $mobile_phone_number; var $password; var $encrypted_password; var $first_name; var $middle_initials; var $last_name; var $address; var $address_second; var $city; var $state; var $zip_code; var $phone; var $email; var $reenter_email; var $security_question_id; var $security_question; var $security_question_answer; var $country_name; var $country_id; var $date_creation; var $time_creation; var $date_last_login; var $time_last_login; var $last_ip_address; var $user_agreement; var $user_agreement_status; var $activation_code; // change password form values var $old_password ; var $new_password ; var $reenter_password; var $turing_number; // inner object references var $system; // reference to system object var $validation_errors; /** * * create object */ function account($system) { if ($system != null ) { $this->system = $system; $this->clear_fields(); $this->validation_errors = array(); // array for form validation errors } else { // not valid system reference die("error creation Account object system reference not valid"); } } /** * update account password (change password function) * * @param string $account_email * @param string $password * @return bool */ function update_password($account_email,$password) { if ($account_email == "") { $account_email = $this->email; } $check_email = $this->check_account_email($account_email); if ($check_email == false ) { return false; } if (ENCRYPT_PASSWORD == true) { $pass = $this->encrypt_password($password); } else { $pass = $password; } $sql = " UPDATE accounts SET password='$pass' WHERE email = '$account_email' "; $result = $this->system->db->query($sql); if ($result == false) { return false;} return true; } /** * * update account info current account_id is used to update data */ function update_profile($account_id = 0) { if ($account_id == 0) { $account_id = $this->get_current_account_id(); } if (is_numeric($account_id) == false) { $account_id = $this->get_account_id($account_id); } $this->coutry_name = $this->get_country_name($this->country_id); $sql = " UPDATE accounts SET first_name = '" . $this->first_name . "',middle_initials = '" . $this->middle_initials . "',last_name='" . $this->last_name . "',country_name='" . $this->coutry_name . "',state='" . $this->state . "',city='" . $this->city . "',address='" . $this->address . "',address_second='" . $this->address_second . "',zip_code='" . $this->zip_code . "',phone='" . $this->phone . "'" . " WHERE account_id = $account_id "; $result = $this->system->db->query($sql); if ($result == false) { return false; } else { return true; } } /** * * add new account to database return account_id if success else FALSE; */ function add($send_activation_email = true) { $this->account_status_id = ACCOUNT_STATUS_PENDING; // active $this->activation_code = @$this->create_activation_code($this->email); if ($this->country_id == "") { $this->country_id = 0; } if($this->user_name == "") { $this->user_name = $this->email; } if (ENCRYPT_PASSWORD == false) { $password = $this->password; } else { $password = $this->encrypted_password; } if ($this->account_type_id == "") { $this->account_type_id = 1; // free account type } $sql = " INSERT INTO accounts(first_name,middle_initials,last_name,phone,email,password,status_id,status_title,state,city, address,zip_code,address_second,country_id,country_name,date_creation,date_last_login, security_question,security_question_answer,user_agreement,last_ip_address,activation_code, user_name, mobile_phone_number,account_type_id ) VALUES ('" . $this->first_name . "','" . $this->middle_initials . "','" . $this->last_name . "','" . $this->phone . "','" . $this->email . "','" . $password . "'," . $this->account_status_id . ",'" . $this->account_status_title . "','" . $this->state . "','" . $this->city . "','" . $this->address . "','" . $this->zip_code . "','" . $this->address_second . "'," . $this->country_id . ",'" . $this->country_name . "',now()" . ",now(),'" . $this->security_question . "','" . $this->security_question_answer ."','" . $this->user_agreement . "','" . $this->last_ip_address . "','" . $this->activation_code . "','" . $this->user_name . "','" . $this->mobile_phone_number . "'," . $this->account_type_id . ")"; //echo $sql; $result = @$this->system->db->query($sql); if ($result == false) { return false; } else { $account_id = @$this->get_account_id($this->email); if ($send_activation_email == true) { @$this->activation_code = $this->create_activation_code($this->email,$account_id); $result = @$this->send_activation_email($account_id,$this->password); // send activation email if ($result == false) { //echo "error send email "; return false; } } return $account_id; } } /** * * change account type */ function change_account_type($account_id = 0,$account_type_id) { if ($account_id == 0) { $account_id = $this->get_current_account_id(); } $sql = " UPDATE accounts SET account_type_id = $account_type_id WHERE account_id = $account_id " ; $result = $this->system->db->query($sql); if ($result == false) { return false;} else { return true; } } /** * * change account status */ function change_status($account_id = 0,$status_id) { if ($account_id == 0) { $account_id = $this->get_current_account_id(); } $sql = " UPDATE accounts SET status_id = $status_id WHERE account_id = $account_id " ; $result = $this->system->db->query($sql); if ($result == false) { return false;} else { return true; } } /** * activate account * * @param unknown_type $activation_code */ function activate_account($activation_code) { $sql = "SELECT account_id FROM accounts WHERE activation_code = '$activation_code' "; $account_id = $this->system->db->get_scalar($sql); if ($account_id > 0) { $result = $this->change_status($account_id,ACCOUNT_STATUS_ACTIVE); if ($result == false) { return false; } else { return true; } } else { return false; } } /** * * account data */ function read($account_id = "") { if ($account_id == "") { $account_id = $this->get_current_account_id(); } if (is_numeric($account_id) == true) { $result = $this->check_account_id($account_id); if ($result == false) { return false; } } else { $account_id = $this->get_account_id($account_id); if ($account_id == false) { return false; } } $sql = " SELECT * FROM accounts WHERE account_id = $account_id "; $result = $this->system->db->query($sql); $row = $this->system->db->fetch_array($result); if ($row == false) { return false; } $this->account_id = $row['account_id']; $this->account_type_id = $row['account_type_id']; $this->email = $row['email']; $this->first_name = $row['first_name']; $this->middle_initials = $row['middle_initials']; $this->last_name = $row['last_name']; $this->password = $row['password']; $this->encrypted_password = $this->encrypt_password($this->password); $this->security_question = $row['security_question']; $this->security_question_answer = $row['security_question_answer']; $this->phone = $row['phone']; $this->address = $row['address']; $this->address_second = $row['address_second']; $this->zip_code = $row['zip_code']; $this->state = $row['state']; $this->city = $row['city']; $this->country_name = $row['country_name']; $this->account_status_id = $row['status_id']; $this->account_status_title = $row['status_name']; $this->date_creation = $row['date_creation']; $this->time_creation = $row['time_creation']; $this->date_last_login = $row['date_last_login']; $this->time_last_login = $row['time_last_login']; $this->user_agreement = $row['user_agreement']; $this->last_ip_address = $row['last_ip_address']; $this->activation_code = $row['activation_code']; $this->user_name = $row['user_name']; $this->mobile_phone_number = $row['mobile_phone_number']; return true; } /** * return acount id for email address * * @param string $account_email */ function get_account_id($account_email = "") { if ($this->check_account_email($account_email) == false) { return false; } $sql = " SELECT account_id FROM accounts WHERE email='$account_email' "; $id = $this->system->db->get_scalar($sql); return $id; } /** * read account * * @param string $account_email */ function read_account($account_email) { $account_id = $this->get_account_id($account_email); $this->read($account_id); } function read_current_account() { if ($this->check_login() == true) { $this->read_account($_SESSION['account_email']); } } /** * read login form data * */ function read_login_form($login_by_email = false) { $this->password = tools::get_field_value("password"); $this->encrypted_password = $this->encrypt_password($this->password); if ($login_by_email == false) { $this->user_name = tools::get_field_value('user_name'); } else { $this->email = tools::get_field_value('email'); } $this->turing_number = tools::get_field_value('turing_number'); } function delete_temp_account($user_name) { // clear temp account $sql = " DELETE FROM accounts WHERE status_id = 0 AND user_name='$user_name' LIMIT 1 "; $result = $this->system->db->query($sql); if ($result ==false) { return false; } return true; } /** * get values from post form and assing to object properties * */ function read_form_data($read_edit_profile_form = false,$with_turing_number = true) { if ($with_turing_number == true) { $this->turing_number = tools::get_field_value('turing_number'); } $this->account_type_id = tools::get_field_value('account_type_id'); $this->first_name = tools::get_field_value('first_name'); $this->middle_initials = tools::get_field_value('middle_initials'); $this->last_name = tools::get_field_value('last_name'); $this->address = tools::get_field_value('address'); $this->address_second = tools::get_field_value('address_second'); $this->city = tools::get_field_value('city'); $this->state = tools::get_field_value('state'); $this->zip_code = tools::get_field_value('zip_postal_code'); $this->phone = tools::get_field_value('phone'); $this->mobile_phone_number = tools::get_field_value('mobile_phone_number'); $this->user_name = tools::get_field_value('user_name'); $this->delete_temp_account($this->user_name); if ($read_edit_profile_form == false) { $this->password = tools::get_field_value("password"); $this->reenter_password = tools::get_field_value("reenter_password"); $this->encrypted_password = $this->encrypt_password($this->password); $this->email = tools::get_field_value('email'); $this->reenter_email = tools::get_field_value('reenter_email'); $this->last_ip_address = tools::get_client_ip(); } $this->validate($read_edit_profile_form,$with_turing_number); // validate form field values } function get_refferal_link($accont_id) { $url = tools::get_script_path(); $refferal_link = $url . "index.php?ref=$accont_id"; return $refferal_link; } function get_activation_link($email) { $activation_code = $this->get_activation_code($email); $url = tools::get_script_path(); $activation_link = $url . "index.php?command=activate¶m=$activation_code"; return $activation_link; } /** * send email with activation link * * @param int $account_id */ function send_activation_email($account_id = 0,$pass) { if ($account_id == 0) { $account_id = $this->get_current_account_id(); } if ($account_id == false) { return false;} $email = $this->get_account_email_address($account_id); $activation_link = $this->get_activation_link($email); $name = $this->first_name; $user_name = $this->get_user_name($account_id); $password = $pass; $subject = " Thank you for registering! "; $message = $this->system->notification->compile_email_template("activation_account_email.txt",get_defined_vars()); $result = $this->system->notification->send_email($email,$subject,$message); if ($result == false) { return false; } else { return true; } } /** * create account activation code * * @param unknown_type $email * @return unknown */ function create_activation_code($email = "",$account_id = 0) { if ($email == "") { $email = $this->email; } if($account_id == 0) { $account_id = $email; } $code = $account_id . time() . tools::get_current_date(); return sha1($code); } /** * get activation code * * @param int $account_id */ function get_activation_code($email = 0) { if ($email == 0) { $email = $this->email; } $sql = "SELECT activation_code FROM accounts WHERE email = '$email' "; $code = $this->system->db->get_scalar($sql); if ($code != false) { return $code; } else { return false; } } /** * check if account id is valid * * @param int $account_id */ function check_account_id($account_id = 0) { if ($account_id == 0) { $account_id = $this->account_id; } $sql = " SELECT account_id FROM accounts WHERE account_id =$account_id "; $id = @$this->system->db->get_scalar($sql); if ($id == false) { return false; } if ($id != $account_id || $id == "" || $id <=0 ) { return false; } else { return true; } } Code (markup):
/** * validate password field value * * @param string $password * @param string $reenter_passwod */ function validate_password($password,$reenter_password) { if ( $password != $reenter_password ) { $this->validation_errors['reenter_password'] = "Reenter password error"; return false; } if (strlen($password) < 4) { $this->validation_errors['password'] = "Password error"; return false; } return true; } /** * email address validation * * @param string $email * @param string $reenter_email * @return bool */ function validate_email($email,$reenter_email) { if ( tools::check_email($email) == false ) { $this->validation_errors['email'] = "Invalid email address"; return false; } if ($this->check_account_email($email) == true) { // email addres are used in another account $this->validation_errors['email'] = "Email address are used"; return false; } return true; } /** * validate form filed value * * @param string $text * @param string $field_name * @param int $min_length * @param string $error_message * @return bool */ function validate_text($text,$field_name,$min_length,$error_message) { if ($text == "" || isset($text) == false || strlen($text) < $min_length) { $this->validation_errors[$field_name] = $error_message; return false; } else { return true; } } /** * celar obejct fields * */ function clear_fields() { $this->account_status_id = ACCOUNT_STATUS_PENDING; $this->account_status_title = $this->get_status_name($this->account_status_id); $this->password = ""; $this->encrypted_password = ""; $this->first_name = ""; $this->middle_initials = ""; $this->last_name = ""; $this->address = ""; $this->address_second = ""; $this->city = ""; $this->state = ""; $this->zip_code = ""; $this->phone = ""; $this->email = ""; $this->security_question_id = ""; $this->security_question = ""; $this->security_question_answer = ""; $this->user_agreement_status = ""; } /** * return validation erorr message * * @param unknown_type $field_name */ function get_error($field_name) { if ( isset($this->validation_errors[$field_name]) == false ) { return false; } else { return $this->validation_errors[$field_name]; } } /** * return validation errors count * * @return unknown */ function get_errors_count() { if (isset($this->validation_errors) == true) { return count($this->validation_errors); } else { return 0; } } function reset_password($account_email) { if (ENCRYPT_PASSWORD == true) { $new_password = security::generate_password(); } else { $new_password = $this->get_account_password($account_email); } if (LOGIN_WITH_EMAIL == true) { $user_name = $account_email; } else { $account_id = $this->get_account_id($account_email); $user_name = $this->get_user_name($account_id); } $content = $this->system->notification->compile_email_template("reset_password_email.txt",get_defined_vars()); $result = $this->system->notification->send_email($account_email," forgotten password ",$content); if ($result == true && ENCRYPT_PASSWORD == true) { $update_result = $this->update_password($account_email,$new_password); if ($update_result == true) { return true; } return false; } if ( $result !=true ) { return false; } return true; } /** * return account email * * @param unknown_type $account_id */ function get_account_email_address($account_id) { $sql = " SELECT email FROM accounts WHERE account_id = $account_id "; $email = $this->system->db->get_scalar($sql); return $email; } function create_account_status_select($selected_value,$with_all = false) { return $this->system->create_select("account_status","account_status_id","title",$selected_value,$with_all); } function get_account_full_name($account_id = 0) { $sql = " SELECT CONCAT(first_name,' ',last_name) AS full_name FROM accounts WHERE account_id = $account_id "; if ($account_id == 0) { $account_id = $this->get_current_account_id(); } $name = $this->system->db->get_scalar($sql); return $name; } // delete user from database function remove_user($account_id) { $sql = " DELETE FROM accounts WHERE account_id= $account_id LIMIT 1 "; $result = $this->system->db->query($sql); if ($result != true) { return false; } return true; } } // end class ?> Code (markup):
If you want to force the username to be a valid e-mail address then you can simply do the two step registration process. When they sign up an activation code is e-mailed to the address given with a link. When they visit the link the account becomes active and they can log in.
Thank you for your reply. You say it's simple to "an activation code is e-mailed to the address given with a link. When they visit the link the account becomes active and they can log in", but I have no idea how to do that. I'd prefer something along the lines of, in the Account Creation Page, the user enters an email address in the User Name field, and it automatically populates the Email Address field on that page. Both the user name and the email address is stored in their prospective database columns. Would that be simple? If so, how might that be done?
Hey, Earlier I was too sleepy and was not thinking right. . But I saw this thing called LOGIN_WITH_EMAIL at the top of that account.php file. define('LOGIN_WITH_EMAIL',false); PHP: Try setting that to true. . May work. ~ Thomas
Thanks SO much for your message/reply. I tried your suggestion, but unfortunately didn't work. Any thoughts on my suggestion where the user enters an email address in the User Name field, and it automatically populates the Email Address field on that page. Therefore , both the user name and the email address are stored in their prospective database columns, without modifying the db. But, I'm sure you have better ideas, just a thought. I look forward to any assistance.. Thanks again.