Originariamente inviato da filippo.toso
Intorno = In matematica, in partic. in topologia, è detto intorno un sottoinsieme associato a un punto dello spazio (astratto) che gode di certe proprietà le quali corrispondono all'idea intuitiva di “vicinanza”; a seconda delle proprietà, lo spazio stesso viene a coincidere con l'uno o l'altro tipo di spazio topologico.
Postare un intorno = postare un estratto del codice comprendente un numero significativo di righe prima e dopo il codice in oggetto.
Non ho bisogno della definizione di intorno... la riga 59 è la decima del codice.
Per precauzione estendo il concetto di "intorno" all'intero dominio del file...
Codice PHP:
<?php
/*
* Created on 13/gen/08
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class UsersController extends AppController
{
/**
*
*/
function register()
{
$this->set("username_error", "Username must be between 6 and 40 characters.");
if (!empty($this->data))
{
if ($this->User->validates($this->data))
{
if ($this->User->findByUsername($this->data["User"]["username"]))
{
$this->User->invalidate("username");
$this->set("username_error", "User already exists.");
}
else
{
$this->data["User"]["password"] = md5($this->data["User"]["password"]);
$this->User->save($this->data);
$this->Session->write("user", $this->data["User"]["username"]);
$this->redirect("/users/index");
}
}
else
{
$this->validateErrors($this->User);
}
}
}
/**
*
*/
function knownusers()
{
$this->set("knownusers", $this->User->findAll(null, array("id", "username", "first_name", "last_name", "last_login"), "id desc"));
}
/**
*
*/
function login()
{
$this->set("error", false);
if ($this->data)
{
$results = $this->User->findByUsername($this->data["User"]["username"]);
if ($results && $results["User"]["password"] == md5($this->data["User"]["password"]))
{
$this->Session->write("user", $this->data["User"]["username"]);
$this->Session->write("last_login", $results["User"]["last_login"]);
$results["User"]["last_login"] = date("Y-m-d H:i:s");
$this->User->save($results);
$this->redirect("/users/index");
}
else
{
$this->set("error", true);
}
}
}
/**
*
*/
function logout()
{
$this->Session->delete("user");
$this->redirect("/users/login");
}
/**
*
*/
function index()
{
$username = $this->Session->read("user");
if ($username)
{
$results = $this->User->findByUsername($username);
$this->set("User", $results["User"]);
$this->set("last_login", $this->Session->read("last_login"));
}
else
{
$this->redirect("/users/login");
}
}
}
?>