Skip to content

Commit

Permalink
add test for userresource
Browse files Browse the repository at this point in the history
  • Loading branch information
esvit committed Sep 22, 2013
1 parent f8a6e7d commit dfd5098
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 295 deletions.
1 change: 1 addition & 0 deletions install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS `cms_users` (
`email` varchar(60) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`is_active` tinyint(1) unsigned NOT NULL DEFAULT '0',
`is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
`last_activity` datetime DEFAULT NULL,
`session_id` varchar(50) DEFAULT NULL,
`is_god` tinyint(3) unsigned NOT NULL DEFAULT '0',
Expand Down
10 changes: 0 additions & 10 deletions server/Bazalt/Auth/Acl/Container.php

This file was deleted.

188 changes: 96 additions & 92 deletions server/Bazalt/Auth/Model/Guest.php
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
<?php

namespace Bazalt\Auth\Model;
use Bazalt\ORM,
Bazalt\Session;

class Guest extends \stdClass
{
public static function create($sessionId)
{
$user = new Guest();
$user->guest_id = $sessionId;
$user->is_guest = true;

return $user;
}

public function getRolesKey()
{
return 'guest_' . parent::getRolesKey();
}

public function hasName()
{
return $this->hasName;
}

public function getRoles()
{
return Role::getGuestRoles();
}

/**
* Зберегти гостя як юзера в БД
*/
public function saveAsUser()
{
$user = new User();
$user->login = $this->login;
$user->password = $this->password;
$user->firstname = $this->firstname;
$user->secondname = $this->secondname;
$user->patronymic = $this->patronymic;
$user->email = $this->email;
$user->gender = $this->gender;
$user->birth_date = $this->birth_date;
$user->reg_date = $this->reg_date;
$user->is_active = false;
$user->last_activity = $this->last_activity;

if (!$user->login) {
$user->login = CMS\User::generateRandomPassword();
}
if (!$user->password) {
$user->password = CMS\User::generateRandomPassword();
}
$user->password = CMS\User::criptPassword($user->password);
$user->save();

$this->setting('id', $user->id);

return $user;
}

/**
* Повертає чи встановлює налаштування гостя
*/
public function setting($name, $value = null, $default = null)
{
$session = new Session('guestSetting');
if ($value !== null) {
$session->{$name} = $value;
}
if (isset($session->{$name})) {
return $session->{$name};
}
return $default;
}

public function isGuest()
{
return true;
}


public function toArray()
{
$ret['roles'] = [];
$ret['acl'] = [];

return $this;
}
<?php

namespace Bazalt\Auth\Model;
use Bazalt\ORM,
Bazalt\Session;

class Guest extends \stdClass
{
public static function create($sessionId)
{
$user = new Guest();
$user->guest_id = $sessionId;
$user->is_guest = true;

return $user;
}

public function getRolesKey()
{
return 'guest_' . parent::getRolesKey();
}

public function hasName()
{
return $this->hasName;
}

public function getRoles()
{
return Role::getGuestRoles();
}

/**
* Зберегти гостя як юзера в БД
*/
public function saveAsUser()
{
$user = new User();
$user->login = $this->login;
$user->password = $this->password;
$user->firstname = $this->firstname;
$user->secondname = $this->secondname;
$user->patronymic = $this->patronymic;
$user->email = $this->email;
$user->gender = $this->gender;
$user->birth_date = $this->birth_date;
$user->reg_date = $this->reg_date;
$user->is_active = false;
$user->last_activity = $this->last_activity;

if (!$user->login) {
$user->login = CMS\User::generateRandomPassword();
}
if (!$user->password) {
$user->password = CMS\User::generateRandomPassword();
}
$user->password = CMS\User::criptPassword($user->password);
$user->save();

$this->setting('id', $user->id);

return $user;
}

/**
* Повертає чи встановлює налаштування гостя
*/
public function setting($name, $value = null, $default = null)
{
$session = new Session('guestSetting');
if ($value !== null) {
$session->{$name} = $value;
}
if (isset($session->{$name})) {
return $session->{$name};
}
return $default;
}

public function isGuest()
{
return true;
}

public function hasPermission()
{
return false;
}

public function toArray()
{
$ret['roles'] = [];
$ret['acl'] = [];

return $this;
}
}
1 change: 1 addition & 0 deletions server/Bazalt/Auth/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function toArray()
$ret = $this->values;
unset($ret['password']);
unset($ret['is_god']);
unset($ret['session_id']);

$ret['fullname'] = $this->getName();
$ret['is_active'] = $this->is_active == '1';
Expand Down
50 changes: 0 additions & 50 deletions server/Bazalt/Auth/Webservice/AclResource.php

This file was deleted.

Loading

0 comments on commit dfd5098

Please sign in to comment.