Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/EmailVerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* limitations under the License.
**/
use App\Http\Controllers\Controller;
use App\libs\Utils\EmailUtils;
use App\Services\Auth\IUserService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function showVerificationForm(LaravelRequest $request)
$params = ['email' => ''];
if($request->has("email")){
$email = trim($request->get("email"));
if (filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE) {
if (EmailUtils::isValidEmail($email)) {
$params['email'] = $email;
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**/

use App\Http\Controllers\Controller;
use App\libs\Utils\EmailUtils;
use App\Services\Auth\IUserService;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function showLinkRequestForm(LaravelRequest $request)

if($request->has("email")){
$email = trim($request->get("email"));
if (filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE) {
if (EmailUtils::isValidEmail($email)) {
$params['email'] = $email;
}
}
Expand Down
35 changes: 26 additions & 9 deletions app/Http/Middleware/ETagsMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace App\Http\Middleware;
/**
* Copyright 2015 OpenStack Foundation
* Copyright 2022 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -11,18 +11,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use Closure;
use Log;

use Illuminate\Support\Facades\Log;
/**
* Class ETagsMiddleware
* @package App\Http\Middleware
*/
final class ETagsMiddleware
{


/**
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
Expand All @@ -31,21 +28,41 @@ final class ETagsMiddleware
*/
public function handle($request, Closure $next)
{
// Handle request
$method = $request->getMethod();

// Support using HEAD method for checking If-None-Match
if ($request->isMethod('HEAD')) {
$request->setMethod('GET');
}
//Handle response
$response = $next($request);

if ($response->getStatusCode() === 200 && $request->getMethod() === 'GET')
{
$etag = md5($response->getContent());
$etag = md5($response->getContent());
$requestETag = str_replace('"', '', $request->getETags());
$requestETag = str_replace('-gzip', '', $requestETag);
if($requestETag && is_array($requestETag))
Log::debug(sprintf("ETagsMiddleware::handle requestEtag %s calculated etag %s", $requestETag[0], $etag));

if ($requestETag && $requestETag[0] == $etag)
{
Log::debug('ETAG 304');
// Strip W/ if weak comparison algorithm can be used
$requestETag = array_map([$this, 'stripWeakTags'], $requestETag);

if (in_array($etag, $requestETag)) {
$response->setNotModified();
}

$response->setEtag($etag);
}

$request->setMethod($method);

return $response;
}

private function stripWeakTags($etag)
{
return str_replace('W/', '', $etag);
}
}
8 changes: 6 additions & 2 deletions app/Http/Utils/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\libs\Utils\PunnyCodeHelper;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\QueryBuilder;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -349,7 +351,7 @@ public function apply2Query(QueryBuilder $query, array $mappings)
* @param string $original_format
* @return mixed
*/
private function convertValue($value, $original_format)
private function convertValue(string $value, string $original_format)
{
switch ($original_format) {
case 'datetime_epoch':
Expand All @@ -360,8 +362,10 @@ private function convertValue($value, $original_format)
return intval($value);
break;
case 'json_string':
return sprintf("%s",$value);
return sprintf("%s", $value);
break;
case 'json_email':
return PunnyCodeHelper::encodeEmail($value);
default:
return $value;
break;
Expand Down
10 changes: 7 additions & 3 deletions app/Http/Utils/ParseMultiPartFormDataInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ private function decide($string)
private function file($string)
{
preg_match('/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s', $string, $match);
return [
$match[1] => ($match[2] !== NULL ? $match[2] : '')
];
if(count($match) >=2 ) {
return [
$match[1] => ($match[2] !== NULL ? $match[2] : '')
];
}
Log::warning(sprintf( "ParseMultiPartFormDataInputStream::file %s", $string));
return [];
}

/**
Expand Down
12 changes: 7 additions & 5 deletions app/Models/OAuth2/OAuth2OTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\libs\Utils\PunnyCodeHelper;
use App\Models\Utils\BaseEntity;
use Doctrine\ORM\Mapping AS ORM;
use DateTime;
Expand Down Expand Up @@ -192,15 +194,15 @@ public function setScope(?string $scope): void
*/
public function getEmail(): ?string
{
return $this->email;
return PunnyCodeHelper::decodeEmail($this->email);
}

/**
* @param string $email
*/
public function setEmail(?string $email): void
{
$this->email = !empty($email) ? strtolower(trim($email)):null;
$this->email = PunnyCodeHelper::encodeEmail($email);
}

/**
Expand Down Expand Up @@ -361,7 +363,7 @@ public function isValid():bool{
}

public function getUserName():?string{
return $this->connection == OAuth2Protocol::OAuth2PasswordlessEmail ? $this->email : $this->phone_number;
return $this->connection == OAuth2Protocol::OAuth2PasswordlessEmail ? $this->getEmail() : $this->phone_number;
}

/**
Expand Down Expand Up @@ -402,7 +404,7 @@ public function generateValue(): string
public static function fromRequest(OAuth2AccessTokenRequestPasswordless $request, int $length):OAuth2OTP{
$instance = new self($length);
$instance->connection = $request->getConnection();
$instance->email = $request->getEmail();
$instance->setEmail($request->getEmail());
$instance->phone_number = $request->getPhoneNumber();
$instance->scope = $request->getScopes();
$instance->setValue($request->getOTP());
Expand All @@ -420,7 +422,7 @@ public static function fromParams(string $user_name, string $connection, string
$instance = new self(strlen($value));
$instance->connection = $connection;
if($connection == OAuth2Protocol::OAuth2PasswordlessConnectionEmail)
$instance->email = $user_name;
$instance->setEmail($user_name);
if($connection == OAuth2Protocol::OAuth2PasswordlessConnectionEmail)
$instance->phone_number = $user_name;
$instance->setValue($value);
Expand Down
10 changes: 7 additions & 3 deletions app/Repositories/DoctrineUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\libs\Utils\PunnyCodeHelper;
use Auth\Repositories\IUserRepository;
use Auth\User;
use utils\DoctrineFilterMapping;
Expand Down Expand Up @@ -49,8 +51,8 @@ protected function getFilterMappings()
'last_name' => 'e.last_name:json_string',
'full_name' => new DoctrineFilterMapping("concat(e.first_name, ' ', e.last_name) :operator :value"),
'github_user' => 'e.github_user:json_string',
'email' => ['e.email:json_string', 'e.second_email:json_string', 'e.third_email:json_string'],
'primary_email' => 'e.email:json_string',
'email' => ['e.email:json_email', 'e.second_email:json_email', 'e.third_email:json_email'],
'primary_email' => 'e.email:json_email',
'active' => 'e.active:json_boolean',
'group_id' => new DoctrineJoinFilterMapping('e.groups', "g", "g.id :operator :value")
];
Expand Down Expand Up @@ -87,12 +89,14 @@ public function getByToken(string $token): ?User
*/
public function getByEmailOrName(string $term): ?User
{
$term = PunnyCodeHelper::encodeEmail($term);

return $this->getEntityManager()
->createQueryBuilder()
->select("e")
->from($this->getBaseEntity(), "e")
->Where("e.email = (:term)")
->setParameter("term", trim($term))
->setParameter("term", $term)
->getQuery()
->getOneOrNullResult();
}
Expand Down
5 changes: 3 additions & 2 deletions app/libs/Auth/CustomAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function retrieveByCredentials(array $credentials)

$email = $credentials['username'];
$password = $credentials['password'];
$user = $this->user_repository->getByEmailOrName(trim($email));

$user = $this->user_repository->getByEmailOrName($email);

if (is_null($user)) //user must exists
{
Expand Down Expand Up @@ -193,7 +194,7 @@ public function validateCredentials(Authenticatable $user, array $credentials)
$email = $credentials['username'];
$password = $credentials['password'];

$user = $this->user_repository->getByEmailOrName(trim($email));
$user = $this->user_repository->getByEmailOrName($email);

if (!$user || !$user->canLogin() || !$user->checkPassword($password)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions app/libs/Auth/Factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function populate(User $user, array $payload):User{
$user->setLastName(trim($payload['last_name']));

if(isset($payload['email']) && !empty($payload['email']))
$user->setEmail(strtolower(trim($payload['email'])));
$user->setEmail($payload['email']);

if(isset($payload['second_email']))
$user->setSecondEmail(strtolower(trim($payload['second_email'])));
Expand All @@ -62,7 +62,7 @@ public static function populate(User $user, array $payload):User{
$user->setBio(trim($payload['bio']));

if(isset($payload['identifier']) && !empty($payload['identifier']))
$user->setIdentifier(trim($payload['identifier']));
$user->setIdentifier($payload['identifier']);

if(isset($payload['statement_of_interest']))
$user->setStatementOfInterest(trim($payload['statement_of_interest']));
Expand Down
Loading