Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PHP_CodeSniffer for quality checking
- Loading branch information
1 parent
b3421be
commit fef051f
Showing
6 changed files
with
460 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Ankit Jain | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,164 @@ | ||
<?php | ||
|
||
/** | ||
* Login Class Doc Comment | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package Registration-Module | ||
* @author Ankit Jain <ankitjain28may77@gmail.com> | ||
* @license The MIT License (MIT) | ||
* @link https://github.com/ankitjain28may/registration-module | ||
*/ | ||
namespace AnkitJain\RegistrationModule; | ||
use AnkitJain\RegistrationModule\Session; | ||
require_once (dirname(__DIR__) . '/config/database.php'); | ||
require_once dirname(__DIR__) . '/config/database.php'; | ||
|
||
/** | ||
* For Login the User | ||
* | ||
* @category PHP | ||
* @package Registration-Module | ||
* @author Ankit Jain <ankitjain28may77@gmail.com> | ||
* @license The MIT License (MIT) | ||
* @link https://github.com/ankitjain28may/registration-module | ||
*/ | ||
class Login | ||
{ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Login Class | ||
|-------------------------------------------------------------------------- | ||
| | ||
| For Login. | ||
| | ||
*/ | ||
|
||
protected $flag; | ||
protected $error; | ||
protected $connect; | ||
protected $flag; | ||
protected $error; | ||
protected $connect; | ||
|
||
public function __construct() | ||
{ | ||
$this->flag = 0; | ||
$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); | ||
$this->error = array(); | ||
} | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->flag = 0; | ||
$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); | ||
$this->error = array(); | ||
} | ||
|
||
public function authLogin($data) | ||
{ | ||
$data = $this->emptyValue($data); | ||
/** | ||
* Credentials check for allowing user to login | ||
* | ||
* @param array $data Contains the User Credentials | ||
* | ||
* @return json | ||
*/ | ||
public function authLogin($data) | ||
{ | ||
$data = $this->emptyValue($data); | ||
|
||
$login = $data["login"]; | ||
$password = $data["passLogin"]; | ||
$login = $data["login"]; | ||
$password = $data["passLogin"]; | ||
|
||
if (preg_match("/^.+[@]{1}.+$/", $login)) { | ||
if (filter_var($login, FILTER_VALIDATE_EMAIL) == false) { | ||
$this->onError("login", " *Enter correct Email address"); | ||
} | ||
} | ||
|
||
if (preg_match("/^.+[@]{1}.+$/", $login)) | ||
{ | ||
if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) | ||
{ | ||
$this->onError("login", " *Enter correct Email address"); | ||
} | ||
} | ||
if ($this->flag == 0) { | ||
$password = md5($password); | ||
$query = " | ||
SELECT * FROM login WHERE email = '$login' or username = '$login' | ||
"; | ||
if ($result = $this->connect->query($query)) { | ||
if ($result->num_rows > 0) { | ||
|
||
if($this->flag == 0) | ||
{ | ||
$password = md5($password); | ||
$query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; | ||
if ($result = $this->connect->query($query)) | ||
{ | ||
if ($result->num_rows > 0) | ||
{ | ||
$row = $result->fetch_assoc(); | ||
$loginID = $row['login_id']; | ||
$query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; | ||
if($result = $this->connect->query($query)) | ||
{ | ||
if ($result->num_rows > 0) | ||
{ | ||
Session::put('start', $loginID); | ||
return json_encode([ | ||
"location" => URL."/account.php" | ||
]); | ||
} | ||
$this->onError("passLogin", " *Invalid password"); | ||
return json_encode($this->error); | ||
} | ||
return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); | ||
} | ||
$this->onError("login", " *Invalid username or email"); | ||
return json_encode($this->error); | ||
} | ||
return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); | ||
} | ||
else | ||
{ | ||
return json_encode($this->error); | ||
} | ||
} | ||
$row = $result->fetch_assoc(); | ||
$loginID = $row['login_id']; | ||
$query = " | ||
SELECT id FROM register WHERE | ||
id = '$loginID' and | ||
password = '$password' | ||
"; | ||
if ($result = $this->connect->query($query)) { | ||
if ($result->num_rows > 0) { | ||
Session::put('start', $loginID); | ||
return json_encode( | ||
[ | ||
"location" => URL . "/account.php" | ||
] | ||
); | ||
} | ||
$this->onError("passLogin", " *Invalid password"); | ||
return json_encode($this->error); | ||
} | ||
return json_encode( | ||
[ | ||
"Error" => "You are not registered, " . $this->connect->error | ||
] | ||
); | ||
} | ||
$this->onError("login", " *Invalid username or email"); | ||
return json_encode($this->error); | ||
} | ||
return json_encode( | ||
[ | ||
"Error" => "You are not registered, " . $this->connect->error | ||
] | ||
); | ||
} else { | ||
return json_encode($this->error); | ||
} | ||
} | ||
|
||
public function onError($key, $value) | ||
{ | ||
$this->flag = 1; | ||
$this->error = array_merge($this->error, [["key" => $key, "value" => $value]]); | ||
} | ||
/** | ||
* For generating Error array by key value pair | ||
* | ||
* @param string $key Contains key | ||
* @param string $value Contains the Value for the key | ||
* | ||
* @return void | ||
*/ | ||
public function onError($key, $value) | ||
{ | ||
$this->flag = 1; | ||
$this->error = array_merge( | ||
$this->error, | ||
[ | ||
[ | ||
"key" => $key, | ||
"value" => $value | ||
] | ||
] | ||
); | ||
} | ||
|
||
public function emptyValue($data) | ||
{ | ||
$errorCode = array( | ||
"login" => " *Enter the login field", | ||
"passLogin" => " *Enter the password" | ||
); | ||
/** | ||
* For checking whether the credentials are empty or not | ||
* | ||
* @param array $data Contains the Credentials | ||
* | ||
* @return array | ||
*/ | ||
public function emptyValue($data) | ||
{ | ||
$errorCode = array( | ||
"login" => " *Enter the login field", | ||
"passLogin" => " *Enter the password" | ||
); | ||
|
||
foreach ($data as $key => $value) { | ||
$data[$key] = trim($data[$key]); | ||
$value = trim($value); | ||
if(empty($value)) | ||
{ | ||
$this->onError($key, $errorCode[$key]); | ||
} | ||
} | ||
return $data; | ||
} | ||
foreach ($data as $key => $value) { | ||
$data[$key] = trim($data[$key]); | ||
$value = trim($value); | ||
if (empty($value)) { | ||
$this->onError($key, $errorCode[$key]); | ||
} | ||
} | ||
return $data; | ||
} | ||
} |
Oops, something went wrong.