changed login from username to both username and email

This commit is contained in:
shubham_meena 2014-03-24 17:07:53 +05:30
parent 7e6cf7c213
commit b719ba6464
5 changed files with 92 additions and 15 deletions

View file

@ -126,8 +126,8 @@ go_home = "Go Home"
userlist_info = "welcome to the userlist"
[login]
login_info = "Please login with your Username and Password."
login_error_message = "The username/password were not correct!"
login_info = "Please login with your Email/Username and Password."
login_error_message = "The Email/username/password were not correct!"
login_register_message ="<strong>Register</strong> If you don't have an account yet, create one"
login_here = "here"
login_forgot_password_message = "In case you forgot your password, click"

View file

@ -116,8 +116,8 @@ go_home = "Allez au main page"
userlist_info = "bienvenue sur le userlist page!"
[login]
login_info = "S'il vous plait vous connecter avec votre nom d'utilisateur et mot de passe."
login_error_message = "Le remplie nom d'utilisateur / mot de passe ne sont pas correctes!"
login_info = "S'il vous plait vous connecter avec votre Email/nom d'utilisateur et mot de passe."
login_error_message = "Le remplie Email/nom d'utilisateur / mot de passe ne sont pas correctes!"
login_register_message ="<strong> Inscrivez-vous </strong> Si vous n'avez pas encore de compte, creez-en un"
login_here = "ici"
login_forgot_password_message = "Dans le cas ou vous avez oublie votre mot de passe, cliquez"

View file

@ -90,6 +90,47 @@ class WebUsers extends Users{
}
/**
* check if the login email and password match the db.
* @param $email the inserted email id
* @param $password the inserted password (unhashed)
* @return the logged in user's db row as array if login was a success, else "fail" will be returned.
*/
public static function checkLoginMatchUsingEmail($email,$password){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:emailid", array('emailid' => $email));
$row = $statement->fetch();
$salt = substr($row['Password'],0,2);
$hashed_input_pass = crypt($password, $salt);
if($hashed_input_pass == $row['Password']){
return $row;
}else{
return "fail";
}
}
/**
* check for the login type email or username.
* @param $value the inserted value
* @return the type email or username will be returned.
*/
public static function checkLoginType($login_value){
$dbl = new DBLayer("web");
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_user");
$row = $statement->fetch();
foreach( $row as $key => $value)
{
if($login_value == $value){
return $key;
}
}
}
/**
* returns te id for a given username
* @param $username the username
@ -119,6 +160,23 @@ class WebUsers extends Users{
}
}
/**
* returns the username for a given emailaddress
* @param $email the emailaddress
* @return the username linked to the emailaddress
*/
public static function getUsernameFromEmail($email){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email));
$row = $statement->fetch();
if(!empty($row)){
return $row['Login'];
}else{
return "FALSE";
}
}
/**
* get uId attribute of the object.

View file

@ -9,15 +9,34 @@ function login(){
global $INGAME_WEBPATH;
global $WEBPATH;
try{
$username = filter_var($_POST['Username'],FILTER_SANITIZE_STRING);
$login_value = filter_var($_POST['LoginValue'],FILTER_SANITIZE_STRING);
$password = filter_var($_POST['Password'],FILTER_SANITIZE_STRING);
//check login type if email or username
$login_type = WebUsers::checkLoginType($login_value);
//check if the filtered sent POST data returns a match with the DB
$result = WebUsers::checkLoginMatch($username, $password);
if($login_type == 'Login')
{
$result = WebUsers::checkLoginMatch($login_value, $password);
}else
{
$result = WebUsers::checkLoginMatchUsingEmail($login_value, $password);
}
if( $result != "fail"){
//handle successful login
$_SESSION['user'] = $username;
$_SESSION['id'] = WebUsers::getId($username);
if($login_type == 'Login')
{
$_SESSION['user'] = $login_value;
$_SESSION['id'] = WebUsers::getId($login_value);
}else{
$_SESSION['user'] = WebUsers::getUsernameFromEmail($login_value);
$_SESSION['id'] = WebUsers::getIdFromEmail($login_value);
}
$_SESSION['ticket_user'] = serialize(Ticket_User::constr_ExternId($_SESSION['id']));
$user = new WebUsers($_SESSION['id']);
$_SESSION['Language'] = $user->getLanguage();

View file

@ -14,8 +14,8 @@
</div>
<form method="post" action="index.php{if isset($getstring)}{$getstring}{/if}" class="form-horizontal">
<fieldset>
<div data-rel="tooltip" class="input-prepend" data-original-title="Username">
<span class="add-on"><i class="icon-user"></i></span><input type="text" value="" id="Username" name="Username" class="input-large span10" placeholder="Username">
<div data-rel="tooltip" class="input-prepend" data-original-title="Username/Email">
<span class="add-on"><i class="icon-user"></i></span><input type="text" value="" id="LoginValue" name="LoginValue" class="input-large span10" placeholder="Username or Email">
</div>
<div class="clearfix"></div>