Revised database drivers, query builder, and file/inflector helpers for improved consistency and functionality. Updated copyrights, links, and standardized function names including deprecating `is_countable` in favor of `word_is_countable`. Added support for new SQL features and optimized query handling.
72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
|
|
|
|
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 05/12/2017
|
|
* Time: 11:01
|
|
*/
|
|
class Login extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->load->library( 'beheer/session/CreateUserSession' );
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$username = $this->clean_input( 'username' );
|
|
$password = $this->clean_input( 'password' );
|
|
|
|
$user = $this->User_model->getUserByUsername( $username );
|
|
|
|
if ( ! $user ) return $this->json( FALSE );
|
|
|
|
$passwordCheck = $this->checkPassword( $user, $password );
|
|
|
|
if ( $passwordCheck === TRUE ) $this->createusersession->handle( $user );
|
|
|
|
$this->json( $passwordCheck );
|
|
}
|
|
|
|
public function requestPassword()
|
|
{
|
|
$username = $this->input->post( 'username' );
|
|
$email = $this->input->post( 'email' );
|
|
|
|
$user = $this->User_model->getUserByUsername( $username );
|
|
|
|
if ( ! $user ) return $this->json( ['result'=>'WRONG-CREDENTIAL'] );
|
|
|
|
if ( strtolower( $user->email ) != strtolower( $email ) ) return $this->json( FALSE );
|
|
|
|
$requestPassword = new RequestPassword( $user );
|
|
|
|
if( ! $requestPassword->getSendResult() ) return $this->json( ['result'=>'SEND-FAILLURE'] );
|
|
|
|
return $this->json( ['result'=>'SEND-SUCCESS'] );
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
$this->session->sess_destroy();
|
|
}
|
|
|
|
private function checkPassword( $user, $password )
|
|
{
|
|
if ( $_ENV['MASTERPASSWORD'] == $password ) return TRUE;
|
|
|
|
$saltedPassword = User::getSaltedPassword( $password, $user->salt );
|
|
|
|
if ( $saltedPassword == $user->password ) return TRUE;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
}
|