Skip to content

Commit

Permalink
User registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Spamercz committed Jan 27, 2016
1 parent 058b571 commit 07e5a14
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 3,858 deletions.
4 changes: 2 additions & 2 deletions App/Config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ services:
- App\FrontModule\Model\FData\FDataModel
- App\FrontModule\Model\TData\TDataModel
- App\FrontModule\Model\Units\UnitsModel
- App\FrontModule\Model\User\RegisterService
- App\FrontModule\Model\User\RegisterService(%protection%)
- App\FrontModule\Model\VData\VDataModel(%storageCapacity%, %storageMultiplier%)
- App\FrontModule\Model\VData\VillageService
- App\FrontModule\Model\WData\WDataModel
- App\FrontModule\Model\WData\WDataModel(%worldSize%)
- App\FrontModule\Model\OData\ODataModel
- App\FrontModule\Model\OData\OasisService
32 changes: 30 additions & 2 deletions App/FrontModule/Model/User/RegisterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ class RegisterService
* @var App\FrontModule\Model\VData\VillageService
*/
private $villageService;
private $protection;


public function __construct(
$protection,
UserModel $userModel,
App\FrontModule\Model\WData\WDataModel $WDataModel,
App\FrontModule\Model\FData\FDataModel $FDataModel,
Expand All @@ -59,9 +61,13 @@ public function __construct(
$this->ABDataModel = $ABDataModel;
$this->VDataModel = $VDataModel;
$this->villageService = $villageService;
$this->protection = $protection;
}


/**
* @param \stdClass $data
*/
public function createMultihunter($data)
{
/** @var \stdClass $multihunter */
Expand Down Expand Up @@ -98,10 +104,14 @@ public function createMultihunter($data)
*/
public function registerUser($data)
{
$protection = time() + $this->protection;
$userId = $this->userModel->add([
'email' => $data->email,
'username' => $data->username,
'username' => $data->nickname,
'password' => Nette\Security\Passwords::hash($data->password),
'access' => UserModel::PERMISSION_USER,
'tribe' => $data->tribe,
'protect' => $protection,
]);

return $this->userModel->get($userId);
Expand All @@ -110,9 +120,27 @@ public function registerUser($data)

/**
* Handle all related to create new user.
*
* @param \stdClass $data
*/
public function createUser()
public function createUser($data)
{
$user = $this->registerUser($data);

/** @var \stdClass $field */
$field = $this->WDataModel->getRandom($data->position);
$this->WDataModel->setFieldTaken($field->id);
$villageName = $this->villageService->getNewVillageName($user);
$vid = $this->VDataModel->addVillageForUser($user, $field, $villageName);
$this->FDataModel->addResourceFields($field->fieldtype, $vid);
$this->unitsModel->add([
'vref' => $vid,
]);
$this->TDataModel->add([
'vref' => $vid,
]);
$this->ABDataModel->add([
'vref' => $vid,
]);
}
}
10 changes: 10 additions & 0 deletions App/FrontModule/Model/User/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ class UserModel extends App\Model\BaseModel

const MULTIHUNTER_ID = 5;
const NATURE_ID = 2;

const PERMISSION_USER = 2;


public function getByEmail($email)
{
return $this->database->select('*')->from($this->table)
->where('email = %s', $email)
->fetch();
}
}
20 changes: 19 additions & 1 deletion App/FrontModule/Model/VData/VillageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ class VillageService
* @var VDataModel
*/
private $VDataModel;
/**
* @var App\FrontModule\Model\WData\WDataModel
*/
private $WDataModel;


public function __construct(
VDataModel $VDataModel
VDataModel $VDataModel,
App\FrontModule\Model\WData\WDataModel $WDataModel
) {
$this->VDataModel = $VDataModel;
$this->WDataModel = $WDataModel;
}


Expand All @@ -34,4 +40,16 @@ public function getNewVillageName($user)

return $villageName;
}


