Skip to content

Commit

Permalink
add in all the other formatted code.
Browse files Browse the repository at this point in the history
  • Loading branch information
codeformatter committed Sep 16, 2018
1 parent a1eb5f9 commit 6db7435
Show file tree
Hide file tree
Showing 115 changed files with 6,288 additions and 4,359 deletions.
198 changes: 111 additions & 87 deletions classes/auth/Auth.class.php

Large diffs are not rendered by default.

52 changes: 30 additions & 22 deletions classes/auth/AuthGuest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* FileSender www.filesender.org
*
*
* Copyright (c) 2009-2014, AARNet, Belnet, HEAnet, SURFnet, UNINETT
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
Expand All @@ -17,7 +17,7 @@
* * Neither the name of AARNet, Belnet, HEAnet, SURFnet and UNINETT nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -31,15 +31,17 @@
*/

// Require environment (fatal)
if (!defined('FILESENDER_BASE'))
if (!defined('FILESENDER_BASE')) {
die('Missing environment');
}

/**
* Guest authentication class
*
*
* Handles guest authentication.
*/
class AuthGuest {
class AuthGuest
{
/**
* Cache authentication status
*/
Expand All @@ -57,31 +59,33 @@ class AuthGuest {

/**
* Authentication check.
*
*
* @return bool
*/
public static function isAuthenticated() {
if(is_null(self::$isAuthenticated)) {
public static function isAuthenticated()
{
if (is_null(self::$isAuthenticated)) {
self::$isAuthenticated = false;

// Do we have a valid guest token in the query ?
if(array_key_exists('vid', $_REQUEST)) {
if (array_key_exists('vid', $_REQUEST)) {
$vid = $_REQUEST['vid'];
if(
if (
Utilities::isValidUID($vid)
) {
$guest = Guest::fromToken($vid);

if($guest->status != GuestStatuses::AVAILABLE || $guest->isExpired())
if ($guest->status != GuestStatuses::AVAILABLE || $guest->isExpired()) {
throw new GuestExpiredException($guest);
}

self::$isAuthenticated = true;
self::$guest = $guest;

// Update last guest activity
self::$guest->last_activity = time();
self::$guest->save();
}else{
} else {
throw new TokenHasBadFormatException($vid);
}
}
Expand All @@ -92,30 +96,34 @@ public static function isAuthenticated() {

/**
* Retreive user attributes.
*
*
* @retrun array
*/
public static function attributes() {
if(is_null(self::$attributes)) {
if(!self::isAuthenticated()) throw new AuthAuthenticationNotFoundException();
public static function attributes()
{
if (is_null(self::$attributes)) {
if (!self::isAuthenticated()) {
throw new AuthAuthenticationNotFoundException();
}

self::$attributes = array(
self::$attributes = [
'uid' => self::$guest->saml_user_identification_uid,
'email' => self::$guest->owner->email,
'name' => null,
'guest' => self::$guest
);
];
}

return self::$attributes;
}

/**
* Retreive guest
*
*
* @return Guest object
*/
public static function getGuest() {
public static function getGuest()
{
return self::isAuthenticated() ? self::$guest : null;
}
}
47 changes: 26 additions & 21 deletions classes/auth/AuthLocal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* FileSender www.filesender.org
*
*
* Copyright (c) 2009-2014, AARNet, Belnet, HEAnet, SURFnet, UNINETT
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
Expand All @@ -17,7 +17,7 @@
* * Neither the name of AARNet, Belnet, HEAnet, SURFnet and UNINETT nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -31,69 +31,74 @@
*/

// Require environment (fatal)
if (!defined('FILESENDER_BASE'))
if (!defined('FILESENDER_BASE')) {
die('Missing environment');
}

/**
* Guest authentication class
*
*
* Handles guest authentication.
*/
class AuthLocal {
class AuthLocal
{
/**
* Cache attributes
*/
private static $attributes = null;

/**
* Authentication check.
*
*
* @return bool
*/
public static function isAuthenticated() {
public static function isAuthenticated()
{
return !is_null(self::$attributes);
}

/**
* Retreive user attributes.
*
*
* @retrun array
*/
public static function attributes() {
if(is_null(self::$attributes))
public static function attributes()
{
if (is_null(self::$attributes)) {
throw new AuthAuthenticationNotFoundException();
}

return self::$attributes;
}

/**
* Set local user
*
*
* @param string $user_id user id
* @param string $email user email
* @param string $name user name
*
*
*/
public static function setUser($user_id, $email, $name = null) {
if(is_null($user_id)) { // Virtually closes the local session
public static function setUser($user_id, $email, $name = null)
{
if (is_null($user_id)) { // Virtually closes the local session
self::$attributes = null;

} else {
self::$attributes = array(
self::$attributes = [
'uid' => $user_id,
'email' => $email,
'name' => $name
);
];
/* $authid = Authentication::ensure('filesender-authlocal@localhost.localdomain', 'auth local')->id;
* $user = User::fromAuthId( $authid );
* $user->email_addresses = 'filesender-authlocal@localhost.localdomain';
*/
$authid = Authentication::ensure($user_id, 'auth local')->id;
$user = User::fromAuthId( $authid );
$user = User::fromAuthId($authid);
$user->email_addresses = $email;
$user->name = $name;

Auth::setUserObject( $user );
Auth::setUserObject($user);
}
}
}
Loading

0 comments on commit 6db7435

Please sign in to comment.