Skip to content

Commit

Permalink
Added PHP_CodeSniffer for quality checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitjain28may committed Jan 24, 2017
1 parent b3421be commit fef051f
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 209 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -8,13 +8,15 @@ php:
before_install:
- cp ./config/database.travis.php ./config/database.php
- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:dev-master
- composer require "squizlabs/php_codesniffer=*"
- composer install --dev --ignore-platform-reqs
- mysql -e 'CREATE DATABASE account;'
- mysql -u root account < ./sql/registration-module.sql

script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
- phpcs source

after_script:
- php vendor/bin/coveralls -v
9 changes: 9 additions & 0 deletions LICENSE.md
@@ -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.
226 changes: 147 additions & 79 deletions source/Login.php
@@ -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;
}
}

0 comments on commit fef051f

Please sign in to comment.