Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Jun 10, 2017
1 parent ca978b4 commit dfd1c3d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 5 deletions.
62 changes: 57 additions & 5 deletions lib/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,71 @@

class Auth
{
public static function get($default = null, $ns = 'web')
{
if (session_id()) {
$user = session($ns)->getUser(actual('auth.user'));
} else {
$user = actual('auth.user');
}

if ($user) {
$user = !is_array($user) ? $user->toArray() : $user;
actual('auth.user', $user);

return $user;
}

return $default;
}

public static function make($user = null, $ns = 'web')
{
$user = $user ?: static::get($user, $ns);

if ($user) {
$user = !is_array($user) ? $user->toArray() : $user;
actual('auth.user', $user);

if (session_id()) {
session($ns)->setUser($user);
}
}
}

public static function is($ns = 'web')
{
'octodummy' !== static::get('octodummy', $ns);
}

public static function guest($ns = 'web')
{
'octodummy' === static::get('octodummy', $ns);
}

public static function login($user, $ns = 'web')
{
session($ns)->setUser($user);
$user = !is_array($user) ? $user->toArray() : $user;

actual('auth.user', $user);

if (session_id()) {
session($ns)->setUser($user);
}
}

public static function logout($ns = 'web')
{
session($ns)->erase('user');
if (session_id()) {
session($ns)->erase('user');
}

actual('auth.user', null);
}

public static function id($ns = 'web')
{
$user = session($ns)->getUser();
$user = static::get(null, $ns);

if ($user) {
return $user['id'];
Expand All @@ -26,7 +78,7 @@ public static function id($ns = 'web')

public static function email($ns = 'web')
{
$user = session($ns)->getUser();
$user = static::get(null, $ns);;

if ($user) {
return isAke($user, 'email', null);
Expand All @@ -37,7 +89,7 @@ public static function email($ns = 'web')

public static function user($model = true, $ns = 'web', $em = 'user')
{
$user = session($ns)->getUser();
$user = static::get(null, $ns);;

if ($user && $model) {
return em($em)->find((int) $user['id']);
Expand Down
26 changes: 26 additions & 0 deletions lib/testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ public function em($entity, $new = true)
return dbMemory($entity, $new);
}

public function signIn($user = null)
{
$user = $user ? : $this->create(App\entities\UserEntity::class);
Auth::login($user);
}

public function make($class, $count = 1, $args = [], $lng = 'fr_FR')
{
if (is_array($count)) {
$args = $count;
$count = 1;
}

return $this->factory($class, $count, $lng)->raw($args);
}

public function create($class, $count = 1, $args = [], $lng = 'fr_FR')
{
if (is_array($count)) {
$args = $count;
$count = 1;
}

return $this->factory($class, $count, $lng)->store($args);
}

public function factory($class, $count = 1, $lng = 'fr_FR')
{
$model = maker($class, [], false);
Expand Down

0 comments on commit dfd1c3d

Please sign in to comment.