Topic: Using email address or login for access_user! (Read 688 times)
Cyberpunk Wannabe
Gender:
Posts: 43
280 credits Members referred : 0
Lolo means Grandpa in the Philippines!
« on: Feb 07, 2007, 09:03:43 AM »
Using email address or login for access_user!
The concept is simple, an access_user class that does many different things.
The current class can be used to log people in, but could also key many things on the login. For example, the login on a FreeBSD (or Linux) server, or for hosting people files, or putting invoices into like on a site that sells domain names, or even for creating directories like where a realtor would put all the files for each listed property. Access_user, as it is, can really do all this special stuff!
However, let’s face it; most of us just want to restrict access to part of a normal website! We like the idea of having multiple levels of access, but beyond that, the above mentioned special cases are, well, special cases! For us the simplicity of having a system where users can log in with just their email address and password is very appealing! As it is, access_user can NOT do that!
BUT IT COULD!
Actually, in Ver 1.93 we devised and tested a simple modification that would allow ALL the above with just a tiny configuration change.
In Ver 1.94 we applied the SAME changes and a small mod to improve session handling at logout and allow easy use of the access_level to select data on a web page.
We just finished modifying Ver 1.95 the same way with this very stable modification. We now have four (4) live websites using this mod.
USE AT YOUR OWN RISK! (Note: at this time Olaf does NOT support this mod. So with each new release you will need to make the same changes again & again. We like it so much it is no big thing!)
Below are the lines we modified.
Quote
Red we removed Blue we added Green is just comments and BLACK is unchanged!
Here is what we did…
To db_config.php we added:
Quote
//aLan Tait Changes... // Change this constant for using email add for login name define("LOGTYP", "email");// either "login" or "email" // To use Email you must change "LOGIN_LENGTH" to 0 (below) // To use email without a unique login you must modify the "users" table to either: // Eliminate the login column; OR // Make the login column NOT unique
In access_user_class.php we made these changes:
Add the following VAR statement:
Quote
var $logtyp = LOGTYP;// Change "login" or "email" on db_config.php- this property to use email as the username
In function check_user
Quote
case "new": if ($this->logtyp == "login") { $sql = sprintf("SELECT COUNT(*) AS test FROM %s WHERE email = '%s' OR login = '%s'", $this->table_name, $this->user_email, $this->user); } else { $sql = sprintf("SELECT COUNT(*) AS test FROM %s WHERE email = '%s'", $this->table_name, $this->user_email); } break;
Quote
default: $sql = sprintf("SELECT COUNT(*) AS test FROM %s WHERE BINARY login%s = '%s' AND pw = '%s' AND active = 'y'", $this->table_name, $this->logtyp, $this->user, $this->user_pw); }
In function get_access_level
Quote
function get_access_level() { $sql = sprintf("SELECT access_level FROM %s WHERE login%s = '%s' AND active = 'y'", $this->table_name, $this->logtyp, $this->user);
In function set_user
Quote
function set_user($goto_page) { $_SESSION['access_level'] = $this->get_access_level(); $_SESSION['user'] = $this->user;
In function reg_visit
Quote
function reg_visit($login, $pass) { $visit_sql = sprintf("UPDATE %s SET extra_info = '%s' WHERE login%s = '%s' AND pw = '%s'", $this->table_name, date("Y-m-d H:i:s"), $this->logtyp, $login, $pass);
In function log_out
Quote
function log_out() { unset($_SESSION['user']); unset($_SESSION['pw']); unset($_SESSION['logged_in']); $_SESSION = array();
In function get_user_info
Quote
function get_user_info() { $sql_info = sprintf("SELECT real_name, extra_info, email, id FROM %s WHERE login%s = '%s' AND pw = '%s'", $this->table_name, $this->logtyp, $this->user, $this->user_pw);
if ($this->check_user("new_pass")) { // this is a fix for version 1.76 $sql_get_user = sprintf("SELECT login%s FROM %s WHERE MD5(pw) = '%s' AND id = %d", $this->logtyp, $this->table_name, $this->user_pw, $this->id); $get_user = mysql_query($sql_get_user); $this->user = mysql_result($get_user, 0, "login"$this->logtyp); // end fix return true;
That's it! Now remember to modify your database table and either remove the unique key from the login column (if you want to use it for something else) or just remove the login column completely!
If you use the Admin Page you will need a few mods there too!
Enjoy!
« Last Edit: Feb 07, 2007, 09:10:35 AM by Lan »
Cyberpunk Wannabe
Gender:
Posts: 43
280 credits Members referred : 0
Lolo means Grandpa in the Philippines!
« Reply #1 on: Feb 07, 2007, 09:42:31 AM »
Here is what you need to do to modify the admin_user.php page to work with the email login above...
In admin_user.php we made these changes:
Add the following VAR statement:
Quote
var $activation; var $logtyp = LOGTYP;// Change "login" or "email" on db_config.php- this property to use email as the username var $type;
In function get_userdata
Quote
function get_userdata($for_user, $type = "login") { if ($type == "login") { $sql = sprintf("SELECT id, login%s, email, access_level, active FROM %s WHERE login%s = '%s'", $this->logtyp, $this->table_name, $this->logtyp, trim($for_user)); } else { $sql = sprintf("SELECT id, login%s, email, access_level, active FROM %s WHERE id = %d", $this->logtyp, $this->table_name, intval($for_user));