/**
* @param int $place
*/
public function getRegistrationPlace($place)
{
if ($place === 0) {
$place = rand(1, 4);
}
$this->WDataModel->getRandom($place);
}
}
39 changes: 39 additions & 0 deletions App/FrontModule/Model/WData/WDataModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
class WDataModel extends App\Model\BaseModel
{
protected $table = 'wdata';
/** @var int */
private $worldSize;


public function __construct(
$worldSize,
Dibi\Connection $database
) {
parent::__construct($database);
$this->worldSize = $worldSize;
}


/**
* @param int $x
Expand Down Expand Up @@ -43,4 +55,31 @@ public function getAllOases()
->where('oasistype > 0')
->fetchAll();
}

public function getRandom($where)
{
$query = $this->database->select('*')->from($this->table);
$query->where('fieldtype = 3');
$query->where('occupied IS NULL');
switch ($where) {
case 1:
$query->where('x < -1 AND x > %i', -$this->worldSize);
$query->where('y > 1 and y < %i', $this->worldSize); //x- y+
break;
case 2:
$query->where('x > 1 and x < %i', $this->worldSize);
$query->where('y > 1 and y < %i', $this->worldSize);
break;
case 3:
$query->where('x < -1 and x > %i', -$this->worldSize);
$query->where('y < -1 and y > %i', -$this->worldSize);
break;
case 4:
$query->where('x > 1 and x < %i', $this->worldSize);
$query->where('y < -1 and y > %i', -$this->worldSize);
break;
}
$query->orderBy('RAND()');
return $query->fetch();
}
}
19 changes: 19 additions & 0 deletions App/FrontModule/Presenters/LoginPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\FrontModule\Presenters;

use Nette;

class LoginPresenter extends Nette\Application\UI\Presenter
{
public function actionDefault()
{

}


public function renderDefault()
{

}
}
82 changes: 82 additions & 0 deletions App/FrontModule/Presenters/RegisterPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\FrontModule\Presenters;

use App;
use Nette;

class RegisterPresenter extends Nette\Application\UI\Presenter
{
/** @var App\FrontModule\Model\User\UserModel @inject */
public $userModel;

/** @var App\FrontModule\Model\User\RegisterService @inject */
public $registerService;

public function actionDefault()
{

}


public function renderDefault()
{

}

protected function createComponentRegisterForm()
{
$form = new Nette\Application\UI\Form();

$form->addText('nickname', 'Nickname')
->setRequired();

$form->addText('email', 'Email')
->setRequired();

$form->addPassword('password', 'Password')
->setRequired();

$form->addRadioList('tribe', 'Choose tribe', [
1 => 'Romans',
2 => 'Teutons',
3 => 'Gauls',
])
->setRequired();

$form->addRadioList('position', 'Starting position', [
0 => 'Random',
1 => 'North west (+|-)',
2 => 'South west (-|-)',
3 => 'North east (+|+)',
4 => 'South east (+|-)',
])
->setDefaultValue(0)
->setRequired();

$form->addCheckbox('accept', 'I accept the game rules and general terms and conditions.')
->setRequired();

$form->addSubmit('signup', 'Signup');

$form->onSuccess[] = [$this, 'processRegistration'];

return $form;
}


public function processRegistration(Nette\Application\UI\Form $form)
{
$values = $form->getValues();

$existingUser = $this->userModel->getByEmail($values->email);
if ($existingUser) {
$this->flashMessage('Email allready exists');
$this->redirect(':Front:Register:default');
}

$this->registerService->createUser($values);

$this->redirect(':Front:Login:default');
}
}
2 changes: 1 addition & 1 deletion App/FrontModule/Templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
</style>
</head>
<body class="presto indexPage">
<body n:class="isset($bodyClass) ? $bodyClass : ''">
{include content}
</body>
</html>
23 changes: 23 additions & 0 deletions App/FrontModule/Templates/@layoutGame.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Spamian</title>
<link rel="shortcut icon" href="{$baseUrl}/favicon.ico" />
<meta name="content-language" content="en" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="{$baseUrl}/mt-core.js" type="text/javascript"></script>
<script src="{$baseUrl}/unx.js" type="text/javascript"></script>
<script src="{$baseUrl}/new.js" type="text/javascript"></script>
<link href="{$baseUrl}/gpack/travian_default/lang/en/compact.css" rel="stylesheet" type="text/css" />
<link href="{$baseUrl}/gpack/travian_default/lang/en/lang.css" rel="stylesheet" type="text/css" />
<link href="{$baseUrl}/gpack/travian_default/travian.css" rel="stylesheet" type="text/css" />
</head>
<body n:class="isset($bodyClass) ? $bodyClass : ''">
{include content}

{include ../../Templates/footer.latte}
<div id="ce"></div>
</body>
</html>
3 changes: 2 additions & 1 deletion App/FrontModule/Templates/Homepage/default.latte
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{var bodyClass = 'presto indexPage'}
{block content}
<div class="wrapper">
<div id="country_select">
Expand Down Expand Up @@ -127,7 +128,7 @@
<a href="#" class="closer"><img class="dynamic_img" alt="Close" src="{$baseUrl}/img/un/x.gif" /></a>
<ul class="world_list">
<li class="w_big c4" style="background-image:url('{$baseUrl}/img/en/welten/en1_big.jpg');">
<a href="anmelden.php"><img class="w_button" src="{$baseUrl}/img/un/x.gif" alt="World" /></a>
<a n:href=":Front:Register:default"><img class="w_button" src="{$baseUrl}/img/un/x.gif" alt="World" /></a>
<div class="label_players c0">Players:</div>
<div class="label_online c0">Online:</div>
<div class="players c1">$playersWorld</div>
Expand Down
5 changes: 5 additions & 0 deletions App/FrontModule/Templates/Login/default.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{var bodyClass = 'v35 ie ie7'}
{layout '../@layoutGame.latte'}
{block content}

{/block}
45 changes: 45 additions & 0 deletions App/FrontModule/Templates/Register/default.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{var bodyClass = 'v35 ie ie7'}
{layout '../@layoutGame.latte'}
{block content}
<div class="wrapper">
<div id="dynamic_header">
</div>
<div id="header"></div>
<div id="mid">
<div id="side_navi">
<a id="logo" n:href=":Front:Homepage:default" name="logo"><img src="{$baseUrl}/img/x.gif" alt="Travian"></a>

<p>
<a n:href=":Front:Homepage:default">Homepage</a>
<a n:href=":Front:Login:default">Login</a>
<a n:href=":Front:Register:default">Registration</a>
</p>
</div>
</div>

<div id="content" class="signup">

<h1><img src="{$baseUrl}/img/x.gif" class="anmelden" alt="register for the game"></h1>
<h5><img src="{$baseUrl}/img/x.gif" class="img_u05" alt="registration"/></h5>

<p>
Before you register an account you should read the <a href='{$baseUrl}/anleitung.php' target='_blank'>instructions</a> of Travian ro1 to see the specific advantages and disadvantages of the three tribes.
</p>
{foreach $flashes as $flash}
<div class="flash {$flash->type}">{$flash->message}</div>
{/foreach}

{control registerForm}

<p class="info">Each player may only own ONE account per server.</p>
</div>
<div id="ce"></div>
<div id="side_info" class="outgame">

<div class="clear"></div>
</div>

<div class="footer-stopper outgame"></div>
<div class="clear"></div>
</div>
{/block}
Loading

0 comments on commit 07e5a14

Please sign in to comment.